Top Posters
Since Sunday
New Topic  
Eels Eels
wrote...
Posts: 716
Rep: 0 0
7 years ago
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) The itemStateChanged method should be coded in a CheckBoxListener class.
B) greenCheckBox should not be a private member.
C) The button cannot be added to the content pane.
D) ColorCheckBoxWindow is not implementing the correct listener.
Textbook 
Starting Out with Java: Early Objects

Starting Out with Java: Early Objects


Edition: 4th
Author:
Read 211 times
3 Replies
Replies
Answer verified by a subject expert
ToothyToothy
wrote...
Top Poster
Posts: 744
Rep: 4 0
7 years ago
Sign in or Sign up in seconds to unlock everything for free
More solutions for this book are available here
1

Related Topics

Eels Author
wrote...
7 years ago
YOU'RE AWESOME
wrote...
7 years ago
Thanks for providing feedback
New Topic      
Explore
Post your homework questions and get free online help from our incredible volunteers
  1124 People Browsing
Related Images
  
 226
  
 609
  
 240
Your Opinion
What's your favorite math subject?
Votes: 293