To create a drawing pad using applet we have to import java.awt.*; java.awt.event.*; java.applet.*; packages. Now implements MouseMotionListener, MouseListener interfaces and overrides the methods mouseMoved(), mouseDragged(), mouseClicked(), mousePressed(), mouseReleased(), mouseEntered(), mouseExited(). Now draw line from the old mouse position to current mouse position. this code written in mouseDragged() method.
import java.awt.*; import java.awt.event.*; import java.applet.*; public class A extends Applet implements MouseMotionListener,MouseListener{ float X,Y,X1,Y1; public void init(){ addMouseListener(this); addMouseMotionListener(this); } public void mouseMoved(MouseEvent e){} public void mouseDragged(MouseEvent e){ Graphics g=getGraphics(); X1=e.getX(); Y1=e.getY(); g.setColor(Color.red); g.drawLine((int)X,(int)Y,(int)X1,(int)Y1); X=X1; Y=Y1; } public void mouseClicked(MouseEvent e){} public void mousePressed(MouseEvent e){ X=e.getX(); Y=e.getY(); } public void mouseReleased(MouseEvent e){} public void mouseEntered(MouseEvent e){} public void mouseExited(MouseEvent e){} }