I compiled this at school and swear it ran like a week ago. That was on a PC using Textpad, now I am on a mac using TextMate and I keep getting this error:
class Checkerboard is public, should be declared in a file named Checkerboard.java
public class Checkerboard extends Frame implements ActionListener
^
1 error
Also, it ran the first time I compiled on the mac, but was a big blank box. Any ideas what this could be?
class Checkerboard is public, should be declared in a file named Checkerboard.java
public class Checkerboard extends Frame implements ActionListener
^
1 error
/*
Page #: Page 372 #3
Filename: checkerboard.java
*/
import java.awt.*;
import java.awt.event.*;
public class checkerboard extends Frame implements ActionListener
{
//declare variables
Panel checkerPanel = new Panel();
TextField[] board = new TextField[16];
int start, stop, step;
Panel fieldPanel = new Panel();
TextField fieldStart = new TextField(5);
TextField fieldStop = new TextField(5);
TextField fieldStep = new TextField(5);
Label LabelStop = new Label("Start");
Label LabelStart = new Label("Stop");
Label LabelStep = new Label("Step");
Panel buttonsPanel = new Panel();
Button goButton = new Button("Go");
Button clearButton = new Button("Clear");
public checkerboard()
{
start = 0;
stop = 0;
step = 0;
this.setLayout(new BorderLayout());
checkerPanel.setLayout(new GridLayout(4, 4));
fieldPanel.setLayout(new GridLayout(2, 3));
buttonsPanel.setLayout(new FlowLayout());
for(int i = 0; i<16; i++)
{
board[i] = new TextField();
board[i].setText("" + i);
board[i].setEditable(false);
checkerPanel.add(board[i]);
}
fieldPanel.add(fieldStart);
fieldPanel.add(fieldStop);
fieldPanel.add(fieldStep);
fieldPanel.add(LabelStart);
fieldPanel.add(LabelStop);
fieldPanel.add(LabelStep);
buttonsPanel.add(goButton);
buttonsPanel.add(clearButton);
goButton.addActionListener(this);
//add windowListener p.350
addWindowListener(
new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
);
}
public void actionPerformed(ActionEvent e)
{
String arg = e.getActionCommand();
if(arg == "Go")
{
start = Integer.parseInt(fieldStart.getText());
stop = Integer.parseInt(fieldStop.getText());
step = Integer.parseInt(fieldStep.getText());
if (start < 0 || stop < 0 || step < 0) arg = "clear";
for (int i=0; i<16; i++)
board[i].setBackground(Color.magenta);
for (int i=start; i<=stop; i=i+step)
board[i].setBackground(Color.yellow);
}
if (arg== "Clear")
{
fieldStop.setText("");
fieldStart.setText("");
fieldStep.setText("");
for (int i=0; i<16; i++)
board[i].setBackground(Color.white);
}
}
public static void main(String[] args)
{
checkerboard f = new checkerboard();
f.setBounds(50, 100, 300, 400);
f.setTitle("Checkerboard Array");
f.setVisible(true);
}
}