Chapter 2
Drawing Shapes
In This Chapter
Creating basic shapes such as lines, rectangles, and ellipses
Setting the fill color and stroke thickness
Creating shapes you can see through
Creating gradient fills
Rotating shapes
Drawing text onscreen
Were you one of those kids who, way back in school, passed away the boring hours of algebra class by doodling in the margins of the book? If so, you're in luck. Now that you're a grownup and you're mastering Java programming, you don't have to doodle in the book. Instead, you can write programs that doodle onscreen.
This chapter is a gentle introduction to the fascinating world of drawing in Java. The designers of Java call this feature Java 2D. With Java 2D, you can draw basic shapes: lines, arcs, rectangles, ellipses, and so on. You can set the style used to draw the shape's outline, and you can fill the shape with a solid color, a gradient ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access