The Dots applets are shown below, demonstrating different effects of mouse and key listeners, as well as painting versus updating a canvas.

 


 

Dots.java

instructions:
click anywhere on the black square. click again. and again...

comments:
This version instantiates a MouseListener as a separate class.

source code:

 


 

Dots2.java

instructions:
click anywhere on the black square. click again. and again...

comments:
This version implements a MouseListener as part of the Dots class.

source code:

 


 

Dots3.java

instructions:
click and drag anywhere on the black square. click and drag again. and again...

comments:
This version implements a MouseListener and a MouseMotionListener as part of the Dots class.

source code:

 


 

Dots4.java

instructions:
click in the black squre. then press the arrow keys to move up, down, left or right. or press U/u for up, D/d for down, L/l for left, or R/r for right.

comments:
This version implements a KeyListener as part of the Dots class. The paint() function is called to draw on the canvas.

source code:

 


 

Dots5.java

instructions:
click in the black square. press the arrow keys to move up, down, left or right. or press U/u for up, D/d for down, L/l for left, or R/r for right.

comments:
This version implements a KeyListener as part of the Dots class. The update() function is called to draw on the canvas.

source code: