当前位置: 技术问答>java相关
菜鸟小问题!
来源: 互联网 发布时间:2015-08-23
本文导语: 在主程序冲通过多线程打开了多个Receiver类的窗口 public class Receiver extends JFrame implements Runnable{ ''''''''''''''''''''' ''''''''''''''''''''' ..................... } 怎样关闭这样的窗口而不关闭整个工程啊?以前用Delphi的时候用...
在主程序冲通过多线程打开了多个Receiver类的窗口
public class Receiver extends JFrame implements Runnable{
'''''''''''''''''''''
'''''''''''''''''''''
.....................
}
怎样关闭这样的窗口而不关闭整个工程啊?以前用Delphi的时候用close就行了,java里要怎么写?
public class Receiver extends JFrame implements Runnable{
'''''''''''''''''''''
'''''''''''''''''''''
.....................
}
怎样关闭这样的窗口而不关闭整个工程啊?以前用Delphi的时候用close就行了,java里要怎么写?
|
在Receiver的初始化方法jbInit()中加入:
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
或者在Receiver中重载processWindowEvent()方法:
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
//System.exit(0);
dispose();
}
}
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
或者在Receiver中重载processWindowEvent()方法:
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
//System.exit(0);
dispose();
}
}
|
在这个类的构造器里加入这个方法:
public class Receiver extends JFrame implements Runnable
{
'''''''''''''''''''''
'''''''''''''''''''''
public Receiver()
{
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
System.exit(0);
}
});
……………………
}
.....................
}
public class Receiver extends JFrame implements Runnable
{
'''''''''''''''''''''
'''''''''''''''''''''
public Receiver()
{
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
System.exit(0);
}
});
……………………
}
.....................
}
|
GZ!!!