質問編集履歴
3
一部ソース修正しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -224,90 +224,270 @@
|
|
224
224
|
|
225
225
|
```
|
226
226
|
|
227
|
+
|
228
|
+
|
227
229
|
```ここに言語を入力
|
228
230
|
|
229
231
|
package boundary;
|
230
232
|
|
231
233
|
|
232
234
|
|
235
|
+
import javax.swing.JFrame;
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
public class Main extends JFrame{
|
240
|
+
|
241
|
+
public static void main(String[] args) {
|
242
|
+
|
243
|
+
Main frame = new Main();
|
244
|
+
|
245
|
+
frame.setTitle("画面遷移テスト");
|
246
|
+
|
247
|
+
frame.setSize(2200, 1400);
|
248
|
+
|
249
|
+
frame.setLocationRelativeTo(null);
|
250
|
+
|
251
|
+
ChatBoundary chatBoundary = new ChatBoundary();
|
252
|
+
|
253
|
+
frame.getContentPane().add(chatBoundary);
|
254
|
+
|
255
|
+
frame.setVisible(true);
|
256
|
+
|
257
|
+
}
|
258
|
+
|
259
|
+
}
|
260
|
+
|
261
|
+
```
|
262
|
+
|
263
|
+
```ここに言語を入力
|
264
|
+
|
265
|
+
package boundary;
|
266
|
+
|
267
|
+
|
268
|
+
|
233
269
|
import java.awt.BorderLayout;
|
234
270
|
|
235
271
|
import java.awt.Color;
|
236
272
|
|
237
273
|
import java.awt.Dimension;
|
238
274
|
|
239
|
-
|
275
|
+
import java.awt.FlowLayout;
|
276
|
+
|
240
|
-
|
277
|
+
import java.awt.event.AdjustmentEvent;
|
278
|
+
|
279
|
+
import java.awt.event.AdjustmentListener;
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
import javax.swing.BorderFactory;
|
284
|
+
|
285
|
+
import javax.swing.Box;
|
286
|
+
|
241
|
-
import javax.swing.J
|
287
|
+
import javax.swing.JButton;
|
242
288
|
|
243
289
|
import javax.swing.JPanel;
|
244
290
|
|
245
291
|
import javax.swing.JScrollPane;
|
246
292
|
|
247
|
-
import javax.swing.J
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
public class ChatBoundary extends J
|
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
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
293
|
+
import javax.swing.JTextField;
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
public class ChatBoundary extends JPanel{
|
298
|
+
|
299
|
+
private static final FlowLayout right = new FlowLayout(FlowLayout.RIGHT);
|
300
|
+
|
301
|
+
private static final FlowLayout left = new FlowLayout(FlowLayout.LEFT);
|
302
|
+
|
303
|
+
|
304
|
+
|
305
|
+
|
306
|
+
|
307
|
+
public ChatBoundary(){
|
308
|
+
|
309
|
+
setLayout(new BorderLayout());
|
310
|
+
|
311
|
+
setPreferredSize(new Dimension(2200, 1200));
|
312
|
+
|
313
|
+
setBackground(Color.black);
|
314
|
+
|
315
|
+
// メッセージが追加されていく本体
|
316
|
+
|
317
|
+
Box inner = Box.createVerticalBox();
|
318
|
+
|
319
|
+
inner.setBorder(BorderFactory.createLineBorder(Color.RED, 5));
|
320
|
+
|
321
|
+
|
322
|
+
|
323
|
+
//JPanel outer = new JPanel(new BorderLayout());
|
324
|
+
|
325
|
+
//outer.add(inner, BorderLayout.NORTH);
|
326
|
+
|
327
|
+
//outer.setBorder(BorderFactory.createLineBorder(Color.GREEN, 5));
|
328
|
+
|
329
|
+
|
330
|
+
|
331
|
+
add(inner, BorderLayout.NORTH);
|
332
|
+
|
333
|
+
setBorder(BorderFactory.createLineBorder(Color.GREEN, 5));
|
334
|
+
|
335
|
+
|
336
|
+
|
337
|
+
//JScrollPane scrollPane = new JScrollPane(outer);
|
338
|
+
|
339
|
+
|
340
|
+
|
341
|
+
JScrollPane scrollPane = new JScrollPane(this);
|
342
|
+
|
343
|
+
|
344
|
+
|
345
|
+
|
346
|
+
|
347
|
+
//add(scrollPane, BorderLayout.CENTER);
|
348
|
+
|
349
|
+
scrollPane.setBorder(BorderFactory.createLineBorder(Color.BLUE, 5));
|
350
|
+
|
351
|
+
|
352
|
+
|
353
|
+
scrollPane.getVerticalScrollBar().addAdjustmentListener(new AdjustmentListener() {
|
354
|
+
|
355
|
+
private int max = scrollPane.getVerticalScrollBar().getMaximum();
|
356
|
+
|
357
|
+
|
358
|
+
|
359
|
+
public void adjustmentValueChanged(AdjustmentEvent e) {
|
360
|
+
|
361
|
+
if (max - e.getAdjustable().getMaximum() == 0) return;
|
362
|
+
|
363
|
+
|
364
|
+
|
365
|
+
e.getAdjustable().setValue(e.getAdjustable().getMaximum());
|
366
|
+
|
367
|
+
max = scrollPane.getVerticalScrollBar().getMaximum();
|
368
|
+
|
369
|
+
}
|
370
|
+
|
371
|
+
});
|
372
|
+
|
373
|
+
|
374
|
+
|
375
|
+
JPanel controls = new JPanel(); // 操作エリア
|
376
|
+
|
377
|
+
add(controls, BorderLayout.SOUTH);
|
378
|
+
|
379
|
+
|
380
|
+
|
381
|
+
JTextField textField = new JTextField("メッセージ", 20);
|
382
|
+
|
383
|
+
controls.add(textField);
|
384
|
+
|
385
|
+
textField.selectAll(); // 全選択
|
386
|
+
|
387
|
+
|
388
|
+
|
389
|
+
JButton button = new JButton("送信");
|
390
|
+
|
391
|
+
controls.add(button);
|
392
|
+
|
393
|
+
button.addActionListener(e -> {
|
394
|
+
|
395
|
+
inner.add(new Message("naruto.jpg", right));
|
396
|
+
|
397
|
+
inner.add(Box.createVerticalStrut(10)); // 隙間
|
398
|
+
|
399
|
+
inner.add(new Message("naruto.jpg", left));
|
400
|
+
|
401
|
+
inner.add(Box.createVerticalStrut(10)); // 隙間
|
402
|
+
|
403
|
+
|
404
|
+
|
405
|
+
scrollPane.revalidate(); // 再描画
|
406
|
+
|
407
|
+
|
408
|
+
|
409
|
+
textField.selectAll(); // 全選択
|
410
|
+
|
411
|
+
textField.requestFocus(); // フォーカス
|
412
|
+
|
413
|
+
});
|
414
|
+
|
415
|
+
|
416
|
+
|
417
|
+
textField.addActionListener(e -> button.doClick());
|
418
|
+
|
419
|
+
|
420
|
+
|
421
|
+
|
422
|
+
|
423
|
+
}
|
424
|
+
|
425
|
+
}
|
426
|
+
|
427
|
+
|
428
|
+
|
429
|
+
```
|
430
|
+
|
431
|
+
```ここに言語を入力
|
432
|
+
|
433
|
+
package boundary;
|
434
|
+
|
435
|
+
|
436
|
+
|
437
|
+
import java.util.ArrayList;
|
438
|
+
|
439
|
+
|
440
|
+
|
441
|
+
import javax.swing.ImageIcon;
|
442
|
+
|
443
|
+
import javax.swing.JButton;
|
444
|
+
|
445
|
+
|
446
|
+
|
447
|
+
//メッセージのエモーションにかかわるボタンの処理クラス
|
448
|
+
|
449
|
+
class EmotionButton extends JButton {
|
450
|
+
|
451
|
+
private ArrayList<String> arrL = new ArrayList<String>();
|
452
|
+
|
453
|
+
|
454
|
+
|
455
|
+
public EmotionButton(ImageIcon icon) {
|
456
|
+
|
457
|
+
super("0", icon);
|
458
|
+
|
459
|
+
}
|
460
|
+
|
461
|
+
|
462
|
+
|
463
|
+
public int editBtn(String userName) {
|
464
|
+
|
465
|
+
if(arrL.contains(userName)) {
|
466
|
+
|
467
|
+
arrL.remove(arrL.indexOf(userName));
|
468
|
+
|
469
|
+
return arrL.size();
|
308
470
|
|
309
471
|
}
|
310
472
|
|
473
|
+
else {
|
474
|
+
|
475
|
+
arrL.add(userName);
|
476
|
+
|
477
|
+
return arrL.size();
|
478
|
+
|
479
|
+
}
|
480
|
+
|
481
|
+
}
|
482
|
+
|
483
|
+
|
484
|
+
|
485
|
+
public ArrayList<String> getUserName() {
|
486
|
+
|
487
|
+
return arrL;
|
488
|
+
|
489
|
+
}
|
490
|
+
|
311
491
|
|
312
492
|
|
313
493
|
}
|
@@ -316,276 +496,6 @@
|
|
316
496
|
|
317
497
|
```
|
318
498
|
|
319
|
-
```ここに言語を入力
|
320
|
-
|
321
|
-
package boundary;
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
import javax.swing.JFrame;
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
public class Main extends JFrame{
|
330
|
-
|
331
|
-
public static void main(String[] args) {
|
332
|
-
|
333
|
-
Main frame = new Main();
|
334
|
-
|
335
|
-
frame.setTitle("画面遷移テスト");
|
336
|
-
|
337
|
-
frame.setSize(2200, 1400);
|
338
|
-
|
339
|
-
frame.setLocationRelativeTo(null);
|
340
|
-
|
341
|
-
ChatBoundary chatBoundary = new ChatBoundary();
|
342
|
-
|
343
|
-
frame.getContentPane().add(chatBoundary);
|
344
|
-
|
345
|
-
frame.setVisible(true);
|
346
|
-
|
347
|
-
}
|
348
|
-
|
349
|
-
}
|
350
|
-
|
351
|
-
```
|
352
|
-
|
353
|
-
```ここに言語を入力
|
354
|
-
|
355
|
-
package boundary;
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
import java.awt.BorderLayout;
|
360
|
-
|
361
|
-
import java.awt.Color;
|
362
|
-
|
363
|
-
import java.awt.Dimension;
|
364
|
-
|
365
|
-
import java.awt.FlowLayout;
|
366
|
-
|
367
|
-
import java.awt.event.AdjustmentEvent;
|
368
|
-
|
369
|
-
import java.awt.event.AdjustmentListener;
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
import javax.swing.BorderFactory;
|
374
|
-
|
375
|
-
import javax.swing.Box;
|
376
|
-
|
377
|
-
import javax.swing.JButton;
|
378
|
-
|
379
|
-
import javax.swing.JPanel;
|
380
|
-
|
381
|
-
import javax.swing.JScrollPane;
|
382
|
-
|
383
|
-
import javax.swing.JTextField;
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
public class ChatBoundary extends JPanel{
|
388
|
-
|
389
|
-
private static final FlowLayout right = new FlowLayout(FlowLayout.RIGHT);
|
390
|
-
|
391
|
-
private static final FlowLayout left = new FlowLayout(FlowLayout.LEFT);
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
public ChatBoundary(){
|
398
|
-
|
399
|
-
setLayout(new BorderLayout());
|
400
|
-
|
401
|
-
setPreferredSize(new Dimension(2200, 1200));
|
402
|
-
|
403
|
-
setBackground(Color.black);
|
404
|
-
|
405
|
-
// メッセージが追加されていく本体
|
406
|
-
|
407
|
-
Box inner = Box.createVerticalBox();
|
408
|
-
|
409
|
-
inner.setBorder(BorderFactory.createLineBorder(Color.RED, 5));
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
//JPanel outer = new JPanel(new BorderLayout());
|
414
|
-
|
415
|
-
//outer.add(inner, BorderLayout.NORTH);
|
416
|
-
|
417
|
-
//outer.setBorder(BorderFactory.createLineBorder(Color.GREEN, 5));
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
add(inner, BorderLayout.NORTH);
|
422
|
-
|
423
|
-
setBorder(BorderFactory.createLineBorder(Color.GREEN, 5));
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
//JScrollPane scrollPane = new JScrollPane(outer);
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
JScrollPane scrollPane = new JScrollPane(this);
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
//add(scrollPane, BorderLayout.CENTER);
|
438
|
-
|
439
|
-
scrollPane.setBorder(BorderFactory.createLineBorder(Color.BLUE, 5));
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
scrollPane.getVerticalScrollBar().addAdjustmentListener(new AdjustmentListener() {
|
444
|
-
|
445
|
-
private int max = scrollPane.getVerticalScrollBar().getMaximum();
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
public void adjustmentValueChanged(AdjustmentEvent e) {
|
450
|
-
|
451
|
-
if (max - e.getAdjustable().getMaximum() == 0) return;
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
e.getAdjustable().setValue(e.getAdjustable().getMaximum());
|
456
|
-
|
457
|
-
max = scrollPane.getVerticalScrollBar().getMaximum();
|
458
|
-
|
459
|
-
}
|
460
|
-
|
461
|
-
});
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
JPanel controls = new JPanel(); // 操作エリア
|
466
|
-
|
467
|
-
add(controls, BorderLayout.SOUTH);
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
JTextField textField = new JTextField("メッセージ", 20);
|
472
|
-
|
473
|
-
controls.add(textField);
|
474
|
-
|
475
|
-
textField.selectAll(); // 全選択
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
JButton button = new JButton("送信");
|
480
|
-
|
481
|
-
controls.add(button);
|
482
|
-
|
483
|
-
button.addActionListener(e -> {
|
484
|
-
|
485
|
-
inner.add(new Message("naruto.jpg", right));
|
486
|
-
|
487
|
-
inner.add(Box.createVerticalStrut(10)); // 隙間
|
488
|
-
|
489
|
-
inner.add(new Message("naruto.jpg", left));
|
490
|
-
|
491
|
-
inner.add(Box.createVerticalStrut(10)); // 隙間
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
scrollPane.revalidate(); // 再描画
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
textField.selectAll(); // 全選択
|
500
|
-
|
501
|
-
textField.requestFocus(); // フォーカス
|
502
|
-
|
503
|
-
});
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
textField.addActionListener(e -> button.doClick());
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
}
|
514
|
-
|
515
|
-
}
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
```
|
520
|
-
|
521
|
-
```ここに言語を入力
|
522
|
-
|
523
|
-
package boundary;
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
import java.util.ArrayList;
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
import javax.swing.ImageIcon;
|
532
|
-
|
533
|
-
import javax.swing.JButton;
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
//メッセージのエモーションにかかわるボタンの処理クラス
|
538
|
-
|
539
|
-
class EmotionButton extends JButton {
|
540
|
-
|
541
|
-
private ArrayList<String> arrL = new ArrayList<String>();
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
public EmotionButton(ImageIcon icon) {
|
546
|
-
|
547
|
-
super("0", icon);
|
548
|
-
|
549
|
-
}
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
public int editBtn(String userName) {
|
554
|
-
|
555
|
-
if(arrL.contains(userName)) {
|
556
|
-
|
557
|
-
arrL.remove(arrL.indexOf(userName));
|
558
|
-
|
559
|
-
return arrL.size();
|
560
|
-
|
561
|
-
}
|
562
|
-
|
563
|
-
else {
|
564
|
-
|
565
|
-
arrL.add(userName);
|
566
|
-
|
567
|
-
return arrL.size();
|
568
|
-
|
569
|
-
}
|
570
|
-
|
571
|
-
}
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
public ArrayList<String> getUserName() {
|
576
|
-
|
577
|
-
return arrL;
|
578
|
-
|
579
|
-
}
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
}
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
```
|
588
|
-
|
589
499
|
|
590
500
|
|
591
501
|
|
2
回答いただいたものを参考にソースを書き直しました。また完成図を追加しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -26,9 +26,11 @@
|
|
26
26
|
|
27
27
|
### 発生している問題
|
28
28
|
|
29
|
-
|
29
|
+
現段階では送信ボタンを押すと,メッセージを出すようにしているのですが,その描画が反映されない状況です。
|
30
|
-
|
30
|
+
|
31
|
-
|
31
|
+
また,送信ボタン周りの操作クラスが再描画によってつぶれてしまい,適切な領域が割り当てられていなく,スクロールもない状態になってしまっています.
|
32
|
+
|
33
|
+
ChatBounddaryの継承をJPanelに変更したことで,add(scrollPane, BorderLayout.CENTER);を書く適切な位置がわからなくなってしまいました.
|
32
34
|
|
33
35
|
|
34
36
|
|
@@ -42,16 +44,26 @@
|
|
42
44
|
|
43
45
|
|
44
46
|
|
47
|
+
import java.awt.BorderLayout;
|
48
|
+
|
45
49
|
import java.awt.Color;
|
46
50
|
|
47
51
|
import java.awt.Dimension;
|
48
52
|
|
53
|
+
import java.awt.FlowLayout;
|
54
|
+
|
49
55
|
import java.awt.Graphics;
|
50
56
|
|
57
|
+
import java.awt.event.ActionEvent;
|
58
|
+
|
59
|
+
import java.awt.event.ActionListener;
|
60
|
+
|
51
61
|
import java.awt.event.MouseEvent;
|
52
62
|
|
53
63
|
import java.awt.event.MouseListener;
|
54
64
|
|
65
|
+
import java.util.ArrayList;
|
66
|
+
|
55
67
|
|
56
68
|
|
57
69
|
import javax.swing.ImageIcon;
|
@@ -64,95 +76,505 @@
|
|
64
76
|
|
65
77
|
|
66
78
|
|
67
|
-
public class Message extends JPanel implements MouseListener {
|
79
|
+
public class Message extends JPanel implements MouseListener, ActionListener {
|
68
|
-
|
80
|
+
|
69
|
-
private
|
81
|
+
private EmotionButton[] eb = new EmotionButton[4];
|
70
82
|
|
71
83
|
private ImageIcon[] icon = new ImageIcon[4];
|
72
84
|
|
73
|
-
private static final int WIDTH =
|
74
|
-
|
75
|
-
private static final int HEIGHT = 900;
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
85
|
+
//private static final int WIDTH = 900;
|
86
|
+
|
87
|
+
//private static final int HEIGHT = 900;
|
88
|
+
|
89
|
+
private JButton saveBtn;
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
public Message(String imageName,FlowLayout layout) {
|
96
|
+
|
97
|
+
setLayout(layout);
|
98
|
+
|
99
|
+
setBackground(Color.WHITE);
|
100
|
+
|
101
|
+
//setPreferredSize(new Dimension(WIDTH, HEIGHT));
|
102
|
+
|
103
|
+
//setBackground(Color.black);
|
104
|
+
|
105
|
+
ImageIcon image = new ImageIcon(imageName);
|
106
|
+
|
107
|
+
JLabel jl = new JLabel(image,JLabel.CENTER);
|
108
|
+
|
109
|
+
add(jl);
|
110
|
+
|
111
|
+
for (int i = 0; i < 4; i++) {
|
112
|
+
|
113
|
+
icon[i] = new ImageIcon("emotion" + i + ".png");
|
114
|
+
|
115
|
+
eb[i] = new EmotionButton(icon[i]);
|
116
|
+
|
117
|
+
eb[i].setPreferredSize(new Dimension(100, 100));
|
118
|
+
|
119
|
+
eb[i].addMouseListener(this);
|
120
|
+
|
121
|
+
add(eb[i]);
|
122
|
+
|
123
|
+
}
|
124
|
+
|
125
|
+
saveBtn = new JButton("保存");
|
126
|
+
|
127
|
+
saveBtn.addActionListener(this);
|
128
|
+
|
129
|
+
add(saveBtn, BorderLayout.EAST);
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
}
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
public void paintComponent(Graphics g) {
|
138
|
+
|
139
|
+
super.paintComponent(g);
|
140
|
+
|
141
|
+
}
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
public void actionPerformed(ActionEvent e) {
|
146
|
+
|
147
|
+
InformDialog.displayDialogText("保存します");
|
148
|
+
|
149
|
+
}
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
public void mouseClicked(MouseEvent e) {
|
154
|
+
|
155
|
+
EmotionButton eBtn = (EmotionButton) e.getSource();
|
156
|
+
|
157
|
+
switch (e.getButton()) {
|
158
|
+
|
159
|
+
case MouseEvent.BUTTON1:
|
160
|
+
|
161
|
+
eBtn.setText(String.valueOf(eBtn.editBtn("wataru")));
|
162
|
+
|
163
|
+
break;
|
164
|
+
|
165
|
+
case MouseEvent.BUTTON3:
|
166
|
+
|
167
|
+
ArrayList<String> arrUN = eBtn.getUserName();
|
168
|
+
|
169
|
+
for (int i = 0; i < arrUN.size(); i++) {
|
170
|
+
|
171
|
+
System.out.println(arrUN.get(i));
|
172
|
+
|
173
|
+
}
|
174
|
+
|
175
|
+
if (arrUN.size() != 0) {
|
176
|
+
|
177
|
+
InformDialog.displayDialogText(arrUN.get(0));
|
178
|
+
|
179
|
+
}
|
180
|
+
|
181
|
+
break;
|
182
|
+
|
183
|
+
}
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
}
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
public void mouseEntered(MouseEvent e) {
|
192
|
+
|
193
|
+
//InformDialog.displayDialogText("ボタンに触れましました。");
|
194
|
+
|
195
|
+
}
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
public void mouseExited(MouseEvent e) {
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
}
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
public void mousePressed(MouseEvent e) {
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
}
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
public void mouseReleased(MouseEvent e) {
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
}
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
}
|
224
|
+
|
225
|
+
```
|
226
|
+
|
227
|
+
```ここに言語を入力
|
228
|
+
|
229
|
+
package boundary;
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
import java.awt.BorderLayout;
|
234
|
+
|
235
|
+
import java.awt.Color;
|
236
|
+
|
237
|
+
import java.awt.Dimension;
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
import javax.swing.JFrame;
|
242
|
+
|
243
|
+
import javax.swing.JPanel;
|
244
|
+
|
245
|
+
import javax.swing.JScrollPane;
|
246
|
+
|
247
|
+
import javax.swing.JViewport;
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
public class ChatBoundary extends JFrame{
|
252
|
+
|
253
|
+
Message[] message = new Message[3];
|
254
|
+
|
255
|
+
//Message message = null;
|
256
|
+
|
257
|
+
public static void main(String[] args) {
|
258
|
+
|
259
|
+
ChatBoundary chatBoundary = new ChatBoundary("ChatBoundary");
|
260
|
+
|
261
|
+
chatBoundary.setSize(new Dimension(2000,1400));
|
262
|
+
|
263
|
+
//chatBoundary.setResizable(false);
|
264
|
+
|
265
|
+
chatBoundary.setVisible(true);
|
266
|
+
|
267
|
+
}
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
ChatBoundary(String title){
|
272
|
+
|
273
|
+
setTitle(title);
|
274
|
+
|
275
|
+
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
276
|
+
|
277
|
+
//Container contentPane = getContentPane();
|
278
|
+
|
279
|
+
message[0] = new Message("naruto.jpg");
|
280
|
+
|
281
|
+
message[1] = new Message("コナン.jpg");
|
282
|
+
|
283
|
+
JScrollPane scrollpane = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
|
284
|
+
|
285
|
+
scrollpane.setPreferredSize(new Dimension(1000,1200));
|
286
|
+
|
287
|
+
scrollpane.setViewportView(message[0]);
|
288
|
+
|
289
|
+
JViewport view = scrollpane.getViewport();
|
290
|
+
|
291
|
+
view.setView(message[1]);
|
292
|
+
|
293
|
+
view.setViewPosition(new Point(100,1000));
|
294
|
+
|
295
|
+
//送信欄の枠
|
296
|
+
|
297
|
+
JPanel jp = new JPanel();
|
298
|
+
|
299
|
+
jp.setBackground(Color.blue);
|
300
|
+
|
301
|
+
jp.setPreferredSize(new Dimension(100,130));
|
302
|
+
|
303
|
+
add(scrollpane, BorderLayout.NORTH);
|
304
|
+
|
305
|
+
add(jp, BorderLayout.SOUTH);
|
306
|
+
|
307
|
+
pack();//フレームに入れた部品の大きさなどを考慮してフレームの適切なサイズを計算
|
308
|
+
|
309
|
+
}
|
310
|
+
|
311
|
+
|
312
|
+
|
313
|
+
}
|
314
|
+
|
315
|
+
|
316
|
+
|
317
|
+
```
|
318
|
+
|
319
|
+
```ここに言語を入力
|
320
|
+
|
321
|
+
package boundary;
|
322
|
+
|
323
|
+
|
324
|
+
|
325
|
+
import javax.swing.JFrame;
|
326
|
+
|
327
|
+
|
328
|
+
|
329
|
+
public class Main extends JFrame{
|
330
|
+
|
331
|
+
public static void main(String[] args) {
|
332
|
+
|
333
|
+
Main frame = new Main();
|
334
|
+
|
335
|
+
frame.setTitle("画面遷移テスト");
|
336
|
+
|
337
|
+
frame.setSize(2200, 1400);
|
338
|
+
|
339
|
+
frame.setLocationRelativeTo(null);
|
340
|
+
|
341
|
+
ChatBoundary chatBoundary = new ChatBoundary();
|
342
|
+
|
343
|
+
frame.getContentPane().add(chatBoundary);
|
344
|
+
|
345
|
+
frame.setVisible(true);
|
346
|
+
|
347
|
+
}
|
348
|
+
|
349
|
+
}
|
350
|
+
|
351
|
+
```
|
352
|
+
|
353
|
+
```ここに言語を入力
|
354
|
+
|
355
|
+
package boundary;
|
356
|
+
|
357
|
+
|
358
|
+
|
359
|
+
import java.awt.BorderLayout;
|
360
|
+
|
361
|
+
import java.awt.Color;
|
362
|
+
|
363
|
+
import java.awt.Dimension;
|
364
|
+
|
365
|
+
import java.awt.FlowLayout;
|
366
|
+
|
367
|
+
import java.awt.event.AdjustmentEvent;
|
368
|
+
|
369
|
+
import java.awt.event.AdjustmentListener;
|
370
|
+
|
371
|
+
|
372
|
+
|
373
|
+
import javax.swing.BorderFactory;
|
374
|
+
|
375
|
+
import javax.swing.Box;
|
376
|
+
|
377
|
+
import javax.swing.JButton;
|
378
|
+
|
379
|
+
import javax.swing.JPanel;
|
380
|
+
|
381
|
+
import javax.swing.JScrollPane;
|
382
|
+
|
383
|
+
import javax.swing.JTextField;
|
384
|
+
|
385
|
+
|
386
|
+
|
387
|
+
public class ChatBoundary extends JPanel{
|
388
|
+
|
389
|
+
private static final FlowLayout right = new FlowLayout(FlowLayout.RIGHT);
|
390
|
+
|
391
|
+
private static final FlowLayout left = new FlowLayout(FlowLayout.LEFT);
|
392
|
+
|
393
|
+
|
394
|
+
|
395
|
+
|
396
|
+
|
397
|
+
public ChatBoundary(){
|
398
|
+
|
399
|
+
setLayout(new BorderLayout());
|
400
|
+
|
401
|
+
setPreferredSize(new Dimension(2200, 1200));
|
82
402
|
|
83
403
|
setBackground(Color.black);
|
84
404
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
405
|
+
// メッセージが追加されていく本体
|
406
|
+
|
407
|
+
Box inner = Box.createVerticalBox();
|
408
|
+
|
409
|
+
inner.setBorder(BorderFactory.createLineBorder(Color.RED, 5));
|
410
|
+
|
411
|
+
|
412
|
+
|
413
|
+
//JPanel outer = new JPanel(new BorderLayout());
|
414
|
+
|
415
|
+
//outer.add(inner, BorderLayout.NORTH);
|
416
|
+
|
417
|
+
//outer.setBorder(BorderFactory.createLineBorder(Color.GREEN, 5));
|
418
|
+
|
419
|
+
|
420
|
+
|
421
|
+
add(inner, BorderLayout.NORTH);
|
422
|
+
|
423
|
+
setBorder(BorderFactory.createLineBorder(Color.GREEN, 5));
|
424
|
+
|
425
|
+
|
426
|
+
|
427
|
+
//JScrollPane scrollPane = new JScrollPane(outer);
|
428
|
+
|
429
|
+
|
430
|
+
|
431
|
+
JScrollPane scrollPane = new JScrollPane(this);
|
432
|
+
|
433
|
+
|
434
|
+
|
435
|
+
|
436
|
+
|
437
|
+
//add(scrollPane, BorderLayout.CENTER);
|
438
|
+
|
439
|
+
scrollPane.setBorder(BorderFactory.createLineBorder(Color.BLUE, 5));
|
440
|
+
|
441
|
+
|
442
|
+
|
443
|
+
scrollPane.getVerticalScrollBar().addAdjustmentListener(new AdjustmentListener() {
|
444
|
+
|
445
|
+
private int max = scrollPane.getVerticalScrollBar().getMaximum();
|
446
|
+
|
447
|
+
|
448
|
+
|
449
|
+
public void adjustmentValueChanged(AdjustmentEvent e) {
|
450
|
+
|
451
|
+
if (max - e.getAdjustable().getMaximum() == 0) return;
|
452
|
+
|
453
|
+
|
454
|
+
|
455
|
+
e.getAdjustable().setValue(e.getAdjustable().getMaximum());
|
456
|
+
|
457
|
+
max = scrollPane.getVerticalScrollBar().getMaximum();
|
458
|
+
|
459
|
+
}
|
460
|
+
|
461
|
+
});
|
462
|
+
|
463
|
+
|
464
|
+
|
465
|
+
JPanel controls = new JPanel(); // 操作エリア
|
466
|
+
|
467
|
+
add(controls, BorderLayout.SOUTH);
|
468
|
+
|
469
|
+
|
470
|
+
|
471
|
+
JTextField textField = new JTextField("メッセージ", 20);
|
472
|
+
|
473
|
+
controls.add(textField);
|
474
|
+
|
475
|
+
textField.selectAll(); // 全選択
|
476
|
+
|
477
|
+
|
478
|
+
|
479
|
+
JButton button = new JButton("送信");
|
480
|
+
|
481
|
+
controls.add(button);
|
482
|
+
|
483
|
+
button.addActionListener(e -> {
|
484
|
+
|
485
|
+
inner.add(new Message("naruto.jpg", right));
|
486
|
+
|
487
|
+
inner.add(Box.createVerticalStrut(10)); // 隙間
|
488
|
+
|
489
|
+
inner.add(new Message("naruto.jpg", left));
|
490
|
+
|
491
|
+
inner.add(Box.createVerticalStrut(10)); // 隙間
|
492
|
+
|
493
|
+
|
494
|
+
|
495
|
+
scrollPane.revalidate(); // 再描画
|
496
|
+
|
497
|
+
|
498
|
+
|
499
|
+
textField.selectAll(); // 全選択
|
500
|
+
|
501
|
+
textField.requestFocus(); // フォーカス
|
502
|
+
|
503
|
+
});
|
504
|
+
|
505
|
+
|
506
|
+
|
507
|
+
textField.addActionListener(e -> button.doClick());
|
508
|
+
|
509
|
+
|
510
|
+
|
511
|
+
|
512
|
+
|
513
|
+
}
|
514
|
+
|
515
|
+
}
|
516
|
+
|
517
|
+
|
518
|
+
|
519
|
+
```
|
520
|
+
|
521
|
+
```ここに言語を入力
|
522
|
+
|
523
|
+
package boundary;
|
524
|
+
|
525
|
+
|
526
|
+
|
527
|
+
import java.util.ArrayList;
|
528
|
+
|
529
|
+
|
530
|
+
|
531
|
+
import javax.swing.ImageIcon;
|
532
|
+
|
533
|
+
import javax.swing.JButton;
|
534
|
+
|
535
|
+
|
536
|
+
|
537
|
+
//メッセージのエモーションにかかわるボタンの処理クラス
|
538
|
+
|
539
|
+
class EmotionButton extends JButton {
|
540
|
+
|
541
|
+
private ArrayList<String> arrL = new ArrayList<String>();
|
542
|
+
|
543
|
+
|
544
|
+
|
545
|
+
public EmotionButton(ImageIcon icon) {
|
546
|
+
|
547
|
+
super("0", icon);
|
548
|
+
|
549
|
+
}
|
550
|
+
|
551
|
+
|
552
|
+
|
553
|
+
public int editBtn(String userName) {
|
554
|
+
|
555
|
+
if(arrL.contains(userName)) {
|
556
|
+
|
557
|
+
arrL.remove(arrL.indexOf(userName));
|
558
|
+
|
559
|
+
return arrL.size();
|
102
560
|
|
103
561
|
}
|
104
562
|
|
105
|
-
|
563
|
+
else {
|
564
|
+
|
106
|
-
|
565
|
+
arrL.add(userName);
|
566
|
+
|
107
|
-
|
567
|
+
return arrL.size();
|
108
|
-
|
568
|
+
|
109
|
-
}
|
569
|
+
}
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
570
|
+
|
114
|
-
|
115
|
-
super.paintComponent(g);
|
116
|
-
|
117
|
-
}
|
571
|
+
}
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
572
|
+
|
122
|
-
|
123
|
-
|
573
|
+
|
124
|
-
|
125
|
-
|
574
|
+
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
public
|
575
|
+
public ArrayList<String> getUserName() {
|
130
|
-
|
131
|
-
|
576
|
+
|
132
|
-
|
133
|
-
}
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
577
|
+
return arrL;
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
}
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
public void mousePressed(MouseEvent e) {
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
}
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
public void mouseReleased(MouseEvent e) {
|
154
|
-
|
155
|
-
|
156
578
|
|
157
579
|
}
|
158
580
|
|
@@ -160,105 +582,11 @@
|
|
160
582
|
|
161
583
|
}
|
162
584
|
|
585
|
+
|
586
|
+
|
163
587
|
```
|
164
588
|
|
165
|
-
|
589
|
+
|
166
|
-
|
167
|
-
package boundary;
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
import java.awt.BorderLayout;
|
172
|
-
|
173
|
-
import java.awt.Color;
|
174
|
-
|
175
|
-
import java.awt.Dimension;
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
import javax.swing.JFrame;
|
180
|
-
|
181
|
-
import javax.swing.JPanel;
|
182
|
-
|
183
|
-
import javax.swing.JScrollPane;
|
184
|
-
|
185
|
-
import javax.swing.JViewport;
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
public class ChatBoundary extends JFrame{
|
190
|
-
|
191
|
-
Message[] message = new Message[3];
|
192
|
-
|
193
|
-
//Message message = null;
|
194
|
-
|
195
|
-
public static void main(String[] args) {
|
196
|
-
|
197
|
-
ChatBoundary chatBoundary = new ChatBoundary("ChatBoundary");
|
198
|
-
|
199
|
-
chatBoundary.setSize(new Dimension(2000,1400));
|
200
|
-
|
201
|
-
//chatBoundary.setResizable(false);
|
202
|
-
|
203
|
-
chatBoundary.setVisible(true);
|
204
|
-
|
205
|
-
}
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
ChatBoundary(String title){
|
210
|
-
|
211
|
-
setTitle(title);
|
212
|
-
|
213
|
-
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
214
|
-
|
215
|
-
//Container contentPane = getContentPane();
|
216
|
-
|
217
|
-
message[0] = new Message("naruto.jpg");
|
218
|
-
|
219
|
-
message[1] = new Message("コナン.jpg");
|
220
|
-
|
221
|
-
JScrollPane scrollpane = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
|
222
|
-
|
223
|
-
scrollpane.setPreferredSize(new Dimension(1000,1200));
|
224
|
-
|
225
|
-
scrollpane.setViewportView(message[0]);
|
226
|
-
|
227
|
-
JViewport view = scrollpane.getViewport();
|
228
|
-
|
229
|
-
view.setView(message[1]);
|
230
|
-
|
231
|
-
view.setViewPosition(new Point(100,1000));
|
232
|
-
|
233
|
-
//送信欄の枠
|
234
|
-
|
235
|
-
JPanel jp = new JPanel();
|
236
|
-
|
237
|
-
jp.setBackground(Color.blue);
|
238
|
-
|
239
|
-
jp.setPreferredSize(new Dimension(100,130));
|
240
|
-
|
241
|
-
add(scrollpane, BorderLayout.NORTH);
|
242
|
-
|
243
|
-
add(jp, BorderLayout.SOUTH);
|
244
|
-
|
245
|
-
pack();//フレームに入れた部品の大きさなどを考慮してフレームの適切なサイズを計算
|
246
|
-
|
247
|
-
}
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
}
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
```
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
### 試したこと
|
260
|
-
|
261
|
-
panel以外でチャットの枠を構成できないか調べ,JListを使って出来るのかと今ネットを探っている段階です.
|
262
590
|
|
263
591
|
|
264
592
|
|
1
完成したイメージの図を新たに付け加えた。
test
CHANGED
File without changes
|
test
CHANGED
@@ -18,6 +18,10 @@
|
|
18
18
|
|
19
19
|
|
20
20
|
|
21
|
+
完成イメージです.
|
22
|
+
|
23
|
+
![イメージ説明](232808c7871cc4d77b0621bbd0355c5d.jpeg)
|
24
|
+
|
21
25
|
|
22
26
|
|
23
27
|
### 発生している問題
|