MouseMotionListener:
public class DrawListener extends MouseAdapter implements ActionListener
Graphics2D g2d;
public void setG(Graphics g){
this.g=g;
//强制转换
g2d=(Graphics2D)g;............Graphics 是父本
}
public void mouseDragged(MouseEvent e){
if("铅笔".equals(action)){
x2=e.getX();
y2=e.getY();
g.setColor(curcolor);
g.drawline(x1,y1,x2,y2);
x1=x2;
y1=y2;
}
if("橡皮".equals(action)){
x2=e.getX();
y2=e.getY();
g.setColor(Color.white);
g2d.setStroke(new BasicStroke(15));............设置橡皮宽度
g.drawLine(x1, y1, x2, y2);
x1=x2;
y1=y2;
g.setColor(curcolor);...........颜色变成设置的颜色
g2d.setStroke(new BasicStroke());.................如果不用橡皮了,宽度变成默认宽度
}
}
public void mouseMoved(MouseEvent e);