Drawing Some Graphics

The central method in Painter is the paint method. This is where all the drawing operations take place—drawing lines, ellipses, rectangles, text, with a wide variety of effects. To make those effects happen, Painter uses Java 2D—that is, Graphics2D objects, not the Graphics objects used in the previous chapters.

To let the user expand and reduce figures interactively while dragging the mouse, Painter uses two different Graphics2D objects—one corresponding to the internal image where the final figure is stored when the user is done drawing, and one corresponding to the window while the user is dragging the mouse. To make the drawing operations easier, the current graphics context is stored in a variable named gImage, and ...

Get Java™ After Hours: 10 Projects You'll Never Do at Work now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.