-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGlassExample.java
More file actions
66 lines (54 loc) · 1.87 KB
/
GlassExample.java
File metadata and controls
66 lines (54 loc) · 1.87 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
/*
* Demonstrate use of GlassPane in JWindow & friends. Buttons enable/disable it.
* @author Eckstein et al, in the O'Reilly book "Java Swing"
*/
public class GlassExample {
/** Construct a Splash screen with the given image */
public static void main(String[] args) {
JFrame f = new JFrame("GlassPane");
final JPanel p1 = new JPanel();
p1.add(new JLabel("GlassPane Example"));
JButton show = new JButton("Show");
p1.add(show);
p1.add(new JButton("No-op"));
f.getContentPane().add(p1);
final JPanel glass = (JPanel) f.getGlassPane();
glass.setVisible(true);
glass.setLayout(new GridBagLayout());
JButton glassButton = new JButton("Hide");
glass.add(glassButton);
f.setSize(150, 80);
f.setVisible(true);
boolean debug = false;
if (debug) {
System.out.println("Button is " + glassButton);
System.out.println("GlassPane is " + glass);
}
// Add actions to the buttons...
// show button (re-)shows the glass pane.
show.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
glass.setVisible(true);
p1.repaint();
}
});
// hide button hides the Glass Pane to show what's under.
glassButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
glass.setVisible(false);
p1.repaint();
}
});
}
}