What addActionListener does?

后端 未结 5 862
终归单人心
终归单人心 2020-12-31 14:26

I have the following code:

JButton button = new JButton(\"Clear\");
button.addActionListener(this);

As far as I understand I create a butto

5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-31 14:45

    Each JButton, has an EventListenerList. Calling addActionListener(this) adds your ActionListener, a callback function named actionPerformed(), to the list. You can see an outline of the code that calls your method here. The actual fireActionPerformed() method is in AbstractButton. A JButton is a JComponent, which you can see listed among the various classes that use the event listener list mechanism.

提交回复
热议问题