我只是在测试我的代码而我正试图这样做,当我点击"推"按钮时,第一个textArea打印出"你好".
但是我不断收到这个错误:不能在不同方法中定义的内部类中引用非final变量textArea
这是我的代码:
import java.awt.BorderLayout;
Run Code Online (Sandbox Code Playgroud)
公共类WindowBuilderTest扩展了JFrame {
private JPanel contentPane;
private JTextField textField;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
WindowBuilderTest frame = new WindowBuilderTest();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public WindowBuilderTest() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 400, 400);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
GridBagLayout gbl_contentPane = new GridBagLayout();
gbl_contentPane.columnWidths …Run Code Online (Sandbox Code Playgroud)