单选题:Which is the best way to receive events when a JButton component
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
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