我在做一个画图板,界面已经做好了,两个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(); } });} }
添加回答
举报
0/150
提交
取消