当前位置: 技术问答>java相关
怎么样才能再关闭JFrame时,执行我自定义的一些方法?(在线等待)
来源: 互联网 发布时间:2015-05-06
本文导语: public class PrintSample extends JFrame implements WindowListener{ public static void main(String[] args) { PrintSample ps = new PrintSample();ps.pack(); ps.setVisible(true); ps.addWindowListener(ps); } public void windowActivated(Wind...
public class PrintSample extends JFrame implements WindowListener{
public static void main(String[] args) {
PrintSample ps = new PrintSample();ps.pack();
ps.setVisible(true);
ps.addWindowListener(ps);
}
public void windowActivated(WindowEvent e){
}
public void windowClosed(WindowEvent e){
stm.cut1();
System.out.println("lskjdf");
}
public void windowClosing(WindowEvent e){
}
public void windowDeactivated(WindowEvent e){
}
public void windowIconified(WindowEvent e){
}
public void windowOpened(WindowEvent e){
}
public void windowDeiconified(WindowEvent e){
}
}
这样不行.
public static void main(String[] args) {
PrintSample ps = new PrintSample();ps.pack();
ps.setVisible(true);
ps.addWindowListener(ps);
}
public void windowActivated(WindowEvent e){
}
public void windowClosed(WindowEvent e){
stm.cut1();
System.out.println("lskjdf");
}
public void windowClosing(WindowEvent e){
}
public void windowDeactivated(WindowEvent e){
}
public void windowIconified(WindowEvent e){
}
public void windowOpened(WindowEvent e){
}
public void windowDeiconified(WindowEvent e){
}
}
这样不行.
|
protected void processWindowEvent(WindowEvent e) {
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
这样也行,你把这个方法添到你的程序中看看
应该也是可以的
更方便一些
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
这样也行,你把这个方法添到你的程序中看看
应该也是可以的
更方便一些
|
你在windowClosing事件中写保证没问题
|
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e)
{
/////add your code
}
});
public void windowClosing(WindowEvent e)
{
/////add your code
}
});