private JButton yes,exit;
////退出就是下面这么写的,很明显没用,,,
public void actionPerformed(ActionEvent e) {
JButton jb=(JButton)e.getSource();
String som=jb.getText();
if(som.equals("确定")){
//响应消息
}
else if(som.equals("退出")){
exit.addActionListener(new ActionListener(){
   public void actionPerformed(ActionEvent e){
    System.exit(0);
   }
});
} }/////下面还有下拉列表的响应事件,依然是没用
private JLabel font,shape,size,color,show;
show=new JLabel("永远的java");///用来检测下有没有反应的
 public void itemStateChanged(ItemEvent e){
     String sth=((Choice)e.getItemSelectable()).getSelectedItem();
     Font MyFont=new Font("TimesRoman",Font.BOLD,12);
if(sth.equals("宋体")){
show.setFont(new Font("TimesRoman",Font.BOLD,10) );//这个就是用来检测下的,果然没
           有用!其实我想实现的是如果选择了“宋体”,就把show 里的字体换了。
}    
      //////////略
}
    很希望看到大家宝贵的意见!

解决方案 »

  1.   

    好久不来了
    帮你写个import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;public class Test extends JFrame
    {
    private JComboBox box;
    private JLabel label;

    public Test()
    {
    setTitle("JComboBox Test");
    setBounds(200, 200, 250, 150);

    label = new JLabel("Hello World !", JLabel.CENTER);
    label.setFont(new Font("Arial", Font.BOLD, 23));

    box = new JComboBox();

    FontLabel arial = new FontLabel("Arial");
    FontLabel courier = new FontLabel("Courier New");
    FontLabel impact = new FontLabel("Impact");

    box.addItem(arial);
    box.addItem(courier);
    box.addItem(impact);

    box.addItemListener(new ItemListener()
    {
    public void itemStateChanged(ItemEvent e)
    {
    String font = ((FontLabel)e.getItem()).getText();
    label.setFont(new Font(font, Font.BOLD, 23));
    }
    });

    Container con = getContentPane();
    con.add(label);
    con.add(box, BorderLayout.SOUTH);
    }

    public static void main(String[] args)
    {
    Test t = new Test();
    t.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    t.setVisible(true);
    }

    class FontLabel extends JLabel
    {
    public FontLabel(String text)
    {
    super(text);
    }

    public String toString()
    {
    return getText();
    }
    }
    }