/** * Create the frame */ public ColorPicker() { super(); getContentPane().setLayout(null); setBounds(100, 100, 500, 375); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
content = getContentPane();
final JButton go = new JButton(); go.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Color c; c = JColorChooser.showDialog(((Component)e.getSource( )).getParent( ), "Demo", Color.blue); content.setBackground(c);
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JColorChooser;
import javax.swing.JFrame;
public class ColorPicker extends JFrame {
/**
* Launch the application
* @param args
*/
Container content;
public static void main(String args[]) {
try {
ColorPicker frame = new ColorPicker();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Create the frame
*/
public ColorPicker() {
super();
getContentPane().setLayout(null);
setBounds(100, 100, 500, 375);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
content = getContentPane();
final JButton go = new JButton();
go.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Color c;
c = JColorChooser.showDialog(((Component)e.getSource( )).getParent( ),
"Demo", Color.blue);
content.setBackground(c);
}
});
go.setText("ChooserColor");
go.setBounds(33, 77, 128, 28);
getContentPane().add(go);
//
}
}