我常见了一个JFrame p,设置了红叉叉的p.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
我想要再添加一个exit按钮进去,设置好了按钮监听,有代码if(e.getSource()==exit){ ... }
关键是“...”这一段,我试了dispose();system.exit(0);setVisible(false);结果都没反应,求高手指点下。

解决方案 »

  1.   

    我把代码贴出来看一看
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class text1 extends JFrame implements ActionListener{
    Button exit=new Button("Cancle");
    public text1(){
    this.add(exit);
    this.setTitle("Frame Text!");
    this.setBounds(10,10,500,500);
    this.setVisible(true);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    public void actionPerformed(ActionEvent e){
    if(e.getSource()==exit){
    ...
    }
    }
    public static void main(String args[]){
    new text1();
    }
    }