forked from patniemeyer/learningjava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLocalColor.java
More file actions
26 lines (22 loc) · 799 Bytes
/
Copy pathLocalColor.java
File metadata and controls
26 lines (22 loc) · 799 Bytes
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
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class LocalColor {
public static void main(String[] args) {
final JFrame frame = new JFrame("LocalColor v1.0");
final Container content = frame.getContentPane( ); // unecessary in 1.5+
content.setLayout(new GridBagLayout( ));
JButton button = new JButton("Change color...");
content.add(button);
button.addActionListener(new ActionListener( ) {
public void actionPerformed(ActionEvent e) {
Color c = JColorChooser.showDialog(frame,
"Choose a color", content.getBackground( ));
if (c != null) content.setBackground(c);
}
});
frame.setSize(200, 200);
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
frame.setVisible(true);
}
}