/*ch0705.java*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class ch0705 extends JApplet
{ int x1,y1,x2,y2;
  public void init()
  { addMouseListener(new M1());          //参数定义为M1的对象
    addMouseMotionListener(new M2());    //参数定义为M2类的对象
  }
  public void paint(Graphics g)
  { g.drawLine(x1,y1,x2,y2);
  }
  class M1 extends MouseAdapter          //创建MouseAdapter的子类M1
  { public void mousePressed(MouseEvent e)
    { x1=e.getX();
      y1=e.getY();
    }
  }
  class M2 extends MouseMotionAdapter    //创建MouseMotionAdapter的子类M2
  { public void mouseDragged(MouseEvent e)
    { x2=e.getX();
      y2=e.getY();    
      repaint();
    }
  }
}


