Java 无法使用ActionListener访问此.draw()

Java 无法使用ActionListener访问此.draw(),java,swing,actionlistener,Java,Swing,Actionlistener,我试图使按钮刷新窗口,但收到以下错误消息: Test.java:21: error: cannot find symbol this.draw(); ^ symbol: method draw() 1 error 代码如下: import javax.swing.*; import java.awt.event.*; public class Test { JFrame frame;

我试图使按钮刷新窗口,但收到以下错误消息:

Test.java:21: error: cannot find symbol
                    this.draw();
                        ^
  symbol: method draw()
1 error
代码如下:

import javax.swing.*;
import java.awt.event.*;

public class Test {
    JFrame frame;

    public void createMainWindow() {
        frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(800,600);
        JButton refresh = new JButton("Refresh");
        refresh.setBounds(620, 20, 100, 30);
        refresh.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    this.draw();
                }
            }
            );
        frame.setLayout(null);
        frame.add(refresh);
        frame.setVisible(true);
        frame.setTitle("Title");
    }

    public void draw() {
        // Code                                                                                                                                                                                                    
        frame.setVisible(true);
    }
}

我显然误解了这一点

创建显式匿名类时,
引用
ActionListener的实例。要绘制外部类,请使用
Test.this.draw()
,或者更简单地说,用lambda替换整个侦听器(从技术上讲,它创建了一个匿名类,但不会接管
):


创建显式匿名类时,
引用
ActionListener
的实例。要绘制外部类,请使用
Test.this.draw()
,或者更简单地说,用lambda替换整个侦听器(从技术上讲,它创建了一个匿名类,但不会接管
):

引用ActionListner

你想要:

Test.this.draw();
引用测试类中的方法

引用ActionListner

你想要:

Test.this.draw();
引用测试类中的方法

Test.this.draw();