[英]How do I call the JFrame (the class itself) inside a windowslistener method?
I want to reference the JFrame (which is the class itself) inside a WindowsListener method. 我想在WindowsListener方法中引用JFrame(这是类本身)。 Is there any way to do this?
有什么办法吗?
diag_ap.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
this.setEnabled(true); //does not work
}
});
I expect to call the class frame and disable it so that the only thing that can be pressed is the JDialog box. 我希望调用该类框架并将其禁用,以便唯一可以按下的是JDialog框。
Using this
keyword inside new WindowAdapter().windowClosing(event)
method refers to the WindowAdapter object that you created. 在
new WindowAdapter().windowClosing(event)
方法中使用this
关键字引用您创建的WindowAdapter对象。
To refer the object of the JFrame inside WindowAdapter, you should use MyJFrame.this
. 要在WindowAdapter中引用JFrame的对象,应使用
MyJFrame.this
。 So, the code should be, 因此,代码应该是
diag_ap.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
MyJFrame.this.setEnabled(true); // replace MyJFrame with name of your JFrame
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.