Repository navigation
Expand file tree
/
Copy pathNestedBoxes.java
More file actions
143 lines (117 loc) · 4.25 KB
/
Copy pathNestedBoxes.java
File metadata and controls
143 lines (117 loc) · 4.25 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
/**
* Created by IntelliJ IDEA.
* User: plamen
* Date: 28-Jun-2010
* Time: 14:50:51
* To change this template use File | Settings | File Templates.
*/
public class NestedBoxes extends JFrame implements ActionListener {
public static void main(String[] args) {
new NestedBoxes();
}
public NestedBoxes() {
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
System.exit(0);
}
;
});
buildFrame();
setLocation(250, 250);
setVisible(true);
}
private void buildFrame() {
Container pane = getContentPane();
BoxLayout boxLayout = new BoxLayout(pane, BoxLayout.Y_AXIS);
pane.setLayout(boxLayout);
pane.add(Box.createRigidArea(new Dimension(10, 10)));
JLabel label = new JLabel("A line of the text for the top of the window...");
label.setAlignmentX(Component.CENTER_ALIGNMENT);
pane.add(label);
pane.add(Box.createRigidArea(new Dimension(10, 10)));
JPanel middle = buildMiddle();
pane.add(middle);
pane.add(Box.createRigidArea(new Dimension(10, 10)));
JPanel bottom = buildBottom();
bottom.setAlignmentX(Component.CENTER_ALIGNMENT);
pane.add(bottom);
pane.add(Box.createRigidArea(new Dimension(10, 10)));
pack();
}
private JPanel buildMiddle() {
JPanel middle = new JPanel();
middle.setLayout(new BoxLayout(middle, BoxLayout.X_AXIS));
middle.add(Box.createRigidArea(new Dimension(10, 10)));
JTextArea t1 = new JTextArea(12, 20);
middle.add(t1);
middle.add(Box.createRigidArea(new Dimension(10, 10)));
JTextArea t2 = new JTextArea(12, 20);
middle.add(t2);
middle.add(Box.createRigidArea(new Dimension(10, 10)));
return middle;
}
private JPanel buildBottom() {
JButton button;
JPanel bottom = new JPanel();
bottom.setLayout(new BoxLayout(bottom, BoxLayout.X_AXIS));
bottom.add(Box.createHorizontalGlue());
button = new JButton("First");
button.addActionListener(this);
button.setAlignmentX(Component.CENTER_ALIGNMENT);
setSize(button);
bottom.add(button);
bottom.add(Box.createRigidArea(new Dimension(10, 10)));
button = new JButton("Second");
button.addActionListener(this);
button.setAlignmentX(Component.CENTER_ALIGNMENT);
setSize(button);
bottom.add(button);
bottom.add(Box.createRigidArea(new Dimension(10, 10)));
button = new JButton("Third");
button.addActionListener(this);
button.setAlignmentX(Component.CENTER_ALIGNMENT);
setSize(button);
bottom.add(button);
bottom.add(Box.createRigidArea(new Dimension(10, 10)));
button = new JButton("Fourth");
button.addActionListener(this);
button.setAlignmentX(Component.CENTER_ALIGNMENT);
setSize(button);
bottom.add(button);
bottom.add(Box.createRigidArea(new Dimension(10, 10)));
button = new JButton("Exit");
button.addActionListener(this);
button.setAlignmentX(Component.CENTER_ALIGNMENT);
setSize(button);
bottom.add(button);
bottom.add(Box.createRigidArea(new Dimension(10, 10)));
return bottom;
}
private void setSize(Component c) {
c.setPreferredSize(new Dimension(80, 25));
c.setMaximumSize(new Dimension(80, 25));
c.setMinimumSize(new Dimension(80, 25));
}
@Override
public void actionPerformed(ActionEvent e) {
String s = e.getActionCommand();
if (s.equals("Exit")) {
System.exit(0);
} else if (s.equals("First")) {
System.out.println("First");
} else if (s.equals("Second")) {
System.out.println("Second");
} else if (s.equals("Third")) {
System.out.println("Third");
} else if (s.equals("Fourth")) {
System.out.println("Fourth");
}
}
}