How To Create Java Color Chooser

Create Java Color Chooser

You need to know that Java can do almost about anything when it comes to programming, besides having its weaknesses.

Here is a tutorial on how to create java color chooser using eclipse ide:

import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
public class ColorChooserExample extends JFrame implements ActionListener {
JButton b;
Container c;
ColorChooserExample(){
c=getContentPane();
c.setLayout(new FlowLayout());
b=new JButton(“color”);
b.addActionListener(this);
c.add(b);
}
public void actionPerformed(ActionEvent e) {
Color initialcolor=Color.RED;
Color color=JColorChooser.showDialog(this,”Select a color”,initialcolor);
c.setBackground(color);
}

public static void main(String[] args) {
ColorChooserExample ch=new ColorChooserExample();
ch.setSize(400,400);
ch.setVisible(true);
ch.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
}

heres what you’ll get :

java color chooser

java color chooser

Published by

Rafif Santika

The programming language that I specialize in is Java, because I think Java programming language is more universal and of course because I like it regardless of any reason.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.