Solved

Why Doesn't the Following Code Compile Correctly

Question 59

Multiple Choice

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:

verifed

Verified

Unlock this answer now
Get Access to more Verified Answers free of charge

Related Questions

Unlock this Answer For Free Now!

View this answer and more for free by performing one of the following actions

qr-code

Scan the QR code to install the App and get 2 free unlocks

upload documents

Unlock quizzes for free by uploading documents