Java Reference
In-Depth Information
Display 18.20
JColorChooser Dialog (part 1 of 2)
1 import javax.swing.JFrame;
2 import javax.swing.JPanel;
3 import javax.swing.JButton;
4 import javax.swing.JColorChooser;
5 import java.awt.event.ActionListener;
6 import java.awt.event.ActionEvent;
7 import java.awt.BorderLayout;
8 import java.awt.FlowLayout;
9 import java.awt.Color;
10 public class JColorChooserDemo extends JFrame
11
implements ActionListener
12 {
13
public static final int WIDTH = 400;
14
public static final int HEIGHT = 200;
15
private Color sampleColor = Color.LIGHT_GRAY;
16 public static void main (String[] args)
17 {
18 JColorChooserDemo gui = new JColorChooserDemo();
19 gui.setVisible( true );
20 }
21 public JColorChooserDemo()
22 {
23 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
24 getContentPane().setBackground(sampleColor);
25 setLayout( new BorderLayout());
26 setTitle("JColorChooser Demo");
27 setSize(WIDTH, HEIGHT);
28 JPanel buttonPanel = new JPanel();
29 buttonPanel.setBackground(Color.WHITE);
30 buttonPanel.setLayout( new FlowLayout());
31 JButton chooseButton = new JButton("Choose a Color");
32 chooseButton.addActionListener( this );
33 buttonPanel.add(chooseButton);
34 add(buttonPanel, BorderLayout.SOUTH);
35 }
(continued)
Search WWH ::




Custom Search