错误:令牌上的语法错误“(”,;;预期

时间:2013-10-24 03:34:28

标签: java

我在同一行有两个问题,第一个是

Error: Syntax error on token "(", ; expected
Error: Syntax error on token ")", ; expected

我不知道为什么它告诉我错误,noob模式现在正在踢,所以我无法弄明白。

import java.awt.*;//for graphics class
import java .util.*;// for scanner class
//start of class
public class bouncingball {
     // public static final int CENTER = 300;


      //start of main
      public static void main(String[] args) {

       System.out.println("Project 2 modified by Jordan Spicer");

        DrawingPanel panel = new DrawingPanel(400, 400);

        Graphics g = panel.getGraphics();

        Scanner input = new Scanner(System.in);
        ball(g);
        int test = 0;
        String colors = "";
        System.out.println(" this program prints out a bouncing ball");


       System.out.println("please pick a color for the ball either red or blue ");

        colors = input.nextLine();

        if( (colors.compareTo("blue") == 0) ||colors.compareTo("red") == 0){

        System.out.println("that wasnt a good color try again only put red or blue");

          colors = input.nextLine();
          System.out.println(colors);

        }       
        else{
          System.out.println(colors);


        }

        public static void ball (Graphics g){ <======= the errors are at this line here
          g.setcolor(Color.RED);
       g.drawcircle(50,50,50,50);



        }


    }
}

2 个答案:

答案 0 :(得分:4)

看来你的方法在另一个方法中。把它移到外面。将以下方法声明移至外部。

public static void ball (Graphics g){....}

答案 1 :(得分:0)

现在有点生锈的java,但我不认为你可以有方法

public static void ball (Graphics g)

主要方法内部。尝试在main方法之前声明它?