2014-03-27 84 views
-1

我在blueJ上製作人形時,不斷收到「標識符預期錯誤」。到目前爲止,這裏是主類代碼:<identifier>預計的Java錯誤

import java.awrt.*; 
import java.awt.event.*; 
import java.awt.geom.*; 
/** 
* Write a description of class Main here 
* 
* @author Ibrahim Hmood 
* @version 03.27.2014 
*/ 
public class main 
{ 
     public static void main (String[] args); 
     Frame frame = newCricleDraw(); 
     frame.addWindowListener(new WindowAdapter() 
     {public void windowClosing (WindowEvent we) 
      { 
       system.exit(0); 
      } 
      } 
     };//end of listener 
     frame.setSize(600,600) 
     frame.setVisible(true); 
    } 
} 

,並在這裏爲CircleDraw類的代碼:

import java.awt.*; 
import java.awt.event.*; 
import java.awt.geom.*; 

public class CircleDraw extends Frame 
{ 
    Shape squarehead = new; 
    Ellipse2D.Float(200.0F, 40.0f, 100.0f, 100.0f); 

    Shape squareLeftArm = new; 
    Rectangle2D.Double(165, 230,30, 50); 

    Shape circleCenter = new; 
    Circle2D.Double(165, 230, 30, 50); 

    Shape squareNeck = new 
    Square2D.Double(165, 230, 30,50); 
    { 
     //draw head 
     Graphics2D ga = (Graphics2D)g; 
     ga.draw(squareHead); 
     ga.setPaint(color.Blue); 
     ga.fill(squareHead); 

     //draw arms 
     ga.setPaint(Color.black); 
     ga.draw(squareLeftArm); 
     ga.fill(squareLeftArm); 

     //draw center 
     ga.setPaint(color.NavyBlue); 
     ga.Draw(circleCenter); 
     ga.fill(circleCenter); 

     //draw neck 

    } 
} 

這個錯誤繼續發生,每次我編譯它做檢查。到目前爲止,我還沒有完成它。

+0

@SotiriosDelimanolis這是沒有幫助的。這顯然是一個新的Java程序員。 – mttdbrd

+1

@mttdbrd不要給我那個。我已經指出了其中一個錯誤。還有很多其他的印刷錯誤。 OP需要在學習如何編程之前學習如何輸入。這個問題不會對別人有所幫助。 –

+0

@SotiriosDelimanolis人們來這裏尋求他們的編程幫助。您的評論不具有建設性或有幫助。 – mttdbrd

回答

2

方法,包括main,必須將它們的編碼用大括號括起來。所以:

public static void main (String[] args); 

應該

public static void main (String[] args) { 

此外,大括號{ }和括號()必須平衡或者其他的。編寫一個用作監聽器的「匿名類」時,這可能會非常棘手。

Frame frame = newCricleDraw(); 
    frame.addWindowListener(new WindowAdapter() 
    {public void windowClosing (WindowEvent we) 
     { 
      system.exit(0); 
     } // This closes the { two lines above 
     } // This closes the { just before "public" 

在這一點上,你有一個開放(,只是字new之前,所以你不能用}關閉它。 (使用右括號)更改

};//end of listener 

這樣:

); // end of listener  

然後,你需要在此之後一個分號:

frame.setSize(600,600); 
1

你使用像Eclipse的IDE?好像有錯誤一堆,應該由編譯器/ IDE

public class CircleDraw extends Frame 
{ 
    Shape squareHead = new 
    Ellipse2D.Float(200.0F, 40.0f, 100.0f, 100.0f); 

    Shape squareLeftArm = new 
    Rectangle2D.Double(165, 230,30, 50); 

    Shape circleCenter = new 
      Ellipse2D.Double(165, 230, 30, 50); 

    Shape squareNeck = new 
    Rectangle2D.Double(165, 230, 30,50); 

    public void paint(Graphics g) 
    { 

     //draw head 
     Graphics2D ga = (Graphics2D)g; 
     ga.draw(squareHead); 
     ga.setPaint(Color.BLUE); 
     ga.fill(squareHead); 

     //draw arms 
     ga.setPaint(Color.black); 
     ga.draw(squareLeftArm); 
     ga.fill(squareLeftArm); 

     //draw center 
     ga.setPaint(Color.CYAN); 
     ga.draw(circleCenter); 
     ga.fill(circleCenter); 

     //draw neck 

    } 
} 

然後主類現在

public static void main(String[] args) 
{ 

    Frame frame = new CircleDraw(); 
     frame.addWindowListener(new WindowAdapter() 
    { 
     public void windowClosing (WindowEvent we) 
     { 
      System.exit(0); 
     } 
    });//end of listener 
    frame.setSize(600,600); 
    frame.setVisible(true); 
} 

它的運行被抓住,你有一些工作要做得到形狀和位置的權利...

enter image description here

+0

我用過那個,然後在主窗口中,我得到一個錯誤,說「解析時到達文件末尾」,並突出顯示了最後一個括號。 –

+0

我給你的主要方法,而不是全班。你將你的類定義爲'public class main {'除了類*應該以大寫字母開頭並且更具描述性之外應該改變這個事實。也許公開課HumanTest。 – Dan