Constructor - set up the entire GUI for this program
super("Swing Color Demo");
Container cp = getContentPane();
JButton jButton;
cp.add(jButton = new JButton("Change Color..."), BorderLayout.NORTH);
jButton.setToolTipText("Click here to see the Color Chooser");
jButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent actionEvent)
{
Color ch = JColorChooser.showDialog(
JColorDemo.this, // parent
"Swing Demo Color Popup", // title
demo.getForeground()); // default
System.out.println("Your selected color is " + ch);
if (ch != null) {
demo.setForeground(ch);
demo.repaint();
}
}
});
cp.add(BorderLayout.CENTER, demo =
new JLabel("Your One True Color", JLabel.CENTER));
demo.setToolTipText("This is the last color you chose");
pack();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);