Frame Menu Menu Event and Color Chooser

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ColorChooserDemo extends JFrame implements ActionListener
{
	JMenuBar bar;
	JMenu file;
	JMenuItem new1,close,new2;
	JPanel p1;
	JColorChooser cchooser;
	JDialog jd;
	public ColorChooserDemo()
{
	super("win");
	bar=new JMenuBar();
	file=new JMenu("file");
	new1=new JMenuItem("select color");
	p1=new JPanel();
	getContentPane().add(p1);
	close=new JMenuItem("close");
	file.add(new2=new JMenuItem("select clor1"));
	cchooser=new JColorChooser();
	jd=new JDialog();
	setJMenuBar(bar);
	bar.add(file);
	file.add(new1);
	file.add(close);
	setSize(400,500);
	setVisible(true);
	new1.addActionListener(this);
	close.addActionListener(this);
	new2.addActionListener(this);
	setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
@Override
public void actionPerformed(ActionEvent evt)
{
	if(evt.getSource()==new1)
	{
		Color c=JColorChooser.showDialog(null,"select color",new Color(10,20,40));
		p1.setBackground(c);
	}
	if(evt.getSource()==close)
	{
		System.exit(0);
	}
	if(evt.getSource()==new2)
	{
	jd=JColorChooser.createDialog(null,"my dioalog",true,cchooser,new myaction1(),new myaction2());
	jd.setSize(300,300);
	jd.setVisible(true);
	}
	}
public static void main(String args[])
{
	new ColorChooserDemo();
}
public class myaction1 implements ActionListener
{
@Override
public void actionPerformed(ActionEvent evt1)
{
	Color c1=cchooser.getColor();
	p1.setBackground(c1);
}
}
public class myaction2 implements ActionListener
{
@Override
public void actionPerformed(ActionEvent evt1)
{
jd.setVisible(false);
}
}
}

Download

Frame in Swing

Simple Frame
Frame with Panel
Frame Menu Event ans Color Chooser
Frame with Panel and Button
TextField and TextArea
Combobox in Frame
Change Icon of Frame
Scrollbar in Frame
Scrollbar in Frame
Add picture in Frame
Label in Frame
Toggle Buttons in frame
Radio Buttons in Frame


Write your Comment

Name :
Email Id : [ We will not publish your email id ]
Your Comment : [ Maximum 200 chars ]
Enter Security code