Skip to Content
Java 2D Graphics
book

Java 2D Graphics

by Jonathan Knudsen
May 1999
Intermediate to advanced
368 pages
9h 6m
English
O'Reilly Media, Inc.
Content preview from Java 2D Graphics

4.3. Overlap

What happens if you both stroke and paint a shape? Interestingly, the results depend on whether you stroke or paint first. A shape's outline actually overlaps its interior, as shown in Figure 4.14. The shape's real outline, strictly speaking, is an infinitesimally thin line, shown black in the figure. The process of stroking creates an outline shape around the real outline. Some of the stroked outline extends outside the shape, and some of the stroked outline overlaps with the shape's interior.

Figure 4.14. The stroked outline and interior of a circle

If you're using opaque colors, then you'll get different results depending on the order in which you do things. If you use partially transparent colors, then you'll be able to observe the overlap of stroked outlines and filled interiors in your results. The following shows how this happens in practice. First, it strokes the outline and fills the interior of a circle using a partially transparent color:

Color smokey = new Color(128, 128, 128, 128);
    g2.setPaint(smokey);
    g2.fill(e);
    g2.draw(e);

Then, in a different location, it strokes the circle's outline using a solid black color and fills the interior using a solid gray:

g2.setPaint(Color.black);
    g2.draw(e);
    g2.setPaint(Color.gray);
    g2.fill(e);

Finally, it fills the circle with gray and then strokes the outline with black:

g2.setPaint(Color.gray); g2.fill(e); g2.setPaint(Color.black); ...
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

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Computer Graphics for Java Programmers, Second Edition

Computer Graphics for Java Programmers, Second Edition

Leen Ammeraal, Kang Zhang
Java Swing

Java Swing

Robert Eckstein, Marc Loy, Dave Wood
Java Extreme Programming Cookbook

Java Extreme Programming Cookbook

Eric M. Burke, Brian M. Coyner

Publisher Resources

ISBN: 1565924843Catalog PageErrata