<identifier>期望的java错误</identifier>

时间:2014-03-27 18:25:36

标签: java html sql bluej

我一直得到一个&#34;标识符预期错误&#34;同时在blueJ上塑造人形。到目前为止,这是主类的代码:

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

    }
}

每次编译测试时都会继续发生此错误。到目前为止,我还没有完成它。

2 个答案:

答案 0 :(得分: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 :(得分: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