Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/342.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 向netbeans中的按钮添加操作侦听器_Java_Swing_Netbeans_Jbutton_Actionlistener - Fatal编程技术网

Java 向netbeans中的按钮添加操作侦听器

Java 向netbeans中的按钮添加操作侦听器,java,swing,netbeans,jbutton,actionlistener,Java,Swing,Netbeans,Jbutton,Actionlistener,如何向netbeans中的按钮添加操作侦听器 我试着这么做,但我不知道怎么做 button.addactionlistener(null); 首先,您需要在类中实现action listener public class YourProject extends JFrame implements ActionListener{ yourbutton.addActionListener(this); 您需要添加覆盖方法 我希望这对您有所帮助。您也可以通过其他方式添加 JButton jb= n

如何向netbeans中的按钮添加操作侦听器

我试着这么做,但我不知道怎么做

button.addactionlistener(null);

首先,您需要在类中实现action listener

public class YourProject extends JFrame implements ActionListener{
yourbutton.addActionListener(this);
您需要添加覆盖方法


我希望这对您有所帮助。

您也可以通过其他方式添加

JButton jb= new JButton("ok");

jb.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent ae)
      {System.out.println("You have clicked ok button");
    }
});

与在Eclipse和任何其他IDE中添加它的方式相同。(Java区分大小写,addactionlistener与addactionlistener不同)