如何将动作侦听器添加到netbeans中的按钮
我试图这样做,但我不知道怎么做
button.addactionlistener(null);
答案 0 :(得分:1)
首先,您需要在班级中实现动作侦听器。
public class YourProject extends JFrame implements ActionListener{
yourbutton.addActionListener(this);
您需要添加覆盖方法。
我希望这会对你有所帮助。
答案 1 :(得分:1)
你也可以通过另一种方式添加
JButton jb= new JButton("ok");
jb.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae)
{System.out.println("You have clicked ok button");
}
});