I am following instructions from an assignment in book. I am creating buttons and on one button "yellow" when a user clicks on it the background changes to yellow. I am getting compile errors.
Error; cannot find symbol
add(Red, BorderLayout.Red);
same goes for add(Yellow, BorderLayout.Yellow);
add(Cyan, BorderLayout.CYAN);
add(Magenta, BorderLayout.MAGENTA);
add(White, BorderLayout.WHITE);
also error; cannot find symbol
for ButtonRed.addActionListener(this);
ButtonYellow.addActionListener(this);
ButtonCyan.addActionListener(this);
ButtonMagenta.addActionListner(this);
ButtonWhite.addActionListener(this);
Here is my code.
/*
Chapter 6: Borders
Programmer:Jesse-le Edwards
Date:11-16-14
Filename: Buttons.java
Purpose:
*/
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class Buttons extends Frame implements ActionListener {
public void paint(Graphics g) {
setBackground(Color.red);
}
public void actionPerformed(ActionEvent e) {
String arg = e.getActionCommand();
if (arg == "Yellow") {
setBackground(Color.yellow);
}
}
public Buttons() {
//set the layout
setLayout(new BorderLayout(20, 5));
//Add buttons
Button Red = new Button("Red");
Button Yellow = new Button("Yellow");
Button Cyan = new Button("Cyan");
Button West = new Button("Magenta");
Button White = new Button("White");
add(Red, BorderLayout.RED);
add(Yellow, BorderLayout.YELLOW);
add(Cyan, BorderLayout.CYAN);
add(Magenta, BorderLayout.MAGENTA);
add(White, BorderLayout.WHITE);
ButtonRed.addActionListener(this);
ButtonYellow.addActionListener(this);
ButtonCyan.addActionListener(this);
ButtonMagenta.addActionListner(this);
ButtonWhite.addActionListener(this);
//override the windowClosing event
addWindowListener(
new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
}
);
}
public static void main(String[] args) {
// set frame properties
Buttons f = new Buttons();
f.setTitle("Border Application");
f.setBounds(200, 200, 300, 300);
f.setVisible(true);
}
}