-
Notifications
You must be signed in to change notification settings - Fork 0
/
Swing55.java
59 lines (52 loc) · 1.92 KB
/
Swing55.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
public class Swing55 {
public static void main(String[] args) {
JFrame frame = new JFrame("GlassPane");
JPanel panel = new JPanel();
JLabel label = new JLabel("HANLLA SOOMRO");
JButton button1 = new JButton("Hide");
JButton button2 = new JButton("Show");
JButton button3 = new JButton("Hide");
frame.setSize(400,400);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
frame.setGlassPane(new JComponent() {
@Override
protected void paintComponent(Graphics g) {
g.setColor(new Color(20, 40, 0, 150));
g.fillRect(0,0,getWidth(), getHeight());
}
});
final Container glassPane = (Container) frame.getGlassPane();
glassPane.setLayout(new GridBagLayout());
glassPane.addMouseListener(new MouseAdapter() {});
glassPane.add(button3);
button1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
label.setVisible(!label.isVisible());
}
});
button2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
glassPane.setVisible(true);
}
});
button3.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
glassPane.setVisible(false);
}
});
panel.add(label);
panel.add(button1);
panel.add(button2);
frame.getContentPane().add(panel);
}
}