Hi there, can someone please help me with my compiling errors in my checkerboard assignment.
Thank you
CODE
import javax.swing.JOptionPane;
import java.awt.*;
import java.awt.event.*;
public class myCheckerboard extends Frame implements ActionListener
{
//declare variables
int start, stop, step;
Panel boardPanel = new Panel();
TextArea boardDisplay[] = new TextArea[16];
Panel buttonPanel = new Panel();
Button goButton = new Button("Go");
Panel inputPanel = new Panel();
Label startLabel = new Label("Start");
TextField startField = new TextField();
Label stopLabel = new Label("Stop");
TextField stopField = new TextField();
Label stepLabel = new Label("Step");
TextField stepField = new TextField();
public myCheckerboard()
{
this.setLayout(new BorderLayout());
boardPanel.setLayout(new GridLayout(4,4,2,3));
inputPanel.setLayout(new FlowLayout());
buttonPanel.setLayout(new FlowLayout());
for (int i=0; i<16; i++)
{
boardDisplay[i] = new TextArea(null,3,5,3);
if(i<16)
boardDisplay[i].getText();
else
boardDisplay[i].setEditable(false);
boardDisplay[i].setBackground(Color.white);
boardPanel.add(boardDisplay[i]);
}
//add components to the button
buttonPanel.add(goButton);
//add components to input panel
inputPanel.add(startLabel);
inputPanel.add(startField);
inputPanel.add(stopLabel);
inputPanel.add(stopField);
inputPanel.add(stepLabel);
inputPanel.add(stepField);
//add panels to frame
add(buttonPanel, BorderLayout.SOUTH);
add(inputPanel, BorderLayout.CENTER);
add(boardPanel, BorderLayout.NORTH);
goButton.addActionListener(this);
addWindowListener(
new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
);
}//end of constructor
public void actionPerformed(ActionEvent e)
{
if (i < 15)
start = Integer.parseInt(startField.getText());
stop = Integer.parseInt(stopField.getText());
step = Integer.parseInt(stepField.getText());
for (int i=0; i<16; i++)
boardDisplay[i].setBackground(Color.magenta);
for(int i=start; i<stop; i+=step)
boardDisplay[i].setBackground(Color.yellow);
else
JOptionPane.showMessageDialog(null,"You must enter a value less than 15."."Error",JOptionPane.ERROR_MESSAGE);
}
public static void main(String[]args)
{
Checkerboard f = new Checkerboard();
f.setBounds(50,100,300,400);
f.setTitle("Checkerboard Array");
f.setVisible(true);
}
}
Compiling Errors:
C:\Users\Documents\Java Applications\Chapter05\myCheckerboard.java:93: 'else' without 'if'
else
^
C:\Users\Documents\Java Applications\Chapter05\myCheckerboard.java:81: cannot resolve symbol
symbol : variable i
location: class myCheckerboard
if (i < 15)
^
.\Checkerboard.java:71: illegal start of expression
public void actionPerformed(ActionEvent e)
^
.\Checkerboard.java:93: ';' expected
}
^
.\Checkerboard.java:12: Checkerboard should be declared abstract; it does not define actionPerformed(java.awt.event.ActionEvent) in Checkerboard
public class Checkerboard extends Frame implements ActionListener
^
5 errors
Tool completed with exit code 1