import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
class ColorChooserDemo extends JFrame implements ActionListener
{
JButton b;
Container c;
public ColorChooserDemo(){
c=getContentPane();
c.setLayout(new FlowLayout());
b=new JButton("color");
b.addActionListener(this);
c.add(b);
}
public void actionPerformed(ActionEvent e)
{
Color color=JColorChooser.showDialog(this,"Select a color",null);
c.setBackground(color);
}
public static void main(String[] args) {
ColorChooserDemo f=new ColorChooserDemo();
f.setSize(400,400);
f.setVisible(true);
f.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
}
output:
0 Comments
Post a Comment