FileDocCategorySizeDatePackage
JColorDemo.javaAPI DocExample1809Sun Feb 22 21:39:22 GMT 2004None

JColorDemo

public class JColorDemo extends JFrame

Fields Summary
protected JLabel
demo
A canvas to display the color in.
Constructors Summary
public JColorDemo()
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);
	
Methods Summary
public static voidmain(java.lang.String[] argv)
good old main

        new JColorDemo().setVisible(true);