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
Q43: What features do GUI builders have to
Q48: What is the most time-effective way to
Q66: Which elements of creating a graphical user
Q67: How do the lifetimes of the three
Q68: When method makeMenuItem is called, how many
Q69: The documentation for the JSlider class lists
Q70: Which of the following adds a border
Q72: Based on the statement below, which of
Q74: When a menu item is selected, what
Q76: The code below will not compile successfully
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