[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 193
  • Last Modified:

Checkerboard compile error

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, Color.black); "

Code for the class is:

//********************************************************************
//  CBPanel.java       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, Color.black);
                          else
                              box[i][j] = new CBox(x+100, y, w, h, Color.red);
                              
                              break;

                     case 2:
                       if (j % 2 == 0 && i % 2 !== 0)
                                box[i][j] = new CBox(x+100, y, w, h, Color.red);
                          else
                              box[i][j] = new CBox(x+100, y, w, h, Color.black);
                              
                              break; ;
                  }      
                  
                  }            
            if (count == 2)
                        count = 1;
                  else
                        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)
   {
      super.paintComponent(page);
            
            for (int a=0; a < 8; a++){
                  for (int b=0; b < 8; b++)
                        box[a][b].paint(page);
                  }
            
            
            

     
   }
}
0
romeotheriault
Asked:
romeotheriault
  • 2
1 Solution
 
objectsCommented:
>                    if (j % 2 == 0 && i % 2 !== 0)

should be:

                   if (j % 2 == 0 && i % 2 != 0)
0
 
romeotheriaultAuthor Commented:
Thanks objects, That worked, now that it compiles it only shows the left column? I'm not sure what I've coded wrong.
0
 
objectsCommented:
all your boxes have the same xcoord (x=0)
you need to increment x, by 100 inside you j loop
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now