June 2005
Beginner to intermediate
336 pages
6h 29m
English
If the line flag is true, the user is drawing lines. To draw lines, Painter uses the Line2D.Double class. Because Line2D.Double is one of those rare Graphics2D objects that doesn't need to be passed only the upper-left point at which to begin drawing, you can draw the line simply by using the start and end points:
if(line){
Line2D.Double drawLine = new Line2D.Double(start.x,
start.y, end.x, end.y);
.
.
.
There's a graphics effect you have to take care of here as well: If the user has selected the Drop shadow graphics effect, you also have to draw the shadow. Shadows should not completely obscure what's underneath them; they should only be slightly darker. You can draw lines that work excellently as shadows using the Java2D Composite ...
Read now
Unlock full access