質問編集履歴

3

追加

2017/05/09 00:44

投稿

toutou
toutou

スコア2050

test CHANGED
File without changes
test CHANGED
@@ -399,3 +399,155 @@
399
399
  }
400
400
 
401
401
  ```
402
+
403
+
404
+
405
+ さらに追記
406
+
407
+
408
+
409
+ ```ここに言語を入力
410
+
411
+ class GPanel extends JPanel implements MouseListener, MouseMotionListener{
412
+
413
+ private int move_x = -100;
414
+
415
+ private int move_y = -100;
416
+
417
+ private int start_x = -100;
418
+
419
+ private int start_y = -100;
420
+
421
+ private boolean flag = false;
422
+
423
+
424
+
425
+ BufferedImage seve_field = new BufferedImage(600,600, BufferedImage.TYPE_4BYTE_ABGR);
426
+
427
+ public GPanel()
428
+
429
+ {
430
+
431
+ addMouseListener(this);
432
+
433
+ addMouseMotionListener(this);
434
+
435
+ }
436
+
437
+ @Override
438
+
439
+ public void paintComponent(Graphics g)
440
+
441
+ {
442
+
443
+ Graphics2D g2= (Graphics2D)g;
444
+
445
+ BasicStroke BStroke = new BasicStroke(5.0f);
446
+
447
+ g2.setStroke(BStroke);
448
+
449
+ g2.setColor(Color.RED);
450
+
451
+ Graphics seve = seve_field.createGraphics();
452
+
453
+ Graphics2D seve2= (Graphics2D)seve;
454
+
455
+ seve2.setStroke(BStroke);
456
+
457
+ seve2.setColor(Color.RED);
458
+
459
+
460
+
461
+ if(start_x==-100||start_y== -100||move_x==-100||move_y==-100)
462
+
463
+ {
464
+
465
+ move_x = move_y = start_x = start_y = -100;
466
+
467
+ }
468
+
469
+ g2.drawImage(seve_field,0,0,this);
470
+
471
+ seve2.drawLine(start_x, start_y, move_x, move_y);
472
+
473
+ g2.drawLine(start_x, start_y, move_x, move_y);
474
+
475
+ start_x = move_x;
476
+
477
+ start_y = move_y;
478
+
479
+ }
480
+
481
+ @Override
482
+
483
+ public void mousePressed(MouseEvent e)
484
+
485
+ {
486
+
487
+ flag =false;
488
+
489
+ start_x = move_x = e.getX();
490
+
491
+ start_y = move_y = e.getY();
492
+
493
+ }
494
+
495
+ @Override
496
+
497
+ public void mouseReleased(MouseEvent e)
498
+
499
+ {
500
+
501
+ flag = true;
502
+
503
+ move_x = move_y = start_x = start_y = -100;
504
+
505
+ }
506
+
507
+ @Override
508
+
509
+ public void mouseDragged(MouseEvent e)
510
+
511
+ {
512
+
513
+ move_x = e.getX();
514
+
515
+ move_y = e.getY();
516
+
517
+ repaint();
518
+
519
+ }
520
+
521
+ @Override
522
+
523
+ public void mouseClicked(MouseEvent e)
524
+
525
+ {
526
+
527
+ }
528
+
529
+ @Override
530
+
531
+ public void mouseEntered(MouseEvent e)
532
+
533
+ {
534
+
535
+ }
536
+
537
+ @Override
538
+
539
+ public void mouseExited(MouseEvent e)
540
+
541
+ {
542
+
543
+ }
544
+
545
+ @Override
546
+
547
+ public void mouseMoved(MouseEvent e)
548
+
549
+ {
550
+
551
+ }
552
+
553
+ ```

2

修正

2017/05/09 00:44

投稿

toutou
toutou

スコア2050

test CHANGED
File without changes
test CHANGED
@@ -322,19 +322,17 @@
322
322
 
323
323
  start_y = move_y = e.getY();
324
324
 
325
- System.out.println(e.getY());
326
-
327
325
  }
328
326
 
329
327
  @Override
330
328
 
331
329
  public void mouseReleased(MouseEvent e)
332
330
 
333
- { move_x = -100;//初期位置初期化
331
+ { move_x = -100;
334
332
 
335
333
  move_y = -100;
336
334
 
337
- start_x= -100;//初期位置初期化
335
+ start_x= -100;
338
336
 
339
337
  start_y = -100;
340
338
 

1

追記

2017/05/08 00:07

投稿

toutou
toutou

スコア2050

test CHANGED
File without changes
test CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
 
4
4
 
5
- ```ここに言語を入力
5
+ ```java
6
6
 
7
7
  import java.awt.BorderLayout;
8
8
 
@@ -267,3 +267,137 @@
267
267
  }
268
268
 
269
269
  ```
270
+
271
+
272
+
273
+ 修正部分
274
+
275
+ 以下の通りに直しました。
276
+
277
+ ```java
278
+
279
+ @Override
280
+
281
+ public void paintComponent(Graphics g)
282
+
283
+ {
284
+
285
+ Graphics2D g2 = (Graphics2D)g;
286
+
287
+ BasicStroke BStroke = new BasicStroke(5.0f);
288
+
289
+ g2.setStroke(BStroke);
290
+
291
+ g.setColor(Color.RED);
292
+
293
+ if(start_x==-100||start_y== -10||move_x==-100||move_y==-100)
294
+
295
+ {
296
+
297
+ move_x = -100;
298
+
299
+ move_y = -100;
300
+
301
+ start_x= -100;
302
+
303
+ start_y = -100;
304
+
305
+ }
306
+
307
+ g.drawLine(start_x, start_y, move_x, move_y);
308
+
309
+ start_x = move_x;
310
+
311
+ start_y=move_y;
312
+
313
+ }
314
+
315
+ @Override
316
+
317
+ public void mousePressed(MouseEvent e)
318
+
319
+ {
320
+
321
+ start_x = move_x = e.getX();
322
+
323
+ start_y = move_y = e.getY();
324
+
325
+ System.out.println(e.getY());
326
+
327
+ }
328
+
329
+ @Override
330
+
331
+ public void mouseReleased(MouseEvent e)
332
+
333
+ { move_x = -100;//初期位置初期化
334
+
335
+ move_y = -100;
336
+
337
+ start_x= -100;//初期位置初期化
338
+
339
+ start_y = -100;
340
+
341
+ }
342
+
343
+ @Override
344
+
345
+ public void mouseDragged(MouseEvent e)
346
+
347
+ {
348
+
349
+ move_x = e.getX();
350
+
351
+ move_y = e.getY();
352
+
353
+ repaint();
354
+
355
+ }
356
+
357
+ @Override
358
+
359
+ public void mouseClicked(MouseEvent e)
360
+
361
+ {
362
+
363
+ }
364
+
365
+ @Override
366
+
367
+ public void mouseEntered(MouseEvent e)
368
+
369
+ {
370
+
371
+ start_x = move_x = e.getX();
372
+
373
+ start_y = move_y = e.getY();
374
+
375
+ }
376
+
377
+ @Override
378
+
379
+ public void mouseExited(MouseEvent e)
380
+
381
+ {
382
+
383
+ move_x = -100;
384
+
385
+ move_y = -100;
386
+
387
+ start_x= -100;
388
+
389
+ start_y = -100;
390
+
391
+ }
392
+
393
+ @Override
394
+
395
+ public void mouseMoved(MouseEvent e)
396
+
397
+ {
398
+
399
+ }
400
+
401
+ }
402
+
403
+ ```