Thanks
Expand|Select|Wrap|Line Numbers
- public void actionPerformed(ActionEvent e)
- {
- //read user input into variables
- int start = Integer.parseInt(startField.getText());
- int stop = Integer.parseInt(stopField.getText());
- int step = Integer.parseInt(stepField.getText());
- for (int i=0; i<16; i++)
- {
- boardDisplay[i].setBackground(Color.magenta);
- if(e.getActionCommand().equals("Clear"))
- boardDisplay[i].setBackground(Color.white);
- }
- for (int i=start; i<=stop; i+=step)
- {
- boardDisplay[i].setBackground(Color.yellow);
- if(e.getActionCommand().equals("Clear"))
- boardDisplay[i].setBackground(Color.white);
- }
- boolean condition=true;
- while (condition)
- {
- try
- {
- if (start < 0 | start > 16) throw new NumberFormatException();
- else condition = false;
- }
- catch (NumberFormatException g)
- {
- System.out.println("Only enter 0 to 15 in number format.");
- }
- }
- }
- public static void main(String[] args)
- {
- Checkerboard f = new Checkerboard();
- f.setBounds(50,100,300,400);
- f.setTitle("Checkerboard Array");
- f.setVisible(true);
- } //end of main
- }