Java 当我按下按钮时,按钮不工作了?

Java 当我按下按钮时,按钮不工作了?,java,Java,我用java创建了简单的GUI来测试单击按钮的工作。但当我按下按钮时,按钮不起作用 import javax.swing.*; import java.awt.event.*; import java.util.*; public class rigotechnology implements ActionListener{ JFrame test; JButton Try; public void main(){ JFrame test = new J

我用java创建了简单的GUI来测试单击按钮的工作。但当我按下按钮时,按钮不起作用

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

public class rigotechnology implements ActionListener{
    JFrame test;
    JButton Try;

    public void main(){
       JFrame test = new JFrame("TEST FILE");
       test.setLayout(null);
       JButton Try = new JButton("TRY");
       Try.setBounds(50,50,80,80);
       test.add(Try);
       test.setSize(200,200);
       test.setVisible(true);
       Try.addActionListener(this);
    }

    public void actionPerformed(ActionEvent e){
       if(e.getSource()==Try){
          JOptionPane.showMessageDialog(test,"hello");
       }
    }

   public static void main(String args[]){
        rigotechnology o = new rigotechnology();
        o.main();
     }
}

在main方法中,您重新定义了本地JButton Try,因此Try-In-actionPerformed始终为null

public void main(){
   test = new JFrame("TEST FILE");
   test.setLayout(null);
   Try = new JButton("TRY");
   Try.setBounds(50,50,80,80);
   test.add(Try);
   test.setSize(200,200);
   test.setVisible(true);
   Try.addActionListener(this);
}

什么是不工作?如果它工作了,它会做什么,它会做什么呢;请坚持命名惯例,尝试,不要尝试。避免已经被关键词占据的名称,选择更合适的名称。还有,它尝试了什么?为什么不试试选择按钮什么的。当我按下“尝试”按钮时,我能做些什么来弹出消息“你好”?