Biology Forums - Study Force

Science-Related Homework Help Computer Studies Topic started by: Eels on Dec 16, 2016



Title: Why doesn't the following code compile correctly?import java.awt.*;import java.awt.event.*;import ...
Post by: Eels on Dec 16, 2016
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.


Title: Re: Why doesn't the following code compile correctly?import java.awt.*;import ...
Post by: Toothy on Dec 17, 2016
Content hidden


Title: Re: Why doesn't the following code compile correctly?import java.awt.*;import java.awt.event.*;import ...
Post by: Eels on Jan 31, 2017
YOU'RE AWESOME


Title: Re: Why doesn't the following code compile correctly?import java.awt.*;import java.awt.event.*;import ...
Post by: Toothy on Mar 16, 2017
Thanks for providing feedback