-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolorchoose.java
39 lines (34 loc) · 902 Bytes
/
colorchoose.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package mayank;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class colorchoose extends JFrame{
private JButton b;
private JPanel panel;
private Color color=(Color.WHITE);
public colorchoose(){
super("the title");
panel=new JPanel();
panel.setBackground(Color.WHITE);
b=new JButton("color chooser");
b.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
color=JColorChooser.showDialog(null, "pick your color", color);
if(color==null)
color=color.WHITE;
panel.setBackground(color);
}
}
);
add(panel,BorderLayout.CENTER);
add(b,BorderLayout.SOUTH);
}
public static void main(String[] args) {
colorchoose ob=new colorchoose();
ob.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ob.setVisible(true);
ob.setSize(300,200);
}
}