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);

}

}

}

[2503 byte] By [Amanda632a] at [2007-11-26 13:42:29]
# 1
Use .equals instead of == to compare String values:if (arg.equals("Red"))You have it right in actionPerformed, but not in itemStateChanged.
doremifasollatidoa at 2007-7-8 0:00:21 > top of Java-index,Java Essentials,Java Programming...
# 2

please use the code tags, it'll make it easier for ppl to read, and if we can read it, we can help.

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);

}

}

}

youaresofakingwetoddeda at 2007-7-8 0:00:21 > top of Java-index,Java Essentials,Java Programming...
# 3
still not working =\
Amanda632a at 2007-7-8 0:00:21 > top of Java-index,Java Essentials,Java Programming...
# 4
> still not working =\you need to addItemListener to the radio buttonsi.e.Blue.addItemListener(this);do it for all the radio buttons.
youaresofakingwetoddeda at 2007-7-8 0:00:21 > top of Java-index,Java Essentials,Java Programming...
# 5
apparently they are checkboxes..so that's what i meant :)
youaresofakingwetoddeda at 2007-7-8 0:00:21 > top of Java-index,Java Essentials,Java Programming...
# 6
yay ty it worked :)
Amanda632a at 2007-7-8 0:00:21 > top of Java-index,Java Essentials,Java Programming...