here is the code
/*
Chapter 6: Borders
Programmer: ELIIIIIIIIIIIIIIIIIIIIIIIIII DOOOOOOOOONNNNNNNNAAAAAAAAAAAAAAAAAAAAAAAHHHHHHUUUUUUUEEEEEEEEEE
Date:
Filename: Borders.java
Purpose:
*/
import java.awt.*;
import java.awt.event.*;
public class Borders2 extends Frame implements ActionListener, ItemListener
{
public Borders2()
{
setBackground(Color.red);
//set the layout
setLayout(new BorderLayout(50,50));
//Add buttons
Button Red = new Button("Red");
Button Yellow = new Button("Yellow");
Button Cyan = new Button("Cyan");
Button Magenta = new Button("Magenta");
Choice choicepanel = new Choice();
choicepanel.add(" ");
choicepanel.add("Red");
choicepanel.add("Yellow");
choicepanel.add("Cyan");
choicepanel.add("Magenta");
choicepanel.add("White");
add(choicepanel);
Red.addActionListener(this);
Yellow.addActionListener(this);
Cyan.addActionListener(this);
Magenta.addActionListener(this);
choicepanel.addItemListener(this);
Red.setActionCommand("Red");
Yellow.setActionCommand("Yellow");
Cyan.setActionCommand("Cyan");
Magenta.setActionCommand("Magenta");
add(Red, BorderLayout.NORTH);
add(Yellow, BorderLayout.SOUTH);
add(Cyan, BorderLayout.EAST);
add(Magenta, BorderLayout.WEST);
add(choicepanel, BorderLayout.CENTER);
//override the windowClosing event
addWindowListener(
new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
);
}
public void actionPerformed(ActionEvent e)
{
String arg = e.getActionCommand();
if(arg == "Red")
setBackground(Color.red);
if(arg == "Yellow")
setBackground(Color.yellow);
if(arg == "Cyan")
setBackground(Color.cyan);
if(arg == "Magenta")
setBackground(Color.magenta);
}
public void itemStateChanged(ItemEvent ie)
{
String arg = e.getActionCommand();
if(arg == "Red")
setBackground(Color.red);
if(arg == "Yellow")
setBackground(Color.yellow);
if(arg == "Cyan")
setBackground(Color.cyan);
if(arg == "Magenta")
setBackground(Color.magenta);
}
public static void main(String[] args)
{
// set frame properties
Borders f = new Borders();
f.setTitle("Border Application");
f.setBounds(200,200,300,300);
f.setVisible(true);
}
}
the problem im having is in the itemstate changed fucntion. it says that it cant find the variable e in String arg = e.getActionCommand();. i cant find the answer in my book.
can anyone help?