如何在 windowslistener 方法中调用 JFrame(class 本身)?

How do I call the JFrame (the class itself) inside a windowslistener method?

我想在 WindowsListener 方法中引用 JFrame(即 class 本身)。有什么办法吗?

    diag_ap.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            this.setEnabled(true); //does not work
        }
    }); 

我希望调用 class 框架并将其禁用,以便唯一可以按下的是 JDialog 框。

new WindowAdapter().windowClosing(event) 方法中使用 this 关键字引用您创建的 WindowAdapter 对象。

要在WindowAdapter 中引用JFrame 的对象,您应该使用MyJFrame.this。所以,代码应该是,

diag_ap.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            MyJFrame.this.setEnabled(true); // replace MyJFrame with name of your JFrame
        }
    });