Awtcolor class colors are made of red green and blue

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: lor Class You You can set colors for GUI components by using the java.awt.Color class. Colors are made of red, green, and blue components, each of which is represented by a byte value that describes its intensity, ranging from 0 (darkest shade) to 255 (lightest shade). This is known as the RGB model. RGB Color Color c = new Color(r, g, b); r, g, and b specify a color by its red, green, and blue components. Example: Color c = new Color(228, 100, 255); Color(228, 100, 255) EE3206/EE5805 Java Programming & Applications 17 Standard Standard Colors There There are thirteen standard color constants: BLACK BLACK, BLUE, CYAN, DARK_GRAY, GRAY, GREEN, LIGHT_GRAY, MAGENTA, ORANGE, PINK, RED, WHITE, and YELLOW. You You can use these two methods to set the component’s background and foreground colors: setBackground(Color setBackground(Color c) setForeground setForeground(Color c) Example: // jbt is an instance of JButton jbt jbt.setBackground(Color.YELLOW); jbt.setBackground(Color.YELLOW); jbt.setBackground(Color.LIGHT_GRAY); jbt.setBackground(Color.LIGHT_GRAY); EE3206/EE5805 Java Programming & Applications 18 The Font The Font Class Font Font Names Standard font names that are supported in all platforms are: SansSerif, Serif, Monospaced, Dialog, or DialogInput. Font Font Style Font.PLAIN, Font.BOLD, Font.ITALIC Font myFont = new Font(name, style, size); Example: Font myFont = new Font("SansSerif", Font.BOLD, 16); Font myFont = new Font("Serif", Font.BOLD|Font.ITALIC, 12); JButton jbtOK = new JButton("OK"); jbtOK.setFont(myFont); EE3206/EE5805 Java Programming & Applications a bitwise union 19 Using Using Pane...
View Full Document

Ask a homework question - tutors are online