“此行处的多个标记”在构造函数中出错

时间:2015-08-28 01:11:25

标签: java

所以我使用gpdraw作为库为我的计算机科学类绘制东西,我正在尝试在Eclipse中运行它,我把主要的方法但我仍然得到错误。

import gpdraw.*;

public class House {

    public static void main(String[] args) {
        private DrawingTool myPencil;
        private SketchPad myPaper;

        public House() {
            myPaper = new SketchPad(500, 500);

            myPencil = new DrawingTool(myPaper);
        }

        public void draw() {
            myPencil.up();
            myPencil.turnRight(90);
            myPencil.forward(20);
            myPencil.turnLeft(90);
            myPencil.forward(20);
            myPencil.turnRight(20);
            myPencil.forward(200);
        }

    }  

}

1 个答案:

答案 0 :(得分:2)

Java不允许嵌套方法和/或构造函数。

你需要这样的东西:

import gpdraw.*;

public class House {

    private DrawingTool myPencil;
    private SketchPad myPaper;

    public House() {
        myPaper = new SketchPad(500, 500);
        myPencil = new DrawingTool(myPaper);
    }

    public void draw() {
        myPencil.up();
        myPencil.turnRight(90);
        myPencil.forward(20);
        myPencil.turnLeft(90);
        myPencil.forward(20);
        myPencil.turnRight(20);
        myPencil.forward(200);
    }

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

    }   
}