Click here to Skip to main content
15,908,115 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I've double, triple checked my opening and closing braces.

Each time I try to compile my code the following error pops up:
C:\Java 1\New folder (3)\Chapter05\Checkboard.java:82: ')' expected
}
^

What I have tried:

import java.awt.*;
import java.awt.event.*;
import javax.swing.JOptionPane;

public class Checkerboard extends Frame implements ActionListener
{
    Panel boardPanel = new Panel();
    TextField textArray[] = new TextField[16];

    Panel inputPanel = new Panel();
    Label startLabel = new Label("Start");
    Field startField = new TextField(2);
    Label stopLabel = new Label("Stop");
    Field stopField = new TextField(2);
    Label stepLabel = new Label("Step");
    Field stepField = new TextField(2);

    Panel buttonPanel = new Panel();
    Button goButton = new Button("Go");
    Button clearButton = new Button("Clear");

    int start = 0;
    int stop = 0;
    int step = 0;

    public Checkerboard()
    {
		for(int i=0; i<textArray.lenth; i++)
        {
            textArray[i] = new TextField();
            textArray[i].setEditable(false);
            textArray[i].setText(String.valueOf(i));
            textarray[i].setBackground(Color.white);
        }

        this.setLayout(new BorderLayout(2,2));
        boardPanel.setLayout(new GridLayout(4,4,20,20));
        inputPanel.setLayout(new GridLayout(2,3,20,20));
        buttonPanel.setLayout(new GridLayout(1,2,5,5));

    	for(int j=0; j<textArray.length; j++)
    	boardPanel.add(textArray[j]);

    	inputPanel.add(startField);
    	inputPanel.add(stopField);
    	inputPanel.add(stepField);
    	inputPanel.add(startLabel);
    	inputPanel.add(stopLabel);
    	inputPanel.add(steplabel);

    	buttonPanel.add(goButton);
    	buttonPanel.add(clearButton);

    	add(inputPanel, BorderLayout.CENTER);
    	add(inputPanel, BorderLayout.NORTH);
    	add(inputPanel, BorderLayout.SOUTH);

    	startField.addActionListener(this);
    	stopField.addActionListener(this);
    	stepField.addActionListener(this);
    	goButton.addActionListener(this);
    	clearButton.addActionListener(this);

    	setVisible(true);
    	startField.requestFocus();

    	addWindowListener(new WindowAdapter()
    	{
			public void windowClosing(WindowEvent e)
        	{
            	System.ext(0);
        	}
    	}
     } //LOCATION OF THE ERROR.
	 public void actionPerformed(ActionEvent e)
	 {
    	 string arg = e.getActionCommand();
    	 try
    	 {
			 if(args == "Go")
        	 {
    			 int start = Integer.parseInt(startField.getText());
    			 int step = Integer.parseInt(stepField.getText());
    			 int stop = Integer.parseInt(stopField.getText());

    			 for(int i=0; i<textArray.length; i++)

    			 textArray[i].setBackgorund(Color.blue);

    			 for(int i = start; i<textArray.length; i+=step)

    			 textArray[i].setBackground(Color.yellow);
    		 }
		 }
		 catch(Exception x)
		 {
			 JOptionPane.showMessageDialog(null,"Date Entry Error", "Error", JOptionPane.INFORMATION_MESSAGE);
        	 args = "Clear";
    	 }

    	 if(args == "Clear")
    	 {
			 startField.setText("");
        	 stopField.setText("");
        	 stepField.settext("");

        	 for(int i=0; i<textArray.length; i++)
             textArray[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);
	 }
}
Posted
Updated 28-Aug-18 8:28am

You're missing a closing parenthesis and semicolon.
addWindowListener(new WindowAdapter()
    	{
			public void windowClosing(WindowEvent e)
        	{
            	System.ext(0);
        	}
    	});
 
Share this answer
 
Comments
Member 13652359 28-Aug-18 14:47pm    
After correcting it, it shows:

C:\Java 1\New folder (3)\Chapter05\Checkboard.java:76: ';' expected
{
^
addWindowListener(new WindowAdapter())
{//LOCATION OF ERROR
public void windowClosing(WindowEvent e)
{
System.ext(0);
}
});
Bryian Tan 28-Aug-18 15:18pm    
this line
addWindowListener(new WindowAdapter())
should be
addWindowListener(new WindowAdapter()
. There is an extra ")" parantheses
Dave Kreskowiak 28-Aug-18 16:03pm    
I shows you exactly where to fix the problem and you went and did something different.

...sigh...
Member 13652359 28-Aug-18 16:18pm    
My bad Dave.
After doing what you said I received several errors after compiling:

C:\Java 1\New folder (3)\Chapter05\Checkboard.java:12: class Checkerboard is public, should be declared in a file named Checkerboard.java
public class Checkerboard extends Frame implements ActionListener
^
C:\Java 1\New folder (3)\Chapter05\Checkboard.java:19: cannot find symbol
symbol : class Field
location: class Checkerboard
Field startField = new TextField(2);
^
C:\Java 1\New folder (3)\Chapter05\Checkboard.java:21: cannot find symbol
symbol : class Field
location: class Checkerboard
Field stopField = new TextField(2);
^
C:\Java 1\New folder (3)\Chapter05\Checkboard.java:23: cannot find symbol
symbol : class Field
location: class Checkerboard
Field stepField = new TextField(2);
^
C:\Java 1\New folder (3)\Chapter05\Checkboard.java:35: cannot find symbol
symbol : variable lenth
location: class java.awt.TextField[]
for(int i=0; i<textArray.lenth; i++)
^
C:\Java 1\New folder (3)\Chapter05\Checkboard.java:40: cannot find symbol
symbol : variable textarray
location: class Checkerboard
textarray[i].setBackground(Color.white);
^
C:\Java 1\New folder (3)\Chapter05\Checkboard.java:57: cannot find symbol
symbol : variable steplabel
location: class Checkerboard
inputPanel.add(steplabel);
^
C:\Java 1\New folder (3)\Chapter05\Checkboard.java:79: cannot find symbol
symbol : method ext(int)
location: class java.lang.System
System.ext(0);
^
C:\Java 1\New folder (3)\Chapter05\Checkboard.java:85: cannot find symbol
symbol : class string
location: class Checkerboard
string arg = e.getActionCommand();
^
C:\Java 1\New folder (3)\Chapter05\Checkboard.java:88: cannot find symbol
symbol : variable args
location: class Checkerboard
if(args == "Go")
^
C:\Java 1\New folder (3)\Chapter05\Checkboard.java:96: cannot find symbol
symbol : method setBackgorund(java.awt.Color)
location: class java.awt.TextField
textArray[i].setBackgorund(Color.blue);
^
C:\Java 1\New folder (3)\Chapter05\Checkboard.java:106: cannot find symbol
symbol : variable args
location: class Checkerboard
args = "Clear";
^
C:\Java 1\New folder (3)\Chapter05\Checkboard.java:109: cannot find symbol
symbol : variable args
location: class Checkerboard
if(args == "Clear")
^
13 errors

Tool completed with exit code 1
Dave Kreskowiak 28-Aug-18 16:39pm    
Read the very first error message. It's telling you EXACTLY what's going wrong.

You're declaring a class called "Checkerboard" in a file called "Checkboard.java".

It's telling you exactly what needs to be done.
This line may be culprit
Java
addWindowListener(new WindowAdapter()

it opens 2 '(' and close only 1 ')'
One can guess the compiler beg for the missing one.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900