大家来帮我看看这个画图板一部分

我在做一个画图板,界面已经做好了,两个Panel面板,一个在用户界面中,另一个用于画板,只是对于鼠标画画这一个功能实现不了,就是在鼠标事件上糊涂,大家帮我看看鼠标事件那块,zhixian那部分就行,给我说说该怎么写。这是我绘画部分的代码

class myDemo extends 绘制图形{

Panel p1=new Panel();

private String brush = "free";

Color selectColor=Color.black;

Canvas drawArea=new Canvas();

private void myEvent(){

zhixian2.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e) {

if(zhixian2==e.getSource()){

brush="line";

}

}

});

zhixian2.addMouseListener(new MouseAdapter(){

 public void mousePressed(MouseEvent e){

 x=e.getX();

 y=e.getY();

 

 }

});

zhixian2.addMouseListener(new MouseAdapter(){

 public void  mouseReleased(MouseEvent e){

 int x1=e.getX();

 int y1=e.getY();

 Graphics2D g=(Graphics2D) zhixian2.getGraphics();

 g.drawLine(x,y,x1,y1);

 

 }

});

kongtuo2.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e) {

if(kongtuo2==e.getSource()){

brush = "circ";

}

}

});

kongtuo2.addMouseListener(new MouseAdapter(){

 public void mousePressed(MouseEvent e){

 x=e.getX();

 y=e.getY();

 

 }

});

}


}



北岛矢夏3392593
浏览 1243回答 0
0回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java