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

Are you sure you have a 'Checkerboard.java' or 'checkorboard.java'?

It's definitely checkerboard. When I was messing with it I used a capital C by accident, I fixed that and the error no longer pops up. Although the code compiles without errors, it still displays a blank empty box when I go to run it. Any ideas why it does this? Do you think it may be a MAC/PC thing? Cause it worked at school on a PC using Windows XP.

The project file you are using, assuming eclipse, will reference a file named with a capital C and it could not be changed inside of the project without manually changing it. Remember mac's are case sensitive and windows machines are not.

What version of the JRE are you using on the MAC?

I see the code now, you must have class and filename as the same

checkerboard and Checkerboard.java

if it comes to it, just copy the file contents, delete the file from the project, create the file with the uppercase and paste it back in the project

Do you find that out in "Java Preferences"

If so, there is:
J2SE 1.4.2
J2SE 5.0

And I am not using jbuilder (I can never figure that thing out; I am very much a beginner as you can probably tell from my code). I use Text-Mate Version 1.5.7

Also, if it's not too much, can someone check and see if this runs on their Windows machine?

take a look at your text-mate project file and look for the work checkboard and make sure you are using the proper case

lowercase for the filename, windows can find the file and mac can't

take a look at your text-mate project file and look for the work checkboard and make sure you are using the proper case

lowercase for the filename, windows can find the file and mac can't

Yeah, the case is correct. I tried both. Right now the filename is: Checkerboard.java and the code is ...

/*
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);
			}
		
}

I also tried the suggestion of copy and pasting into a new file and deleting the old one. Thats what this one is. It compiles but still gives me a blank box that says "Checkerboard Array" so just the title comes up.

You forgot to add the Panel that you were adding everything too!

/*
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(fieldPanel, BorderLayout.NORTH); // edit
		add(buttonsPanel, BorderLayout.SOUTH); // edit

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

edit: I think your original intent was this version (maybe) --

Edit2: Also it's not really the .java file that matters.

Once you compile and generate a .class file, that file will be referenced... so if your .class file have any case-errors in it, you'll more than likely need to delete or move the .class file and not the .java file.

Also, sort your labels ;)

Label LabelStop = new Label("Start");
Label LabelStart = new Label("Stop");

why the hell is he using AWT instead of Swing, and why in heaven's name is he not keeping to the correct convention for naming variables and other entities?

Ehm beginner...

this is basically a j2se programe. it is very use ful to detect the errors .i will check the givven code now.ok u done a good job.

commented: This post is worthless. You only posted to spam a link to your site. -2

Ehm beginner...

all the more reason to read and follow the rules to the letter.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.