The opacity (alpha-value) is controlled by the 4th parameter of the following constructor of Class Color:
public Color(int red, int green, int blue, int alpha)
Each parameter in the above constructor must be an integer number in the range 0 to 255.
The above output is produced by the following Java code:
| Java Code |
|---|
g.setFont(new Font("TimesRoman", Font.BOLD, 48));
g.setColor(new Color(0, 0, 255, 255));
g.drawString("alpha = 255", 30, 50);
g.setColor(new Color(0, 0, 255, 200));
g.drawString("alpha = 200", 30, 130);
g.setColor(new Color(0, 0, 255, 150));
g.drawString("alpha = 150", 30, 210);
g.setColor(new Color(0, 0, 255, 100));
g.drawString("alpha = 100", 30, 290);
g.setColor(new Color(0, 0, 255, 50));
g.drawString("alpha = 50", 30, 360);
g.setColor(new Color(0, 0, 255, 10));
g.drawString("alpha = 10", 30, 430);
|