JComboBox list;
JLabel lable;
Mypanel panel;
public FontDialog(JFrame f, String s, boolean b) {
super(f, s, b);
panel = new Mypanel();
list = new JComboBox();
lable = new JLabel("字体的效果");
FontFamily fontFamily = new FontFamily();
String[] s1 = fontFamily.getfont();
for (int i = 0; i < s1.length; i++) {
list.addItem(s1[i]);
}
add(list,BorderLayout.NORTH);
add(lable,BorderLayout.CENTER);
add(panel,BorderLayout.SOUTH);
list.addItemListener(this);
panel.button1.addActionListener(this);
panel.button2.addActionListener(this);
setBounds(380, 380, 380, 380);
}
public void itemStateChanged(ItemEvent e) {
// TODO Auto-generated method stub
if(e.getSource()==list)
{
String name = (String)list.getSelectedItem();
//UIManager.put("Label.font", new Font(name,Font.BOLD,12));
lable.setFont(new Font(name,Font.PLAIN,list.getFont().getSize()));
}
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==panel.button1)
{
//int i = list.getSelectedIndex();
//FrameHaveDialog frameHaveDialog = new FrameHaveDialog();
//int index = list.getSelectedIndex();
//lable.setFont(new Font((String) list.getItemAt(index),Font.PLAIN,list.getFont().getSize()));
//System.out.print(0);
setVisible(false);
//System.exit(0);
}
else if(e.getSource()==panel.button2)
{
//System.out.print(1);
setVisible(false);
//System.exit(0);
}
}
}
运行结果: