/**
* @(#)ColorDialog_ChangeBackground.java
*
*
* @author -Anant Mahale
* @version 1.00 2013/8/17
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
class ColorDialog_ChangeBackground
{
public static void main(String args[])
{
myframe m=new myframe();
m.setTitle("Color DialogBox Demo");
m.setSize(500,500);
m.setLocation(100,100);
m.setVisible(true);
m.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
class myframe extends JFrame
{
mypanel p;
myframe()
{
p=new mypanel();
Container c=getContentPane();
c.add(p);
}
class mypanel extends JPanel implements ActionListener
{
JButton btn_click;
Color c;
mypanel()
{
btn_click=new JButton("Click");
btn_click.addActionListener(this);
add(btn_click);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==btn_click)
{
try
{
c=JColorChooser.showDialog(this,"Choose Your Color",Color.pink);
setBackground(c);
}
catch(Exception e)
{
System.out.println(e);
}
}
}
}
}
No comments:
Post a Comment