need help with background color
hello im new to this and i need help with making my background change when i push my buttons, no errors come up with the compiler, this is what my code looks like at the moment.
import java.awt.*;
import java.awt.event.*;
public class ColorButtons extends Frame implements ActionListener, ItemListener
{
public ColorButtons()
{
//set Layouts
this.setLayout(new FlowLayout());
//Add buttons
Panel inputPanel = new Panel();
CheckboxGroup options = new CheckboxGroup();
Checkbox Blue = new Checkbox("Blue",false,options);
Checkbox Red = new Checkbox("Red",false, options);
Checkbox Yellow = new Checkbox("Yellow",false,options);
Checkbox Pink = new Checkbox("Pink",false,options);
Checkbox Gray = new Checkbox("Gray",false,options);
//add components to input panel
inputPanel.add(Blue);
inputPanel.add(Red);
inputPanel.add(Yellow);
inputPanel.add(Pink);
inputPanel.add(Gray);
//add panels to frame
add(inputPanel, BorderLayout.CENTER);
// override the windowClosing event
addWindowListener(
new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
);
}
public static void main(String[] args)
{
// set frame properties
ColorButtons f = new ColorButtons();
f.setTitle("Whats My Color?");
f.setBounds(200,200,600,300);
f.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
String arg = e.getActionCommand();
System.out.println("arg = " + arg);
if (arg.equals("Yellow"))
setBackground(Color.yellow);
if (arg.equals("Red"))
setBackground(Color.red);
if (arg.equals("Blue"))
setBackground(Color.blue);
if (arg.equals("Pink"))
setBackground(Color.pink);
if (arg.equals("Gray"))
setBackground(Color.gray);
repaint();
}
public void itemStateChanged(ItemEvent ie){
if(ie.getStateChange() == ItemEvent.SELECTED) {
Object item = ie.getItem();
String arg = (String)item;
if (arg == "Yellow")
setBackground(Color.yellow);
if (arg == "Red")
setBackground(Color.red);
if (arg == "Blue")
setBackground(Color.blue);
if (arg == "Pink")
setBackground(Color.pink);
if (arg == "Gray")
setBackground(Color.gray);
}
}
}

