February 2014
Beginner
1248 pages
62h 25m
English
The Painter application of Figs. 12.34–12.35 demonstrates a customized subclass of JPanel that’s used to create a dedicated drawing area. The application uses the mouseDragged event handler to create a simple drawing application. The user can draw pictures by dragging the mouse on the JPanel. This example does not use method mouseMoved, so our event-listener class (the anonymous inner class at lines 20–29 of Fig. 12.34) extends MouseMotionAdapter. Since this class already declares both mouseMoved and mouseDragged, we can simply override mouseDragged to provide the event handling this application requires.
Read now
Unlock full access