Java 向netbeans中的按钮添加操作侦听器
如何向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
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不同)