-
Notifications
You must be signed in to change notification settings - Fork 0
/
NumberLots.java
276 lines (232 loc) · 8.67 KB
/
NumberLots.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
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.IOException;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.UIManager;
import javax.swing.plaf.FontUIResource;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;
class NumberLotsPanel extends JPanel implements ActionListener {
JPanel main_panel;
JButton bt_chooseNumRange, bt_drawingLots;
JLabel lb_randomNum, lb_numRange;
JMenuBar mb;
JMenuItem mni_developmentInquiry, mni_developmentInfo;
DefaultTableModel dtm;
JTable tb_result;
//---------------------------------------------------//
String tbh_result[] = { "회차", "결과", "범위" };
String contents[] = new String[3];
int numRange, randomNum, time, count = 0, control = 0;
boolean tf = false;
String jop_message = "<프로그램 단축키>\n" +
"Space Bar : 뽑기\n" +
"R : 범위 지정\n" +
"(한번의 버튼 클릭이 있어야 단축키 사용이 가능합니다)\n\n" +
"<프로그램 관련 정보>\n" +
"◆개발자: 성열암\n" +
"◆문의(카카오톡): sya3369";
//--------------------------------------------------//
Runtime runtime = Runtime.getRuntime();
public NumberLotsPanel() {
setLayout(new BorderLayout());
// --------------------------//
main_panel = new JPanel();
main_panel.setLayout(null);
// ------------------------//
// 라벨 관련 정의 부분
lb_randomNum = new JLabel();
lb_randomNum.setOpaque(true);
lb_randomNum.setBackground(Color.DARK_GRAY);
lb_randomNum.setForeground(Color.WHITE);
lb_randomNum.setFont(new Font("돋움", Font.BOLD, 100));
lb_numRange = new JLabel(" 정해진 범위: 1~?");
lb_numRange.setFont(new Font("돋움", Font.PLAIN, 15));
lb_numRange.setOpaque(true);
lb_numRange.setForeground(Color.WHITE);
lb_numRange.setBackground(Color.BLACK);
// 버튼 관련 정의 부분
bt_chooseNumRange = new JButton("범위설정");
bt_chooseNumRange.setForeground(Color.WHITE);
bt_chooseNumRange.setBackground(Color.BLACK);
bt_chooseNumRange.setFont(new Font("바탕체", Font.BOLD, 18));
bt_chooseNumRange.setFocusPainted(false); // 버튼 텍스트 포커스 표시 설정
bt_drawingLots = new JButton("뽑기");
bt_drawingLots.setBackground(Color.WHITE);
bt_drawingLots.setFont(new Font("바탕체", Font.BOLD, 18));
bt_drawingLots.setEnabled(false);
bt_drawingLots.setFocusPainted(false);
// 메뉴 관련 정의 부분
mb = new JMenuBar();
JMenu mn_info = new JMenu(" 정 보 ");
JMenu mn_exit = new JMenu(" 종 료 ");
mn_exit.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
System.exit(0);
}
});
mni_developmentInquiry = new JMenuItem("개발문의");
mni_developmentInfo = new JMenuItem("프로그램 정보");
// 테이블 관련 정의 부분
dtm = new DefaultTableModel(null, tbh_result) {
public boolean isCellEditable(int a, int b) {
return false;
}
};
tb_result = new JTable(dtm);
tb_result.getTableHeader().setReorderingAllowed(false);
tb_result.setFont(new Font(null, Font.PLAIN, 15));
JScrollPane jsp_result = new JScrollPane(tb_result);
// 컬럼 해더 높이
JTableHeader header = tb_result.getTableHeader();
header.setFont(new Font("함초롬바탕", Font.BOLD, 18));
Dimension d = header.getPreferredSize();
d.height = 25;
header.setPreferredSize(d);
// cell 높이
tb_result.setRowHeight(20);
// 셀 너비,셀 정렬 대한 설정
DefaultTableCellRenderer cellCenter = new DefaultTableCellRenderer();
cellCenter.setHorizontalAlignment(JLabel.CENTER);
tb_result.getColumnModel().getColumn(0).setPreferredWidth(0);
tb_result.getColumnModel().getColumn(0).setCellRenderer(cellCenter);
tb_result.getColumnModel().getColumn(1).setPreferredWidth(150);
tb_result.getColumnModel().getColumn(1).setCellRenderer(cellCenter);
tb_result.getColumnModel().getColumn(2).setPreferredWidth(30);
tb_result.getColumnModel().getColumn(2).setCellRenderer(cellCenter);
// ------------------------------------//
jsp_result.setBounds(8, 160, 480, 240);
lb_randomNum.setBounds(8, 50, 500, 100);
lb_numRange.setBounds(8, 8, 600, 30);
bt_chooseNumRange.setBounds(120, 415, 120, 40);
bt_drawingLots.setBounds(250, 415, 120, 40);
// -----------------------------------//
main_panel.add(jsp_result);
main_panel.add(lb_randomNum);
main_panel.add(lb_numRange);
main_panel.add(bt_chooseNumRange);
main_panel.add(bt_drawingLots);
mn_info.add(mni_developmentInquiry);
mn_info.addSeparator();
mn_info.add(mni_developmentInfo);
mb.add(mn_info);
mb.add(mn_exit);
add(main_panel);
// ---------------------------------------//
bt_chooseNumRange.addActionListener(this);
bt_drawingLots.addActionListener(this);
mni_developmentInquiry.addActionListener(this);
mni_developmentInfo.addActionListener(this);
bt_chooseNumRange.addKeyListener(new ShortCut());
bt_drawingLots.addKeyListener(new ShortCut());
}
// 랜덤범위를 1~X 까지 선택되게 지정(다른값에 대해서는 반복을 통해제어)
void chooseRange() {
String StrNumRange;
while (true) {
UIManager.put("OptionPane.messageFont", new FontUIResource(new Font("함초롬돋움", Font.PLAIN, 13)));
StrNumRange = (String) JOptionPane.showInputDialog(null, "마지막 번호를 정해주세요");
if (!(StrNumRange == null)) {
if (StrNumRange.equals(""))
continue;
if ((StrNumRange.matches(".*[ㄱ-ㅎㅏ-ㅣ가-?|a-z|A-Z]+.*")))
continue;
if (Integer.parseInt(StrNumRange) > 1)
break;
} else
return;
}
numRange = Integer.parseInt(StrNumRange);
lb_numRange.setText(" 정해진 범위: 1~" + numRange);
}
@Override // 버튼 액션에 대한 처리 부분
public void actionPerformed(ActionEvent e) {
if (e.getSource() == bt_chooseNumRange) {
chooseRange();
bt_drawingLots.setEnabled(true);
tf = false;
} else if (e.getSource() == bt_drawingLots) {
bt_chooseNumRange.setEnabled(false);
lb_randomNum.setVisible(true);
randomNum = (int) (Math.random() * numRange + 1);
tf = true;
bt_drawingLots.setText("" + (time = 3));
} else if (e.getSource() == mni_developmentInquiry) {
try {
runtime.exec("explorer.exe https://blog.naver.com/hotkimchi13/221319599879");
} catch(IOException ex) {
System.exit(0);
}
} else if (e.getSource() == mni_developmentInfo) {
UIManager.put("OptionPane.messageFont", new FontUIResource(new Font("함초롬돋움", Font.PLAIN, 13)))
JOptionPane.showMessageDialog(null, jop_message, "프로그램 정보", JOptionPane.INFORMATION_MESSAGE, null);
}
}
// 단축키에 대한 처리 부분
class ShortCut extends KeyAdapter {
public void keyPressed(KeyEvent e) {
String k = e.getKeyText(e.getKeyCode()); // 키값
if(k.equals("r") || k.equals("R")) { bt_chooseNumRange.doClick(); return; }
bt_drawingLots.doClick();
}
}
}
public class NumberLots extends JFrame {
NumberLotsPanel cp = new NumberLotsPanel();
public NumberLots() {
setTitle("랜덤 번호 선택기");
setSize(500, 523);
setLocation(590, 250);
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setJMenuBar(cp.mb);
add(cp);
setVisible(true);
// 시간의 흐름에 대한 정의 부분
while (true) {
if (cp.time == 0) {
if (cp.tf) {
cp.bt_chooseNumRange.setEnabled(true);
cp.tf = false;
cp.bt_drawingLots.setText("뽑기");
cp.lb_randomNum.setText("" + cp.randomNum);
cp.contents[0] = "" + (++cp.count);
cp.contents[1] = "" + cp.randomNum;
cp.contents[2] = "1~" + cp.numRange;
cp.dtm.addRow(cp.contents);
}
}
try {
if (cp.tf)
cp.bt_drawingLots.setText("" + cp.time--);
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) {
new NumberLots();
}
}