Repository navigation
Expand file tree
/
Copy pathVerticalBox2.java
More file actions
95 lines (86 loc) · 2.97 KB
/
Copy pathVerticalBox2.java
File metadata and controls
95 lines (86 loc) · 2.97 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
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:12:10
* To change this template use File | Settings | File Templates.
*/
public class VerticalBox2 extends JFrame implements ActionListener {
public static void main(String[] args) {
new VerticalBox2();
}
public VerticalBox2() {
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
buildFrame();
setLocation(250, 250);
setVisible(true);
}
private void buildFrame() {
JButton button;
Container pane = getContentPane();
BoxLayout boxLayout = new BoxLayout(pane, BoxLayout.Y_AXIS);
pane.setLayout(boxLayout);
pane.add(Box.createRigidArea(new Dimension(100, 10)));
button = new JButton("First");
button.addActionListener(this);
button.setAlignmentX(Component.CENTER_ALIGNMENT);
setSize(button);
pane.add(button);
pane.add(Box.createRigidArea(new Dimension(100, 10)));
button = new JButton("Second");
button.addActionListener(this);
button.setAlignmentX(Component.CENTER_ALIGNMENT);
setSize(button);
pane.add(button);
pane.add(Box.createRigidArea(new Dimension(100, 10)));
button = new JButton("Third");
button.addActionListener(this);
button.setAlignmentX(Component.CENTER_ALIGNMENT);
setSize(button);
pane.add(button);
pane.add(Box.createRigidArea(new Dimension(100, 10)));
button = new JButton("Fourth");
button.addActionListener(this);
button.setAlignmentX(Component.CENTER_ALIGNMENT);
setSize(button);
pane.add(button);
pane.add(Box.createRigidArea(new Dimension(100, 10)));
button = new JButton("Exit");
button.addActionListener(this);
button.setAlignmentX(Component.CENTER_ALIGNMENT);
setSize(button);
pane.add(button);
pack();
}
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) {
//To change body of implemented methods use File | Settings | File Templates.
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");
}
}
}