[英]adding action listener to a button in netbeans
How to add an action listener to a button in netbeans 如何将动作侦听器添加到netbeans中的按钮
I tried to do that, but I don't know how 我试着这样做,但我不知道怎么做
button.addactionlistener(null);
First you need to implement action listener in your class. 首先,您需要在类中实现动作侦听器。
public class YourProject extends JFrame implements ActionListener{
yourbutton.addActionListener(this);
The you need to add the override method. 您需要添加覆盖方法。
I hope this helps you. 我希望这可以帮助你。
YOu can also add by another way 你也可以通过另一种方式添加
JButton jb= new JButton("ok");
jb.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae)
{System.out.println("You have clicked ok button");
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.