Start Search Contents Index Links About

Drawing tool

Mouse events

2002 - Week 25 - Havard Rast Blok

It has been a long time since last exercises. To fresh up a bit, we will make a small drawing tool this week.

First, create a JFrame that reports the mouse events by System.out.println statements. These events include clicking, moving, dragging, etc.

Hint: javax.swing.event.MouseInputListener (since JDK 1.4)


MouseAction.java

Now extend your JFrame to respond to mouse clicking and dragging by drawing a trail where the cursor is dragged. The result should be a very simple drawing program.


Paint.java

Could you imagine some way to save and load your drawings? There are several different ways this could be implemented: Saving and Image object, image file (GIF, JPEG, etc.) or saving the coordinates of the marked pictures, to mention some.



site: Håvard Rast Blok
mail:
updated: 27 July 2007