FileDocCategorySizeDatePackage
JColorDemo.javaAPI DocExample1822Tue Oct 09 16:22:42 BST 2001None

JColorDemo

public class JColorDemo extends JFrame

Fields Summary
JLabel
demo
A canvas to display the color in.
Color
lastChosen
The latest chosen Color
Constructors Summary
public JColorDemo()
Constructor - set up the entire GUI for this program

        super("Swing Color Demo");
		Container cp = getContentPane();
        JButton jButton;
        cp.add(BorderLayout.NORTH, jButton = new JButton("Change Color..."));
		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
					getBackground());			// default
System.out.println(ch);
				if (ch != null) {
					demo.setBackground(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();
        addWindowListener(new WindowCloser(this, true));
	
Methods Summary
public static voidmain(java.lang.String[] argv)
good old main

        new JColorDemo().setVisible(true);