// JColorChooserApplet.java // Demo of JColorChooser as an applet // import java.awt.*; import java.awt.event.*; import javax.swing.*; public class JColorChooserApplet extends JApplet implements ActionListener { private JButton changeColor; private Color color = Color.lightGray; private Container c; public void init( ) { c = getContentPane( ); c.setLayout( new FlowLayout( ) ); changeColor = new JButton( "Change Color" ); changeColor.addActionListener( this ); c.add( changeColor ); } public void paint( Graphics g ) { c.setBackground( color ); } public void actionPerformed( ActionEvent e ) { color = JColorChooser.showDialog( this, "Choose a color", color ); if ( color == null ) color = Color.lightGray; repaint( ); } }