画图工具 但线条出不来

代码如下:
package example;
import java.awt.*;
public class DoodleMenuTest extends Frame{
private Doodle doodle;
public static void main(String args[]){
new DoodleMenuTest("Super Deluxe Paintbox");
}
DoodleMenuTest(String windowTitle){
super(windowTitle);
doodle=new Doodle();
setLayout(new FlowLayout());
add(doodle);
add(new Button("Clear"));
setMenuBar(new DoodleMenuBar());
resize(300,200);
show();
}
public boolean action(Event event,Object label){
if(event.target instanceof MenuItem){
if(((String)label).equals("Pen")){
doodle.setDrawingMode(Doodle.DRAW);
}else
if(((String)label).equals("Eraser")){
doodle.setDrawingMode(Doodle.ERASE);
}else
if(((String)label).equals("Freehand")){
doodle.setDrawingStyle(Doodle.FREEHAND);
}else
if(((String)label).equals("Single Dots")){
doodle.setDrawingStyle(Doodle.SINGLEDOT);
}else
if(((String)label).equals("Quit")){
dispose();
System.exit(0);

        }else if(event.target instanceof Button){
            doodle.repaint();
        }else{
            System.out.println("Totally unexpected Event type:"+event);
        }

    }
    return true;
}

class Doodle extends Canvas{
static final int FREEHAND =0;
static final int SINGLEDOT=1;
static final int DRAW=0;
static final int ERASE=1;
private int x=0;
private int y=0;
private int drawingStyle=FREEHAND;
private int drawingMode=DRAW;
private Color drawColor=Color.black;
void setDrawingStyle(int drawStyle){
drawingStyle=drawStyle;

}
void setDrawingMode(int drawMode){
    Graphics g=getGraphics();
    drawingMode=drawMode;
    drawColor=(drawingMode==DRAW)?Color.black:getBackground();
    setForeground(drawColor);
}
public Dimension preferredSize(){
    return new Dimension(120,100);
}
public void paint(Graphics g){
    g.setColor(Color.black);
    g.drawRect(0, 0, this.size().width-1, this.size().height-1);

}
public boolean mouseDown(Event e,int x,int y){
    this.x=x;
    this.y=y;
    if(drawingStyle==SINGLEDOT){
        getGraphics().drawRect(x, y, 1, 1);
    }
    return true;
}
public boolean mouseDray(Event e,int x,int y){
    if(drawingStyle==SINGLEDOT){
        getGraphics().drawRect(x, y, 1, 1);

    }else
    if (drawingStyle==FREEHAND){
        getGraphics().drawLine(this.x, this.y, x, y);

    }
    this.x=x;
    this.y=y;
    return true;
}

}
class DoodleMenuBar extends MenuBar{
DoodleMenuBar(){
add(new ToolsMenu());
add(new StylesMenu());
}
}
class ToolsMenu extends Menu{
ToolsMenu(){
super("Tools");
add("Pen");
add("Eraser");
addSeparator();
add("Quit");
}
}
class StylesMenu extends Menu{
StylesMenu(){
super("Styles");
add("Freehand");
add("Single Dots");
}
}
}

Pen模式下的Freehand怎么也画不出线条,但SingleDot是有用的。
求解!!!

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问