-
Notifications
You must be signed in to change notification settings - Fork 0
/
Swing56.java
30 lines (24 loc) · 892 Bytes
/
Swing56.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
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Swing56 {
public static void main(String[] args) {
JFrame frame = new JFrame("Color Chooser");
frame.setSize(400,400);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
Container c = frame.getContentPane();
c.setLayout(new GridBagLayout());
JButton button1 = new JButton("Change Color");
c.add(button1);
button1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Color color = JColorChooser.showDialog(null, "Select a color", Color.RED);
c.setBackground(color);
}
});
frame.revalidate();
}
}