Total members 10261 | Gratitudes |It is currently Tue May 22, 2012 5:10 pm Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 1 post ] 
Author Code Snippet
 Code subject: Outlining the font in java
PostPosted: Tue Nov 11, 2008 6:35 pm 
Offline
Mastermind
User avatar

Joined: Tue Mar 27, 2007 10:55 pm
Posts: 2279
Location: Earth
Has thanked: 39 time
Have thanks: 61 time

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(w / 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 839 times ]

_________________
Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )
TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 1 post ] 
Quick reply


  

 Similar topics
 video chat application in java
 navigating to database using java
 java mobile apps
 need help in java
 Read your gmail using Java code
 Java Programing to communicating port parallel
 Java Chat
 Steganography in java
 java code for listing folder contents from remote folder
 java

All times are UTC [ DST ]


Users browsing similar codes

Users browsing this forum: Google Adsense [Bot] and 3 guests



Jump to:  
Previous Code Snippet | Next Code Snippet 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team