用什么方法可以看到Font类的所有字体设置,给出调用方法。
谢谢
用什么方法可以看到Font类的所有字体设置,给出调用方法。
谢谢
import java.awt.BorderLayout;
import java.awt.Choice;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Frame;
import java.awt.GraphicsEnvironment;
import java.awt.Label;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.JLabel;
public class Test_24 extends Frame implements ItemListener {
private static final long serialVersionUID = 1L;
Choice c;
JLabel l;
public static void main(String[] args) {
new Test_24();
}
public Test_24() {
super();
initialize();
}
private void initialize() {
this.setSize(300, 200);
this.setTitle("Frame");
GraphicsEnvironment g = GraphicsEnvironment
.getLocalGraphicsEnvironment();
String fontName[] = g.getAvailableFontFamilyNames();
c = new Choice();
for (int i = 0; i < fontName.length; i++)
c.add(fontName[i]);
l = new JLabel("", JLabel.CENTER);
this.add(c, BorderLayout.NORTH);
this.add(l, BorderLayout.CENTER);
this.setVisible(true);
c.addItemListener(this);
this.addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent e) {
System.exit(0);
}
});
}
public void itemStateChanged(ItemEvent e) {
String name = (String) e.getItem();
System.out.println(name);
Font f = new Font(name, Font.ITALIC, 40);
l.setForeground(Color.red);
l.setFont(f);
l.setText("测试字体");
double x=l.getLocation().getX();
double y=l.getLocation().getY();
int h = l.getSize().height;
int w = l.getSize().width;
System.out.println(x+","+y);
System.out.println(h+","+w);
}
}