-2

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

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);



        }


    }
}
4

2 回答 2

4

看来您在另一种方法中使用方法。把它移到外面。将以下方法声明移到外部。

public static void ball (Graphics g){....}
于 2013-10-24T03:35:48.037 回答
0

现在对java有点生疏了,但我不认为你可以有这个方法

public static void ball (Graphics g)

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

于 2013-10-24T03:39:34.177 回答