开发者

How do I shutdown my program with a JButton ActionListener?

I have a button, and a buttonhandler(ActionEvent) for it. Now, I want to make it so that, when you click the button, your program shuts down. How would I go about doing this? My buttonhandler code:

class ButtonHandler implements ActionListener{
    public void actionPerformed( ActionEvent e){
开发者_开发百科
    }
}

So I basicly need to shutdown the whole JFrame.


Your ButtonHandler would have a reference to the JFrame it's a member of and call JFrame.dispose();

class ButtonHandler implements ActionListener{
    final JFrame parent; 
    public ButtonHandler(JFrame p) { parent = p; }

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


If you are shutting down the entire program, you can use System.exit().

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜