如何使用JButton ActionListener关闭程序?

| 我有一个按钮,以及一个buttonhandler(ActionEvent)。 现在,我要这样做,以便在您单击按钮时关闭程序。 我将如何去做呢? 我的按钮处理程序代码:
class ButtonHandler implements ActionListener{
    public void actionPerformed( ActionEvent e){

    }
}
因此,我基本上需要关闭整个JFrame。     
已邀请:
如果要关闭整个程序,可以使用
System.exit()
。     
您的ButtonHandler将引用它的成员JFrame并调用JFrame.dispose();。
class ButtonHandler implements ActionListener{
    final JFrame parent; 
    public ButtonHandler(JFrame p) { parent = p; }

    public void actionPerformed( ActionEvent e){
        parent.dispose();
    }
}
    

要回复问题请先登录注册