Write a program with three checkboxes and a circle drawn in black. Each check box represents a color(red, green, or blue). Depending on the checkboxes selected, compute the resulting color as follows. If a checkbox is selected, assign the value 255 to the amount of the corresponding color. If a checkbox is not selected, assign 0 to the amount of the corresponding color. For example, if the checkbox representing the colors red and blue are selected, the resulting color should be Color(255,0,255). Color the circle appropriately.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Group5 extends JFrame
{
private Container contents;
private JCheckBox red, green, blue;
private int redValue, greenValue, blueValue;
private JLabel label;
public Group5()
{
super("Selecting a Color");
contents = getContentPane();
contents.setLayout( new FlowLayout());
red = new JCheckBox("red");
green = new JCheckBox("green");
blue = new JCheckBox("blue");
contents.add( red );
contents.add( green );
contents.add( blue );
CheckBoxHandler cbh = new CheckBoxHandler();
red.addItemListener(cbh);
blue.addItemListener(cbh);
green.addItemListener(cbh);
setSize(225,200);
setVisible(true);
}
private class CheckBoxHandler implements ItemListener
{
public void itemStateChanged( ItemEvent ie )
{
if( ie.getSource() == red )
{
if( ie.getStateChange() == ItemEvent.SELECTED)
redValue = 255;
else
redValue = 0;
}
else if( ie.getSource() == blue)
{
if( ie.getStateChange() == ItemEvent.SELECTED)
blueValue = 255;
else
blueValue = 0;
}
else if( ie.getSource() == green)
{
if( ie.getStateChange() == ItemEvent.SELECTED)
greenValue = 255;
else
greenValue = 0;
}
}
}
public static void main( String [] args)
{
Group5 g5 = new Group5();
g5.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
}
I HAVE THE CHECKBOXES DOWN I JUST NEED ASSISTANCE ON MAKING THE CIRCLE AND FILLING IT IN WITH THE APPROPRIATE COLOR
Aucun commentaire:
Enregistrer un commentaire