[英]How do I shutdown my program with a JButton ActionListener?
I have a button, and a buttonhandler(ActionEvent) for it. 我有一个按钮,以及一个buttonhandler(ActionEvent)。 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. 因此,我基本上需要关闭整个JFrame。
Your ButtonHandler would have a reference to the JFrame it's a member of and call JFrame.dispose(); 您的ButtonHandler将引用它的成员JFrame并调用JFrame.dispose();。
class ButtonHandler implements ActionListener{
final JFrame parent;
public ButtonHandler(JFrame p) { parent = p; }
public void actionPerformed( ActionEvent e){
parent.dispose();
}
}
如果要关闭整个程序,则可以使用System.exit()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.