2013-10-24 139 views
-2

我必须在同一行的前两个问题是错误:令牌“(”语法错误;预计

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

我不知道为什么它告诉我说错误,小白模式是踢所以我现在不能弄明白。

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



     } 


    } 
} 
+1

如果你至少** indent **你的代码,你可能发现了错误并保存了一个问题。 –

+2

1)你的代码格式很糟糕,真的很糟糕,很难让其他人阅读你的代码。在向志愿者寻求帮助时,我们非常感谢您付出一点努力让您的代码具有可读性和可读性。 2)你正在做错误的Swing绘图,因为你不应该通过在组件上调用'getGraphics()'来获得你的Graphics对象。以这种方式获得的物体寿命很短,因此您的绘图可能会消失。相反,阅读Swing绘画教程,看看正确的绘画方式。 –

回答

4

看来你里面的另一种方法的方法。它向外侧移动,移动下面的方法declarationt到外部。

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

甜蜜的耶稣谢谢 – user2172510

+0

@ user2172510:祝你好运! – kosa

0

有点生疏用java的权利,但我不认为你可以有方法

public static void ball (Graphics g) 

的主要方法里面。尝试在主要方法之前声明它?

相关问题