Why doesn't the following code compile correctly?
Import java.awt.*;
Import java.awt.event.*;
Import javax.swing.*;
Public class ColorCheckBoxWindow extends JFrame
{
Private JCheckBox greenCheckBox;
Private final int WINDOW_WIDTH = 300, WINDOW_HEIGHT = 100;
Public ColorCheckBoxWindow()
{
SetTitle("Green Check Box") ;
SetSize(WINDOW_WIDTH, WINDOW_HEIGHT) ;
SetDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) ;
GreenCheckBox = new JCheckBox("Green") ;
GreenCheckBox.addItemListener(new CheckBoxListener() ) ;
SetLayout(new FlowLayout() ) ;
Add(greenCheckBox) ;
SetVisible(true) ;
}
Public void itemStateChanged(ItemEvent e)
{
If (e.getSource() == greenCheckBox)
{
System.exit(0) ;
}
}
}
A) ColorCheckBoxWindow is not implementing the correct listener.
B) The button cannot be added to the content pane.
C) The itemStateChanged method cannot be coded here.
D) greenCheckBox should not be a private member.
Correct Answer:
Verified
Q9: A GUI program automatically stops executing when
Q10: When a splash screen is displayed, the
Q50: When adding components to a container that
Q51: Check boxes may be grouped in a
Q53: The ActionEvent argument that is passed to
Q54: Which of the following statements is NOT
Q55: This is a graphic image that is
Q56: A common technique for writing an event
Q58: What will be the result of executing
Q60: Assume that the variable checkbox references a
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