Illegal start of expression?

Page 1 of 1

0 Replies - 230 Views - Last Post: 15 February 2013 - 01:00 AM Rate Topic: -----

#1 mchen123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 15-February 13

Illegal start of expression?

Posted 15 February 2013 - 01:00 AM

Hi everyone,
I am currently working on a Connect 4 project and was able to compile the basic program. However, once I tried to get it to be able to restart when the user presses the key 's', my updated program receives the error "Illegal start of expression" when I try to compile it. Does anyone know what's causing this/how do i prevent this?
My program so far is:


import java.awt.*;
import java.util.*;
public class Connect4 extends JComponentWithEvents{
private Color[][] checkers;
private boolean isRedTurn;
private boolean isOver;
public void keyPressed(char key){
if(key == 's'){
char relaunch = 3;
while (relaunch == 3) {
{

public void start(){
checkers = new Color[6][7];
for(int r = 0; r < checkers.length; r++){
for(int c = 0; c < checkers[r].length; c++){
checkers[r][c] = Color.white;
}
}
isRedTurn = true;
isOver = false;
}
public void paint(Graphics2D page){
int colWidth = getWidth() / 7;
int rowHeight = getHeight() / 6;

page.setColor(Color.blue);
page.fillRect(0, 0, getWidth(), getHeight());
for(int r = 0; r < checkers.length; r++){
for(int c = 0; c < checkers[r].length; c++){
page.setColor(checkers[r][c]);
page.fillOval(colWidth * c + 5, rowHeight * r + 5, colWidth - 10, rowHeight - 10);
}
}
}


public void mousePressed(int x, int y){
int col = 7 * x / getWidth();
int newRow = -1;
if(isRedTurn){
for(int r = checkers.length - 1; r >= 0; r--){
if(checkers[r][col].equals(Color.white)){
checkers[r][col] = Color.red;
newRow = r;
break;
}
}
}
else{
for(int r = checkers.length - 1; r >= 0; r--){
if(checkers[r][col].equals(Color.white)){
checkers[r][col] = Color.black;
newRow = r;
break;
}
}
}
if(newRow != -1){
isRedTurn = !isRedTurn;
checkWin(newRow, col);
}
}
// row index, col index
public void checkWin(int row, int col)
{
//just added a checker at row, col
//what color was it?
int countMatches=0;
//counting the number of matching checkers below the new checker
for (int i= row + 1; i < 6; i++){//starting on the row below
if (checkers[i][col]==checkers[row][col]){
countMatches++;
}
else{
break;
}
}
if (countMatches >= 3){
System.out.println("Congratulations, you are the winner");
}

countMatches = 0;
//count right
for (int i=col + 1; i < 7; i++){
if (checkers[row][i]==checkers[row][col]){
countMatches++;
}
else{
break;
}
}
//count left
for (int i=col-1; i>=0; i--){
if (checkers[row][i]==checkers[row][col]){
countMatches++;
}
else{
break;
}
}
if (countMatches >= 3){
System.out.println("Congratulations, you are the winner");
}

countMatches = 0;
//counting down-right
for (int i=1; row + i < 6 && col + i < 7; i++){
if (checkers[row + i][col + i]==checkers[row][col]){
countMatches++;
}
else{
break;
}
}
//counting up-left
for (int i=1; row - i >= 0 && col - i >= 0; i++){
if (checkers[row - i][col - i]==checkers[row][col]){
countMatches++;
}
else{
break;
}
}
if (countMatches >= 3){
System.out.println("Congratulations, you are the winner");
}

countMatches = 0;
//up-right
for (int i=1; row - i >= 0 && col + i < 7; i++){
if (checkers[row - i][col + i]==checkers[row][col]){
countMatches++;
}
else{
break;
}
}
//down-left
for (int i=1; row + i < 6 && col - i >= 0; i++){
if (checkers[row + i][col - i]==checkers[row][col]){
countMatches++;
}
else{
break;
}
}
if (countMatches >= 3){
System.out.println("Congratulations, you are the winner");
}
public static void main(String[] args)
{
launch(700, 600);
}
}

}
}

}

}
}



Is This A Good Question/Topic? 0
  • +

Page 1 of 1