A Font object represents a font.
Here is a constructor of the Font class.
public Font (java.lang.String name, int style, int size)
- name is the font name (such as "Verdana", "Arial", etc).
- size is the point size of the font.
- style argument takes an integer bitmask that may be PLAIN or a bitwise union of BOLD and/or ITALIC.
For example, the following code construct a Font object.
int style = Font.BOLD | Font.ITALIC;
Font font = new Font ("Garamond", style , 11);
import java.awt.Font;
import java.awt.GraphicsEnvironment;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class TrueTypeJokerman extends JFrame {
private String textMessage = "Java Internationalization";
public TrueTypeJokerman() {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
ge.getAllFonts();
Font font = new Font("Jokerman", Font.PLAIN, 35);
JLabel textLabel = new JLabel(textMessage);
textLabel.setFont(font);
getContentPane().add(textLabel);
setVisible(true);
}
public static void main(String[] args) {
JFrame frame = new TrueTypeJokerman();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
}