Reference no: EM13166258
Create a class called ComboPanel that extends JPanel. The class constructor should add three JComboBox objects to the panel and initialize each of them with Integer objects with values that range from 0 to 255. Each JComboBox will allow the user to select an integer for the three components (red, green, and blue) that make up a Color object. For example, invoking new Color(255, 215, 0) creates a yellowish color object.
Create listener objects for each JComboBox that set the background color of the panel when the user selects an integer. Use the current values supplied by the JComboBox objects to determine the background color.
Use the following code to test your class.
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JComboBox;
public class ComboPanelRunner
{
/**
Creates and displays the application frame.
*/
public static void main(String[] args)
{
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400, 500);
ComboPanel cp = new ComboPanel();
frame.add(cp);
frame.setVisible(true);
}
}