Checkerboard compile error

Posted on 2004-11-06
Last Modified: 2010-03-31
Hi, I'm making a checkerboard but I'm getting a few compiler errors and I'm not sure what the exact problem is.
It's saying that I have "illegal start of expression" at the line below Case 2: and that it's "expecting ')'" at line 38 which is "box[i][j] = new CBox(x+100, y, w, h,; "

Code for the class is:

//       Author: Romeo Theriault
//  Demonstrates the use of graphical objects.

import javax.swing.*;
import java.awt.*;
import java.util.Random;

public class CBPanel extends JPanel
   private CBox[][] box = new CBox[8][8];
      final int w = 100, h = 100;
      int x = -100, y = 0;
      int count = 1;
   //  Constructor: Creates five Circle objects.
   public CBPanel()
              for (int i = 0; i < 8; i++){
                  for (int j = 0; j < 8; j++){
                  switch (count)
                     case 1:
                       if (j % 2 == 0 && i % 2 == 0)
                                box[i][j] = new CBox(x+100, y, w, h,;
                              box[i][j] = new CBox(x+100, y, w, h,;

                     case 2:
                       if (j % 2 == 0 && i % 2 !== 0)
                                box[i][j] = new CBox(x+100, y, w, h,;
                              box[i][j] = new CBox(x+100, y, w, h,;
                              break; ;
            if (count == 2)
                        count = 1;
                        count = 2;
            x = -100;
            y = y + 100;
            setPreferredSize (new Dimension(800, 800));

   //  Draws this panel by requesting that each circle draw itself.
   public void paintComponent (Graphics page)
            for (int a=0; a < 8; a++){
                  for (int b=0; b < 8; b++)

Question by:romeotheriault
    LVL 92

    Expert Comment

    >                    if (j % 2 == 0 && i % 2 !== 0)

    should be:

                       if (j % 2 == 0 && i % 2 != 0)

    Author Comment

    Thanks objects, That worked, now that it compiles it only shows the left column? I'm not sure what I've coded wrong.
    LVL 92

    Accepted Solution

    all your boxes have the same xcoord (x=0)
    you need to increment x, by 100 inside you j loop

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
    Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
    Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
    Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now