-
Notifications
You must be signed in to change notification settings - Fork 0
/
GUIComponent.java
109 lines (83 loc) · 3 KB
/
GUIComponent.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
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
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.FlowLayout;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
public class GUIComponent {
private JPanel mainContainer = new JPanel();
private JTextArea boxArea = new JTextArea(5,20);
private JButton startBtn;
private JButton resetBtn;
private JButton closeBtn;
private JComboBox<Integer> setRange;
private JComboBox<Integer> setCounter;
public JPanel MainUI() {
mainContainer.setLayout(new BorderLayout());
mainContainer.add(setLeftPanel(), BorderLayout.WEST);
mainContainer.add(setCenterPanel(), BorderLayout.CENTER);
mainContainer.add(setSouthPanel(), BorderLayout.SOUTH);
return mainContainer;
}
public JComponent setLeftPanel() {
JPanel LeftPanel = new JPanel();
LeftPanel.setLayout(new BorderLayout());
JLabel lottoResultLabel = new JLabel("Random Lotto Result");
lottoResultLabel.setHorizontalAlignment((int)Component.CENTER_ALIGNMENT);
LeftPanel.add(lottoResultLabel,BorderLayout.NORTH);
LeftPanel.add(ShowTextArea(), BorderLayout.CENTER);
return LeftPanel;
}
public JComponent ShowTextArea() {
boxArea.setEditable(false);
JScrollPane sPaneForBoxArea = new JScrollPane(boxArea);
return sPaneForBoxArea;
}
public JComponent setCenterPanel() {
JPanel CenterPanel = new JPanel();
CenterPanel.setLayout(null);
JLabel rangeLabel = new JLabel("Lotto Number Range");
JLabel counterLabel = new JLabel("Lotto Number Counter");
setRange =(JComboBox<Integer>) setComboBox(2,80);
setCounter = (JComboBox<Integer>) setComboBox(1,100);
rangeLabel.setBounds(20, 20, 200, 30);
counterLabel.setBounds(20, 60, 200, 30);
rangeLabel.setToolTipText("range is selected number under one");
setRange.setLocation(160, 20);
setCounter.setLocation(160, 60);
CenterPanel.add(rangeLabel);
CenterPanel.add(counterLabel);
CenterPanel.add(setRange);
CenterPanel.add(setCounter);
return CenterPanel;
}
public JComponent setComboBox(int firstNumber, int range) {
Vector<Integer> setNumber = new Vector<>();
JComboBox<Integer> setNumberBox = new JComboBox<>(setNumber);
for(int i=firstNumber;i<range;i++) {
setNumber.add(i);
}
setNumberBox.setSize(80, 30);
setNumberBox.setSelectedIndex(firstNumber-1);
return setNumberBox;
}
public JComponent setSouthPanel() {
JPanel southPanel = new JPanel();
southPanel.setLayout(new FlowLayout());
startBtn = new JButton("start");
resetBtn = new JButton("reset");
closeBtn = new JButton("close");
southPanel.add(startBtn);
southPanel.add(resetBtn);
southPanel.add(closeBtn);
startBtn.addActionListener(new ButtonActionListner(boxArea,setRange,setCounter));
resetBtn.addActionListener(new ButtonActionListner(boxArea));
closeBtn.addActionListener(new ButtonActionListner(boxArea,mainContainer));
return southPanel;
}
}