Hi there, can someone please help:
This application is suppose to change color to correspond with the start, stop and step values entered by the user and to create a looping structurethat allows the user to specify how many times the loop statements will be executed.
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(2);
Label stopLabel = new Label("Stop");
TextField stopField = new TextField(2);
Label stepLabel = new Label("Step");
TextField stepField = new TextField(2);
public myCheckerboard()
{
this.setLayout(new BorderLayout());
boardPanel.setLayout(new GridLayout(4,4,2,3));
inputPanel.setLayout(new FlowLayout());
buttonPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
for (int i=0; i<16; i++)
{
boardDisplay[i] = new TextArea(null,3,5,3);
if(i<16)
boardDisplay[i].setText("" + i);
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 static void main(String[]args)
{
myCheckerboard f = new myCheckerboard();
f.setBounds(50,100,300,400);
f.setTitle("Checkerboard Array");
f.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if(i>15)
{
JOptionPane.showMessageDialog(null, "You must enter a value less than 15.","Error",JOptionPane.ERROR_MESSAGE);
}
else
{
start = Integer.parseInt(startField.getText());
stop = Integer.parseInt(stopField.getText());
step = Integer.parseInt(stepField.getText());
}
for (int i = 0; i <15; i++)
{
panelDisplay[i].setBackground(Color.magenta);
}
for(int i = start; i < stop; i += step)
{
panelDisplay[i].setBackground(Color.yellow);
}
}
}
Compiling Errors:
C:\Users\Patricia\Documents\Java Applications\myCheckerboard.java:88: cannot resolve symbol
symbol : variable i
location: class myCheckerboard
if(i>15)
^
C:\Users\Patricia\Documents\Java Applications\myCheckerboard.java:100: cannot resolve symbol
symbol : variable panelDisplay
location: class myCheckerboard
panelDisplay[i].setBackground(Color.magenta);
^
C:\Users\Patricia\Documents\Java Applications\myCheckerboard.java:104: cannot resolve symbol
symbol : variable panelDisplay
location: class myCheckerboard
panelDisplay[i].setBackground(Color.yellow);
^
3 errors
Tool completed with exit code 1
Hope someone can help