8.1. If You're Not Too Picky...
Many applications don't need high quality color reproduction. Standard user interface components like buttons and scrolling lists don't demand accurate color reproduction — it doesn't matter if buttons are a slightly different color on different machines. Likewise, for charts and figures, it may not matter if the colors vary from machine to machine. But if you're writing desktop publishing software, or image manipulation software, you will need to be more careful. I'll talk about 2D's support for correct color handling later in this chapter.
If your application doesn't demand that colors look exactly the same everywhere, you don't have to read most of this chapter. It's easy to work with color without worrying about color spaces or profiles.
8.1.1. Creating Colors
The java.awt.Color class represents a color in a default RGB color space. To create a color, just specify its red, green, and blue components:
public Color(int r, int g, int b)
This constructor creates a new Color using the specified values for red, green and blue. The values should range from to 255, inclusive.
public Color(float r, float g, float b)
This constructor creates a new Color using the specified values for red, green and blue. The values should range from 0.0 to 1.0, inclusive.
public Color(int rgb)
This constructor accepts the red, green, and blue values in a packed integer. This means that the red, green, and blue values, which are 8 bits each, are stored inside a Java ...
Get Java 2D Graphics 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.