CS2305 PROGRAMMING PARADIGMS
Using color, fonts, and images
Color: java.awt.Color
Color class creates a solid RGB color with the specified red, green, blue value in the range (0-
255). Java’s abstract color model uses 24-bit color. The values of each color must be in the range
(0- 255).
Constructor:
Color(int red, int green, int blue) - create new color object for any combination of red, green,
and blue.
Java.awt.Color class used to create new color object for any combination of red, green, and blue,
and it predefines a few color constants. They are stored in class variables,
Color.white (255,255,255)
Color.black (0,0,0)
Color.lightGray (192,192,192)
Color.gray (128,128,128)
Color.darkGray (64,64,64)
Color.red (255,0,0)
Color.blue (0,0,255)
Color.yellow (255,255,0)
Color.magenta (255,0,255)
Color.cyan( 0,255,255)
Color.pink (255,175,175)
Color.orange (255,200,0)
Color.green(0,255,0)
java.awt.Component
Component class defines setBackground() and setForeground() methods for setting background
and foreground colors to the window. Since Frame is a subclass of Component class it can use
these methods.
·void setBackground(java.awt.Color) – set Background color to the window.
·void setForeground(java.awt.Color)- set Foreground color to the window.
java.awt.Graphics
setColor() method used to set the current color for the graphics context which is defined in
Graphics class.
·void setColor(java.awt.Color)
© A.V.C College of Engineering