source file name:   chooserdemo.java

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import javax.swing.tree.*;

class chooserdemo extends JFrame

{

JColorChooser jc=new JColorChooser();

public static void main(String as[])

{

chooserdemo f=new chooserdemo();

f.setTitle("Color Chooser program");

f.setSize(300,300);

f.setVisible(true);

}

public chooserdemo()

{

addMouseListener(new MouseAdapter(){

public void mousePressed(MouseEvent me)

{

System.out.print("test");

Color col=JColorChooser.showDialog(new chooserdemo(),"select color",Color.pink);

Graphics g=getGraphics();

g.setColor(col);

g.fillRect(50,70,150,100);

}

}

);

}

}

output: