-->
当前位置:首页 > 题库

单选题:Which is the best way to receive events when a JButton component

Luz5年前 (2021-05-10)题库924
Which is the best way to receive events when a JButton component is selected? @[B](2)

A. Create an implementation of ButtonListener and add it as a listener to the JButton component by invoking addButtonListener().
B. Create an implementation of ActionListener and add it as a listener to the JButton component by invoking addActionListener().
C. Subclass ActionAdapter and override the actionPerformed() method. Then, add an instance of the subclass as a listener to the JButton component by invoking addActionListener().
D. Subclass MouseAdapter and override the mouseClicked() method. Then, add an instance of the subclass as a listener to the JButton component by invoking addMouseListener().



A.Create an implementation of ButtonListener and add it as a listener to the JButton component by invoking addButtonListener().
B.Create an implementation of ActionListener and add it as a listener to the JButton component by invoking addActionListener().
C.Subclass ActionAdapter and override the actionPerformed() method. Then, add an instance of the subclass as a listener to the JButton component by invoking addActionListener().
D.Subclass MouseAdapter and override the mouseClicked() method. Then, add an instance of the subclass as a listener to the JButton component by invoking addMouseListener().


答案:B