Total members 11889 |It is currently Thu Mar 28, 2024 12:48 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





Outlining the font in java
Code:
import java.awt.*;
import javax.swing.*;
import java.awt.font.*;
import java.awt.event.*;
import java.awt.geom.AffineTransform;

public class FontOutline extends JApplet {
    public void initialize() {
    FontPaint font1 = new FontPaint();
    getContentPane().add(font1, BorderLayout.CENTER);
  }
 public static void main(String[] args) {
    FontPaint font2 = new FontPaint();
    JFrame frame = new JFrame("Outlining Font");
    frame.getContentPane().add(font2, BorderLayout.CENTER);
    frame.setSize(new Dimension(350, 200));
    frame.setVisible(true);
  }
}
class FontPaint extends JPanel {
  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    setBackground(Color.white);
    int w = getSize().width;
    int h = getSize().height;
    Graphics2D g2d = (Graphics2D) g;
  FontRenderContext fontRendContext = g2d.getFontRenderContext();
    Font font = new Font("Monotype Corsiva", 2, 50);
    String st = new String("Hello World.");
    TextLayout text = new TextLayout(st, font, fontRendContext);
    AffineTransform affineTransform = new AffineTransform();
    Shape shape = text.getOutline(null);
    Rectangle rect = shape.getBounds();
    affineTransform = g2d.getTransform();
    affineTransform.translate(/ 2 - (rect.width / 2), h / 2
        
+ (rect.height / 2));
    g2d.transform(affineTransform);
    g2d.setColor(Color.red);
    g2d.draw(shape);
    g2d.setClip(shape);
  }
}
 





Attachments:
File comment: the output
outlineFont.gif
outlineFont.gif [ 8.65 KiB | Viewed 4280 times ]

_________________
M. S. Rakha, Ph.D.
Queen's University
Canada
Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : Outlining the font in java
 change Font of text in java     -  
 CSS used font families     -  
 Change the td font style     -  
 change font size in JavaScript     -  
 Configuring the header html font     -  
 Control font size of sub and sup text     -  
 chainge Font size of drawing     -  
 using double font families with body tag     -  
 change the font style of the body tag     -  
 Change the link font family and weight     -  



Topic Tags

Java Graphics
cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com