Color greenColor = new Color(0, 255, 0); // creates a color with max green value int greenValue = greenColor.getGreen(); // returns 255
JPanel panel = new JPanel(); panel.setBackground(Color.getGreen()); // sets the background color of the panel to greenThis code sets the background color of a JPanel to green using the static method getGreen() which returns a Color object with a green value of 255. These examples use the java.awt.Color package library.