0

请有人解释一下 ActionListener 的控制流程,例如我们在注册了一个组件的类中实现了 t 并且确实覆盖了

 actionPerformed(ActionEvent e) 

现在我很困惑,当我们点击注册按钮 what is the role of (this)addActionListener (this);

4

1 回答 1

1

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
    }
}
于 2013-04-24T12:50:39.517 回答