Color Chooser

PHOTO EMBED

Wed Dec 27 2023 05:13:25 GMT+0000 (Coordinated Universal Time)

Saved by @dsce

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.colorchooser.*;

public class ColorChooserDemo
{   private JFrame frame;
	private JColorChooser cc;
	private JButton b;
     
	public ColorChooserDemo()
	{
		frame = new JFrame("A Sample Frame");
		frame.setSize(700, 500);
		
		cc = new JColorChooser(); frame.add(cc);
		
		b = new JButton("Color Changer");
		b.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent ae)
			{ frame.getContentPane().setBackground(cc.getColor()); }
		});
		frame.add(b);		
				
		frame.setLayout(new FlowLayout());
           frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	    frame.setVisible(true);
	}
	
	public static void main(String[] args)
	{  	new ColorChooserDemo(); 	}
}
content_copyCOPY