JCOLOR CHOOSER CONSTRUCTOR AND ITS USES:
Color showDialog(Component,String,Color)
As you can see I have used this constructor in our program this constructor creates modal dialog here string specifies the the tittle of color chooser and color specifies the initial color of color chooser.
JCOLORCHOOSER()
Creates a simple color chooser with initial color of white.
JCOLORCHOOSER(COLOR)
By using this constructor user can specify the initial colour of jcolor chooser.
JCOLORCHOOSER()
Creates a simple color chooser with initial color of white.
JCOLORCHOOSER(COLOR)
By using this constructor user can specify the initial colour of jcolor chooser.
CODING:
import javax.swing.*;import java.awt.*;
import javax.swing.event.*;
import java.awt.event.*;
class tab extends JFrame
implements ActionListener
{
JButton jb;
tab()
{
super();
setTitle("Color Chooser");
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jb =new JButton("Click To Choose Background Color");
FlowLayout f=new FlowLayout();
setLayout(f);
add(jb);
jb.addActionListener(this);
jb.setActionCommand("choose");
setSize(250, 300);
setVisible(true);
}
public void actionPerformed(ActionEvent ae)
{
if ("choose".equals(ae.getActionCommand()))
{
Color choose = JColorChooser.showDialog(this, "Choose JButton Background",Color.BLACK);
getContentPane().setBackground(choose);
}
}
}
class colorchooser
{
public static void main(String args[])
{
tab x= new tab();
}
}
0 comments:
Post a Comment