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()
.
精彩评论