Joined: Tue Mar 27, 2007 10:55 pm Posts: 2279 Location: Earth Has thanked: 39 time Have thanks: 61 time
Fonts in java
Code:
import java.awt.*; import javax.swing.*;
public class DisplayDifferentFonts extends JComponent { String[] differentFonts; Font[] font; static final int IN = 15; public DisplayDifferentFonts() {
differentFonts = GraphicsEnvironment.getLocalGraphicsEnvironment() .getAvailableFontFamilyNames(); font = new Font[differentFonts.length]; } public void paintComponent(Graphics g) { for (int j = 0; j < differentFonts.length; j += 1) { if (font[j] == null) { font[j] = new Font(differentFonts[j], Font.PLAIN, 16); } g.setFont(font[j]); int p = 15; int q = 15+ (IN * j); g.drawString(differentFonts[j],p,q); } } public static void main(String[] args) { JFrame frame = new JFrame("Different Fonts"); frame.getContentPane().add(new JScrollPane(new DisplayDifferentFonts())); frame.setSize(350, 650); frame.setVisible(true); } }
Attachments:
File comment: different fonts in java differentFonts.gif [ 10.25 KiB | Viewed 1508 times ]
_________________ Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )