[英]FlowControl in ActionListener method in Java When JButton Clicked
请有人向我解释ActionListener的控制流程,例如我们在类中向组件注册了t并实现了重写
actionPerformed(ActionEvent e)
现在我很困惑,当我们单击注册按钮时, addActionListener (this);
what is the role of (this)
addActionListener (this);
addActionListener (this)
指示当前类实现ActionListener
接口并提供actionPerformed(ActionEvent e)
例:
public class SampleListener implements ActionListener{
public static void main(String[] args) {
JButton btn1 = new JButton("Click me");
btn1.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent event) {
// code
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.