Let's review a bit of what we did last time. Create a file One.java /* */ import java.applet.*; import java.awt.*; public class One extends Applet { public void paint(Graphics g) { g.drawOval(50, 50, 100, 75); } } Set your PATH and then compile this file with javac. Next you can run appletviewer One.java Now the applet shows up and it prints an ellipse. So we modify to pay attention to the mouse movement: /* */ import java.applet.*; import java.awt.*; import java.awt.event.*; public class One extends Applet implements MouseMotionListener { public void init() { this.addMouseMotionListener(this); } public void mouseMoved(MouseEvent e) { System.out.println("mouse being moved (" + e.getX() + ", " + e.getY() + ")"); } public void mouseDragged(MouseEvent e) { System.out.println("mouse being dragged (" + e.getX() + ", " + e.getY() + ")"); } public void paint(Graphics g) { g.drawOval(50, 50, 100, 75); } } Let's make the applet draw: /* */ import java.applet.*; import java.awt.*; import java.awt.event.*; public class One extends Applet implements MouseMotionListener { public void init() { this.addMouseMotionListener(this); } public void mouseMoved(MouseEvent e) { System.out.println("mouse being moved (" + e.getX() + ", " + e.getY() + ")"); } public void mouseDragged(MouseEvent e) { System.out.println("mouse being dragged (" + e.getX() + ", " + e.getY() + ")"); Graphics g = this.getGraphics(); g.drawOval(e.getX(), e.getY(), 5, 5); } public void paint(Graphics g) { } } So this is the last change to this applet: /* */ import java.applet.*; import java.awt.*; import java.awt.event.*; class Point { int x, y; Point(int x, int y) { this.x = x; this.y = y; } int getX() { return this.x; } int getY() { return this.y; } } public class One extends Applet implements MouseMotionListener { Point old; public void init() { this.addMouseMotionListener(this); this.old = new Point(0, 0); } public void mouseMoved(MouseEvent e) { System.out.println("mouse being moved (" + e.getX() + ", " + e.getY() + ")"); } public void mouseDragged(MouseEvent e) { System.out.println("mouse being dragged (" + e.getX() + ", " + e.getY() + ")"); Graphics g = this.getGraphics(); g.drawLine(e.getX(), e.getY(), this.old.getX(), this.old.getY()); this.old = new Point(e.getX(), e.getY()); g.drawOval(e.getX(), e.getY(), 5, 5); } public void paint(Graphics g) { } } Major drawback with this program: the picture you draw is not permanent. That's what you get if you don't draw in paint! So the idea is to add points from mouseDragged and call repaint(). Meanwhile paint should be painting the collection of points. Let's now go back to the basic applet template: /* */ import java.applet.*; import java.awt.*; public class One extends Applet { public void init() { } public void paint(Graphics g) { } } Let's make this applet know about a collection of Circles and show them: /* */ import java.applet.*; import java.awt.*; class Circle { int x, y, radius; Color c; Circle(int x, int y, int r, Color c) { this.x = x; this.y = y; this.radius = r; this.c = c; } void draw(Graphics g) { g.setColor(c); g.fillOval(x, y, radius * 2, radius * 2); g.setColor(Color.BLACK); g.drawOval(x, y, radius * 2, radius * 2); } } public class One extends Applet { Circle[] circles; public void init() { this.circles = new Circle[100]; for (int i = 0; i < this.circles.length; i++) { this.circles[i] = new Circle( (int) ((Math.random() * 300) + 50), (int) ((Math.random() * 300) + 50), (int) ((Math.random() * 10) + 30), new Color( (float) Math.random(), (float) Math.random(), (float) Math.random())); } } public void paint(Graphics g) { for (int i = 0; i < this.circles.length; i++) this.circles[i].draw(g); } } Run this program. Restart the applet a couple of times. Change 100 to 10, 50, 200.