質問編集履歴
2
ソースコードの編集
test
CHANGED
File without changes
|
test
CHANGED
@@ -12,21 +12,11 @@
|
|
12
12
|
|
13
13
|
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
15
|
MainInit
|
22
16
|
|
23
17
|
```lang-Java
|
24
18
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
public class MainInit implements ActionListener ,
|
19
|
+
public class MainInit implements ActionListener, MouseListener, MouseMotionListener{ //impriments(組み込む)
|
30
20
|
|
31
21
|
private JFrame mainFrame;
|
32
22
|
|
@@ -52,8 +42,6 @@
|
|
52
42
|
|
53
43
|
|
54
44
|
|
55
|
-
private SettingWindow settingwindow;
|
56
|
-
|
57
45
|
|
58
46
|
|
59
47
|
private ItemBox itemboxtest1;
|
@@ -66,21 +54,25 @@
|
|
66
54
|
|
67
55
|
|
68
56
|
|
69
|
-
|
57
|
+
private Thumbnail DrawPanel;
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
private JFrame mainFrame2;
|
62
|
+
|
63
|
+
private Point startPoint;
|
64
|
+
|
65
|
+
private Point endPoint;
|
66
|
+
|
67
|
+
private int x;
|
68
|
+
|
69
|
+
private int y;
|
70
70
|
|
71
71
|
public MainInit(){
|
72
72
|
|
73
73
|
mainFrame = new JFrame("エビデンスキャプチャ");
|
74
74
|
|
75
|
-
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
75
|
+
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); mainFrame.setSize(500, 300); mainFrame.setLocationRelativeTo(null); contentPane = mainFrame.getContentPane();
|
76
|
-
|
77
|
-
mainFrame.setSize(500, 300); //ウィンドウのサイズ
|
78
|
-
|
79
|
-
mainFrame.setLocationRelativeTo(null); //ウィンドウを画面の中央に表示
|
80
|
-
|
81
|
-
contentPane = mainFrame.getContentPane(); //要素、成分 メインフレームのパネルを取得
|
82
|
-
|
83
|
-
|
84
76
|
|
85
77
|
|
86
78
|
|
@@ -90,15 +82,9 @@
|
|
90
82
|
|
91
83
|
|
92
84
|
|
93
|
-
dirButton = new JButton("Dir");
|
85
|
+
dirButton = new JButton("Dir"); dirButton.setBounds(20, 0, 80, 30);
|
94
|
-
|
95
|
-
|
86
|
+
|
96
|
-
|
97
|
-
contentPane.add(dirButton); //コンパネにボタンを追加
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
addButton = new JButton("Capture");
|
87
|
+
contentPane.add(dirButton); addButton = new JButton("Capture");
|
102
88
|
|
103
89
|
addButton.setBounds(400, 0, 90, 60);
|
104
90
|
|
@@ -110,11 +96,13 @@
|
|
110
96
|
|
111
97
|
|
112
98
|
|
99
|
+
|
100
|
+
|
101
|
+
|
102
|
+
|
113
103
|
JMenuBar menubar = new JMenuBar();
|
114
104
|
|
115
|
-
JMenu menu1 = new JMenu("設定");
|
105
|
+
JMenu menu1 = new JMenu("設定"); JMenu menu2 = new JMenu("ヘルプ");
|
116
|
-
|
117
|
-
JMenu menu2 = new JMenu("ヘルプ");
|
118
106
|
|
119
107
|
JMenuItem menuitem1 = new JMenuItem("設定");
|
120
108
|
|
@@ -128,338 +116,314 @@
|
|
128
116
|
|
129
117
|
|
130
118
|
|
131
|
-
mainFrame.getRootPane().setJMenuBar(menubar);
|
119
|
+
mainFrame.getRootPane().setJMenuBar(menubar);
|
132
|
-
|
133
|
-
|
134
120
|
|
135
121
|
folderlabel = new JLabel();
|
136
122
|
|
137
|
-
textField = new JTextField();
|
123
|
+
textField = new JTextField();
|
124
|
+
|
125
|
+
//「追加」ボタンとアクション・リスナーの関連付け
|
126
|
+
|
127
|
+
dirButton.addActionListener(this);
|
128
|
+
|
129
|
+
dirButton.setActionCommand("Dir"); addButton.addActionListener(this);
|
130
|
+
|
131
|
+
addButton.setActionCommand("Capture")
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
itemPanel = new JPanel(); itemPanel.setBounds(0, 0, 500, 100);
|
140
|
+
|
141
|
+
contentPane.add(itemPanel);
|
142
|
+
|
143
|
+
textPanel = new JPanel(); textPanel.setLayout(null);
|
144
|
+
|
145
|
+
contentPane.add(textPanel);
|
146
|
+
|
147
|
+
textPanel.setBounds(0,80, 500, 100);
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
buttonPanel = new JPanel();
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
buttonPanel.setLayout(null);
|
156
|
+
|
157
|
+
contentPane.add(buttonPanel);
|
158
|
+
|
159
|
+
buttonPanel.setBounds(0,180,500,200);
|
160
|
+
|
161
|
+
;
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
itemboxtest1 = new ItemBox();
|
168
|
+
|
169
|
+
itemPanel.add(itemboxtest1);
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
itemboxtest2 = new ItemBox();
|
176
|
+
|
177
|
+
itemPanel.add(itemboxtest2);
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
itemboxtest3 = new ItemBox();
|
182
|
+
|
183
|
+
itemPanel.add(itemboxtest3);
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
itemboxtest4 = new ItemBox();
|
188
|
+
|
189
|
+
itemPanel.add(itemboxtest4);
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
textPanel.add(folderlabel);
|
196
|
+
|
197
|
+
folderlabel.setBounds(0, 30, 200, 30);
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
textPanel.add(textField);
|
202
|
+
|
203
|
+
textField.setBounds(320, 30, 150, 30);
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
buttonPanel.add(dirButton);
|
208
|
+
|
209
|
+
buttonPanel.add(addButton);
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
|
138
218
|
|
139
219
|
|
140
220
|
|
221
|
+
folderpath = "C:\\tmp";
|
222
|
+
|
223
|
+
folderlabel.setText(folderpath);
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
textField.setText("UT_CNT_%d-%d-%d-%d"); mainFrame.setVisible(true);
|
228
|
+
|
229
|
+
screenShot = new ScreenShot();
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
}
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
public void actionPerformed(ActionEvent event){
|
244
|
+
|
245
|
+
String cmd = event.getActionCommand();
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
if(cmd.equals("Capture")){
|
250
|
+
|
251
|
+
beforeProcess();
|
252
|
+
|
253
|
+
int x = mainFrame.getX();
|
254
|
+
|
255
|
+
int y = mainFrame.getY();
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
try{
|
266
|
+
|
267
|
+
File filepath = FilePathCreate();
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
mainFrame.setLocation(-1000,-1000);
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
screenShot.screenCapture(filepath, endPoint, endPoint);
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
mainFrame.setLocation(x, y);
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
new Thumbnail(filepath);
|
286
|
+
|
287
|
+
|
288
|
+
|
289
|
+
} catch (AWTException e){
|
290
|
+
|
291
|
+
|
292
|
+
|
293
|
+
e.printStackTrace();
|
294
|
+
|
295
|
+
} catch (IOException e){
|
296
|
+
|
297
|
+
e.printStackTrace();
|
298
|
+
|
299
|
+
}
|
300
|
+
|
301
|
+
|
302
|
+
|
303
|
+
|
304
|
+
|
305
|
+
}
|
306
|
+
|
307
|
+
|
308
|
+
|
309
|
+
|
310
|
+
|
311
|
+
else if(cmd.equals("Dir")) {
|
312
|
+
|
313
|
+
|
314
|
+
|
315
|
+
|
316
|
+
|
141
317
|
|
142
318
|
|
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
|
-
i
|
218
|
-
|
219
|
-
i
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
it
|
224
|
-
|
225
|
-
it
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
text
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
// フォルダパス初期値
|
254
|
-
|
255
|
-
folderpath = "C:\\tmp";
|
256
|
-
|
257
|
-
// folderlabel,textFieldを初期値設定
|
258
|
-
|
259
|
-
folderlabel.setText(folderpath);
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
textField.setText("UT_FIL_%d-%d-%d-%d"); //初期表示フォルダパス
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
mainFrame.setVisible(true);
|
270
|
-
|
271
|
-
screenShot = new ScreenShot();
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
}
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
// 利用者の操作に応じた処理を実装
|
282
|
-
|
283
|
-
public void actionPerformed(ActionEvent event){
|
284
|
-
|
285
|
-
// コマンド文字列を取得
|
286
|
-
|
287
|
-
String cmd = event.getActionCommand();
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
if(cmd.equals("Capture")){
|
292
|
-
|
293
|
-
int x = mainFrame.getX();
|
294
|
-
|
295
|
-
int y = mainFrame.getY();
|
296
|
-
|
297
|
-
// 画面キャプチャー
|
298
|
-
|
299
|
-
try{
|
300
|
-
|
301
|
-
File filepath = FilePathCreate();
|
302
|
-
|
303
|
-
// 自分を消す(見えない位置に移動)
|
304
|
-
|
305
|
-
mainFrame.setLocation(-1000,-1000);
|
306
|
-
|
307
|
-
// 画面キャプチャ
|
308
|
-
|
309
|
-
screenShot.screenCapture(filepath);
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
// 自分を表示(元の位置に移動)
|
314
|
-
|
315
|
-
mainFrame.setLocation(x, y);
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
//new Thumbnail(filepath); //サムネイルの表示
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
} catch (AWTException e){
|
326
|
-
|
327
|
-
// TODO 自動生成された catch ブロック
|
328
|
-
|
329
|
-
e.printStackTrace();
|
330
|
-
|
331
|
-
} catch (IOException e){
|
332
|
-
|
333
|
-
// TODO 自動生成された catch ブロック
|
334
|
-
|
335
|
-
e.printStackTrace();
|
319
|
+
|
320
|
+
|
321
|
+
|
322
|
+
|
323
|
+
JFileChooser filechooser = new JFileChooser(folderpath);
|
324
|
+
|
325
|
+
filechooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
326
|
+
|
327
|
+
|
328
|
+
|
329
|
+
int selected = filechooser.showSaveDialog(this.contentPane);
|
330
|
+
|
331
|
+
if (selected == JFileChooser.APPROVE_OPTION){
|
332
|
+
|
333
|
+
File file = filechooser.getSelectedFile();
|
334
|
+
|
335
|
+
folderpath = file.getAbsolutePath();
|
336
|
+
|
337
|
+
folderlabel.setText(folderpath);
|
338
|
+
|
339
|
+
|
340
|
+
|
341
|
+
|
342
|
+
|
343
|
+
}
|
344
|
+
|
345
|
+
}
|
346
|
+
|
347
|
+
|
348
|
+
|
349
|
+
|
350
|
+
|
351
|
+
}
|
352
|
+
|
353
|
+
|
354
|
+
|
355
|
+
|
356
|
+
|
357
|
+
public File FilePathCreate() {
|
358
|
+
|
359
|
+
String filename = FileNameCreate();
|
360
|
+
|
361
|
+
String name = filename;
|
362
|
+
|
363
|
+
int m = 1;
|
364
|
+
|
365
|
+
do {
|
366
|
+
|
367
|
+
File f = new File(folderpath, name + ".jpg");
|
368
|
+
|
369
|
+
if (!f.exists()) {
|
370
|
+
|
371
|
+
return f;
|
372
|
+
|
373
|
+
}
|
374
|
+
|
375
|
+
++m;
|
376
|
+
|
377
|
+
name = filename + "(" + m + ")" ;
|
378
|
+
|
379
|
+
} while (m < 100); // 無限ループ防止
|
380
|
+
|
381
|
+
throw new IllegalStateException("パス生成失敗");
|
382
|
+
|
383
|
+
|
384
|
+
|
385
|
+
}
|
386
|
+
|
387
|
+
|
388
|
+
|
389
|
+
|
390
|
+
|
391
|
+
public String FileNameCreate() {
|
392
|
+
|
393
|
+
String filename;
|
394
|
+
|
395
|
+
String[] itemNumbers = new String[4];
|
396
|
+
|
397
|
+
filename = textField.getText();
|
398
|
+
|
399
|
+
int i=0;
|
400
|
+
|
401
|
+
int found = 0;
|
402
|
+
|
403
|
+
|
404
|
+
|
405
|
+
itemNumbers[0] = itemboxtest1.getText();
|
406
|
+
|
407
|
+
itemNumbers[1] = itemboxtest2.getText();
|
408
|
+
|
409
|
+
itemNumbers[2] = itemboxtest3.getText();
|
410
|
+
|
411
|
+
itemNumbers[3] = itemboxtest4.getText();
|
412
|
+
|
413
|
+
|
414
|
+
|
415
|
+
for(i=0; i<4; i++){
|
416
|
+
|
417
|
+
found = filename.indexOf("%d",found);
|
418
|
+
|
419
|
+
if( found != 0 ){
|
420
|
+
|
421
|
+
filename = filename.replaceFirst("%d",itemNumbers[i]);
|
336
422
|
|
337
423
|
}
|
338
424
|
|
339
425
|
}
|
340
426
|
|
341
|
-
else if(cmd.equals("Dir")) {
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
JFileChooser filechooser = new JFileChooser(folderpath); //上二行と相互関係
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
filechooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
int selected = filechooser.showSaveDialog(this.contentPane);
|
356
|
-
|
357
|
-
if (selected == JFileChooser.APPROVE_OPTION){
|
358
|
-
|
359
|
-
File file = filechooser.getSelectedFile();
|
360
|
-
|
361
|
-
folderpath = file.getAbsolutePath();
|
362
|
-
|
363
|
-
folderlabel.setText(folderpath);
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
}
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
else if(cmd.equals("settingwindow")){
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
settingwindow = new SettingWindow();
|
380
|
-
|
381
|
-
}
|
382
|
-
|
383
|
-
}
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
}
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
public File FilePathCreate() {
|
396
|
-
|
397
|
-
String filename = FileNameCreate();
|
398
|
-
|
399
|
-
String name = filename;
|
400
|
-
|
401
|
-
int m = 1;
|
402
|
-
|
403
|
-
do {
|
404
|
-
|
405
|
-
File f = new File(folderpath, name + ".jpg");
|
406
|
-
|
407
|
-
if (!f.exists()) {
|
408
|
-
|
409
|
-
return f;
|
410
|
-
|
411
|
-
}
|
412
|
-
|
413
|
-
++m;
|
414
|
-
|
415
|
-
name = filename + "(" + m + ")" ;
|
416
|
-
|
417
|
-
} while (m < 100); // 無限ループ防止
|
418
|
-
|
419
|
-
throw new IllegalStateException("パス生成失敗");
|
420
|
-
|
421
|
-
}
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
// 数値リストからファイル名を生成
|
426
|
-
|
427
|
-
public String FileNameCreate() {
|
428
|
-
|
429
|
-
String filename;
|
430
|
-
|
431
|
-
String[] itemNumbers = new String[4];
|
432
|
-
|
433
|
-
filename = textField.getText();
|
434
|
-
|
435
|
-
int i=0;
|
436
|
-
|
437
|
-
int found = 0;
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
itemNumbers[0] = itemboxtest1.getText();
|
442
|
-
|
443
|
-
itemNumbers[1] = itemboxtest2.getText();
|
444
|
-
|
445
|
-
itemNumbers[2] = itemboxtest3.getText();
|
446
|
-
|
447
|
-
itemNumbers[3] = itemboxtest4.getText();
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
for(i=0; i<4; i++){
|
452
|
-
|
453
|
-
found = filename.indexOf("%d",found);
|
454
|
-
|
455
|
-
if( found != 0 ){
|
456
|
-
|
457
|
-
filename = filename.replaceFirst("%d",itemNumbers[i]);
|
458
|
-
|
459
|
-
}
|
460
|
-
|
461
|
-
}
|
462
|
-
|
463
427
|
return filename;
|
464
428
|
|
465
429
|
}
|
@@ -468,17 +432,11 @@
|
|
468
432
|
|
469
433
|
|
470
434
|
|
471
|
-
public void windowDeactivated(WindowEvent we) {
|
435
|
+
public void windowDeactivated(WindowEvent we) { System.out.println("windowClosing");
|
472
|
-
|
473
|
-
|
436
|
+
|
474
|
-
|
475
|
-
|
476
|
-
|
437
|
+
|
438
|
+
|
477
|
-
}
|
439
|
+
}
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
// アプリケーションの起動
|
482
440
|
|
483
441
|
public static void main(String[] args) {
|
484
442
|
|
@@ -486,226 +444,252 @@
|
|
486
444
|
|
487
445
|
}
|
488
446
|
|
447
|
+
|
448
|
+
|
449
|
+
@Override
|
450
|
+
|
451
|
+
public void mouseClicked(MouseEvent e) {
|
452
|
+
|
453
|
+
}
|
454
|
+
|
455
|
+
|
456
|
+
|
457
|
+
|
458
|
+
|
459
|
+
|
460
|
+
|
461
|
+
|
462
|
+
|
463
|
+
@Override
|
464
|
+
|
465
|
+
public void mousePressed(MouseEvent e) {
|
466
|
+
|
467
|
+
startPoint = e.getPoint();
|
468
|
+
|
469
|
+
|
470
|
+
|
471
|
+
}
|
472
|
+
|
473
|
+
|
474
|
+
|
475
|
+
|
476
|
+
|
477
|
+
|
478
|
+
|
479
|
+
|
480
|
+
|
481
|
+
@Override
|
482
|
+
|
483
|
+
public void mouseReleased(MouseEvent e) { /
|
484
|
+
|
485
|
+
endPoint = e.getPoint();
|
486
|
+
|
487
|
+
afterProcess();
|
488
|
+
|
489
|
+
|
490
|
+
|
491
|
+
}
|
492
|
+
|
493
|
+
|
494
|
+
|
495
|
+
|
496
|
+
|
497
|
+
|
498
|
+
|
499
|
+
|
500
|
+
|
501
|
+
@Override
|
502
|
+
|
503
|
+
public void mouseEntered(MouseEvent e) {
|
504
|
+
|
505
|
+
|
506
|
+
|
507
|
+
}
|
508
|
+
|
509
|
+
|
510
|
+
|
511
|
+
|
512
|
+
|
513
|
+
|
514
|
+
|
515
|
+
|
516
|
+
|
517
|
+
@Override
|
518
|
+
|
519
|
+
public void mouseExited(MouseEvent e) {
|
520
|
+
|
521
|
+
|
522
|
+
|
523
|
+
|
524
|
+
|
525
|
+
}
|
526
|
+
|
527
|
+
public void beforeProcess() {
|
528
|
+
|
529
|
+
|
530
|
+
|
531
|
+
x = mainFrame.getX();
|
532
|
+
|
533
|
+
y = mainFrame.getY();
|
534
|
+
|
535
|
+
mainFrame.setLocation(-1000,-1000);
|
536
|
+
|
537
|
+
|
538
|
+
|
539
|
+
|
540
|
+
|
541
|
+
JFrame.setDefaultLookAndFeelDecorated(false);
|
542
|
+
|
543
|
+
mainFrame2 = new JFrame();
|
544
|
+
|
545
|
+
mainFrame2.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
|
546
|
+
|
547
|
+
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
|
548
|
+
|
549
|
+
mainFrame2.setSize(screenSize.width, screenSize.height);
|
550
|
+
|
551
|
+
JPanel p = new JPanel();
|
552
|
+
|
553
|
+
p.setBackground(new Color(.5f,.5f,.5f,.5f));
|
554
|
+
|
555
|
+
mainFrame2.getContentPane().add(p);
|
556
|
+
|
557
|
+
|
558
|
+
|
559
|
+
mainFrame2.setLocationRelativeTo(null);
|
560
|
+
|
561
|
+
mainFrame2.setUndecorated(true);
|
562
|
+
|
563
|
+
|
564
|
+
|
565
|
+
com.sun.awt.AWTUtilities.setWindowOpaque(mainFrame2, false); //半透明化
|
566
|
+
|
567
|
+
mainFrame2.addMouseListener(this);
|
568
|
+
|
569
|
+
mainFrame2.addMouseMotionListener(this);
|
570
|
+
|
571
|
+
mainFrame2.setVisible(true);
|
572
|
+
|
573
|
+
|
574
|
+
|
575
|
+
}
|
576
|
+
|
577
|
+
|
578
|
+
|
579
|
+
public void afterProcess() {
|
580
|
+
|
581
|
+
mainFrame2.dispose();
|
582
|
+
|
583
|
+
File filepath = FilePathCreate();
|
584
|
+
|
585
|
+
try {
|
586
|
+
|
587
|
+
screenShot.screenCapture(filepath,startPoint,endPoint);
|
588
|
+
|
589
|
+
} catch (AWTException e1) {
|
590
|
+
|
591
|
+
// TODO 自動生成された catch ブロック
|
592
|
+
|
593
|
+
e1.printStackTrace();
|
594
|
+
|
595
|
+
} catch (IOException e1) {
|
596
|
+
|
597
|
+
// TODO 自動生成された catch ブロック
|
598
|
+
|
599
|
+
e1.printStackTrace();
|
600
|
+
|
601
|
+
}
|
602
|
+
|
603
|
+
// 自分を表示(元の位置に移動)
|
604
|
+
|
605
|
+
mainFrame.setLocation(x, y);
|
606
|
+
|
607
|
+
}
|
608
|
+
|
609
|
+
|
610
|
+
|
611
|
+
|
612
|
+
|
613
|
+
|
614
|
+
|
615
|
+
|
616
|
+
|
617
|
+
@Override
|
618
|
+
|
619
|
+
public void mouseDragged(MouseEvent e) {
|
620
|
+
|
621
|
+
|
622
|
+
|
489
623
|
}
|
490
624
|
|
625
|
+
|
626
|
+
|
627
|
+
|
628
|
+
|
629
|
+
|
630
|
+
|
631
|
+
|
632
|
+
|
633
|
+
@Override
|
634
|
+
|
635
|
+
public void mouseMoved(MouseEvent e) {
|
636
|
+
|
637
|
+
|
638
|
+
|
639
|
+
}
|
640
|
+
|
641
|
+
|
642
|
+
|
643
|
+
}
|
644
|
+
|
645
|
+
|
646
|
+
|
647
|
+
|
648
|
+
|
649
|
+
|
650
|
+
|
651
|
+
|
652
|
+
|
653
|
+
|
654
|
+
|
491
655
|
```
|
492
656
|
|
493
657
|
|
494
658
|
|
495
659
|
|
496
660
|
|
497
|
-
|
661
|
+
ScreenShot
|
498
662
|
|
499
663
|
```lang-java
|
500
664
|
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
p
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
GridBagConstraints gbc = new GridBagConstraints();
|
528
|
-
|
529
|
-
gbc.fill = GridBagConstraints.BOTH;
|
530
|
-
|
531
|
-
gbc.gridx = x;
|
532
|
-
|
533
|
-
gbc.gridy = y;
|
534
|
-
|
535
|
-
gbc.gridwidth = w;
|
536
|
-
|
537
|
-
gbc.gridheight = h;
|
538
|
-
|
539
|
-
gbl.setConstraints((Component) itemobject, gbc);
|
540
|
-
|
541
|
-
add((Component) itemobject);
|
542
|
-
|
543
|
-
}
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
public ItemBox(){
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
//setLayout(null);
|
552
|
-
|
553
|
-
//setBackground(Color.blue);
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
itemField = new JTextField("0");
|
558
|
-
|
559
|
-
itemField.setPreferredSize(new Dimension(20, 10)); //アイテムフィールドの大きさ指定
|
560
|
-
|
561
|
-
itemField.setFocusable(false); //入力制限
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
upButton = new JButton("↑"); //upButtonオブジェクトを作成し、↑を代入する。
|
566
|
-
|
567
|
-
downButton = new JButton("↓"); //downButtonオブジェクトを作成し、↓を代入する。
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
upButton.setActionCommand("upButton");
|
576
|
-
|
577
|
-
upButton.addActionListener(this); //アクションイベントを受け取れるようになる。
|
578
|
-
|
579
|
-
downButton.setActionCommand("downButton");
|
580
|
-
|
581
|
-
downButton.addActionListener(this);
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
setLayout(gbl);
|
586
|
-
|
587
|
-
addButton(itemField, 0, 0, 1, 2); // (0, 0) 幅=1, 高さ=3
|
588
|
-
|
589
|
-
addButton(upButton, 1, 0, 1, 1); // (1, 0) 幅=1, 高さ=1
|
590
|
-
|
591
|
-
addButton(downButton, 1, 1, 1, 1); // (1, 1) 幅=1, 高さ=1
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
}
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
public String getText(){
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
return itemField.getText();
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
}
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
//操作に応じた処理の実装
|
626
|
-
|
627
|
-
public void actionPerformed(ActionEvent event){ //イベントが発生するとここが処理される
|
628
|
-
|
629
|
-
//ユーザーの操作e対象の判断 //このクラスでのアクションリスナー
|
630
|
-
|
631
|
-
String cmd = event.getActionCommand();
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
if(cmd.equals("upButton")) {
|
636
|
-
|
637
|
-
int i = Integer.parseInt(itemField.getText());
|
638
|
-
|
639
|
-
i++;
|
640
|
-
|
641
|
-
if(i>99)i=0;
|
642
|
-
|
643
|
-
//itemField.setText(String.format("%1$02d",i)); //0埋め
|
644
|
-
|
645
|
-
itemField.setText(String.valueOf(i));
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
}
|
650
|
-
|
651
|
-
else if(cmd.equals("downButton")){
|
652
|
-
|
653
|
-
int i = Integer.parseInt(itemField.getText());
|
654
|
-
|
655
|
-
i--;
|
656
|
-
|
657
|
-
if(i<0)i=99;
|
658
|
-
|
659
|
-
//itemField.setText(String.format("%1$02d",i)); //0埋め
|
660
|
-
|
661
|
-
itemField.setText(String.valueOf(i));
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
}
|
666
|
-
|
667
|
-
}
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
665
|
+
|
666
|
+
|
667
|
+
public class ScreenShot {
|
668
|
+
|
669
|
+
|
670
|
+
|
671
|
+
public void screenCapture(File filepath, Point startPoint, Point endPoint) throws AWTException, IOException {
|
672
|
+
|
673
|
+
Robot robot = new Robot();
|
674
|
+
|
675
|
+
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
|
676
|
+
|
677
|
+
BufferedImage image = robot.createScreenCapture(
|
678
|
+
|
679
|
+
new Rectangle( (int)startPoint.getX(),
|
680
|
+
|
681
|
+
(int)startPoint.getY(),
|
682
|
+
|
683
|
+
(int )(endPoint.getX() - startPoint.getX()),
|
684
|
+
|
685
|
+
(int)(endPoint.getY() - startPoint.getY())));
|
686
|
+
|
687
|
+
ImageIO.write(image, "PNG", filepath); //PNGファイルの保存
|
688
|
+
|
689
|
+
}
|
674
690
|
|
675
691
|
}
|
676
692
|
|
677
693
|
|
678
694
|
|
679
|
-
|
680
|
-
|
681
695
|
```
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
ScreenShot
|
686
|
-
|
687
|
-
```lang-java
|
688
|
-
|
689
|
-
public class ScreenShot {
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
public void screenCapture(File filepath) throws AWTException, IOException {
|
694
|
-
|
695
|
-
Robot robot = new Robot();
|
696
|
-
|
697
|
-
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
|
698
|
-
|
699
|
-
BufferedImage image = robot.createScreenCapture(
|
700
|
-
|
701
|
-
new Rectangle(0, 0, screenSize.width, screenSize.height));
|
702
|
-
|
703
|
-
ImageIO.write(image, "PNG", filepath); //PNGファイルの保存
|
704
|
-
|
705
|
-
}
|
706
|
-
|
707
|
-
}
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
```
|
1
コードの変更
test
CHANGED
File without changes
|
test
CHANGED
File without changes
|