/** Based on section 12.6 in book - using a slider. */ import java.awt.*; import javax.swing.*; public class Driver { public static void main(String [] args) { JFrame frame = new JFrame("Color"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel colorPanel = new JPanel(); colorPanel.setPreferredSize(new Dimension(100,100)); colorPanel.setBackground(new Color(128,128,255)); // Our frame will contain 2 panels -- input in the // form of sliders, and output in the form of a 100x100 // "colorPanel" displaying the color in its background. // Note that we have seen several ways to put multiple // panels in a frame. Panels must go in some "container" // object. This container may be, for example: // 1. an outer level panel // 2. a scroll pane or split pane // 3. the default pane belonging to the frame, which we // obtain by calling getContentPane(). // We are required to use the frame's getContentPane() // to insert the top-level panel into the frame, but // it's up to us how to organize subpanels. Container pane = frame.getContentPane(); pane.setLayout(new FlowLayout()); pane.add(new SliderPanel(colorPanel)); pane.add(colorPanel); frame.pack(); frame.show(); } }