-
Notifications
You must be signed in to change notification settings - Fork 0
/
UpDown.java
72 lines (58 loc) · 1.79 KB
/
UpDown.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
60
61
62
63
64
65
66
67
68
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JLabel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
public class UpDown extends JFrame implements ActionListener{
private final int HEIGHT = 200, WIDTH = 200;
private JLabel topLabel;
private JLabel bottomLabel;
public static void main(String args[]) {
UpDown ud = new UpDown();
ud.setVisible(true);
}
public UpDown() {
setSize(WIDTH, HEIGHT);
setTitle("UpDown!");
setLayout(new BorderLayout());
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel topPanel = new JPanel();
JPanel centerPanel = new JPanel();
JPanel bottomPanel = new JPanel();
JButton downButton = new JButton("v");
JButton upButton = new JButton("^");
topLabel = new JLabel("On Top");
bottomLabel = new JLabel();
//bottomLabel = new JLabel("On Bottom");
//bottomLabel.setVisible(false);
downButton.addActionListener(this);
upButton.addActionListener(this);
topPanel.add(topLabel);
bottomPanel.add(bottomLabel);
centerPanel.add(downButton);
centerPanel.add(upButton);
add(topPanel, BorderLayout.NORTH);
add(bottomPanel, BorderLayout.SOUTH);
add(centerPanel, BorderLayout.CENTER);
}
public void actionPerformed(ActionEvent e) {
String ac = e.getActionCommand();
if (ac.equals("v")) {
topLabel.setText(" ");
bottomLabel.setText("On Bottom");
//topLabel.setVisible(false);
//bottomLabel.setVisible(true);
//this works differently in making North lose width. And extra empty label in North
//will fix that.
}
else if (ac.equals("^")) {
topLabel.setText("On Top");
bottomLabel.setText(" ");
//topLabel.setVisible(true);
//bottomLabel.setVisible(false);
}
}
}