What is wrong with the following code?
class ExitListener implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
System.exit(0) ;
}
}
ActionListener exitListener = new ExitListener() ;
JMenu exitMenu = new JMenu("Exit") ;
exitMenu.addActionListener(exitListener) ;
JMenuBar menuBar = new JMenuBar() ;
menuBar.add(exitMenu) ;
A) The ExitListener class is not public
B) You cannot attach a listener to a menu, only to a menu item
C) You cannot add a menu to the menu bar, only a menu item
D) You need to use a menu listener, not an action listener
Correct Answer:
Verified
Q37: A _ is a combination of a
Q38: What type of object can be added
Q39: What type does the method getSelectedItem in
Q40: Which method can a program use to
Q41: What is known for certain from this
Q43: What features do GUI builders have to
Q44: If the method makeMenuItem is called four
Q45: Which elements of creating a graphical user
Q46: You can add a(n) _ to a
Q47: Which of the following generate action events?
A)Buttons
B)Menu
Unlock this Answer For Free Now!
View this answer and more for free by performing one of the following actions
Scan the QR code to install the App and get 2 free unlocks
Unlock quizzes for free by uploading documents