Total members 11894 |It is currently Thu Nov 21, 2024 9:43 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





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
differentFonts.gif [ 10.25 KiB | Viewed 17983 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 : Fonts in java
 Using two different fonts in the same webpage     -  
 Use TrueType Fonts in php     -  
 2d game in java-Monster-Java 2D Game Graphics and Animation     -  
 What is Java API?!!!     -  
 java or .net     -  
 need help in java     -  
 Using FTP in java     -  
 what is java     -  
 Java course     -  
 Java Servlet and JSP     -  



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