質問編集履歴

1

重複していた文の削除

2017/11/25 09:52

投稿

Alpa
Alpa

スコア80

test CHANGED
File without changes
test CHANGED
@@ -10,7 +10,9 @@
10
10
 
11
11
 
12
12
 
13
+ ###該当のソースコード
14
+
13
- ```java
15
+ ```ここに言語を入力
14
16
 
15
17
  import javax.swing.*;//swingのimport
16
18
 
@@ -378,398 +380,6 @@
378
380
 
379
381
  ```
380
382
 
381
- ###前提・実現したいこと
382
-
383
- ここに質問したいことを詳細に書いてください
384
-
385
- (例)PHP(CakePHP)で●●なシステムを作っています。
386
-
387
-   ■■な機能を実装中に以下のエラーメッセージが発生しました。
388
-
389
-
390
-
391
- ###発生している問題・エラーメッセージ
392
-
393
-
394
-
395
- ```
396
-
397
- エラーメッセージ
398
-
399
- ```
400
-
401
-
402
-
403
- ###該当のソースコード
404
-
405
- ```ここに言語を入力
406
-
407
- import javax.swing.*;//swingのimport
408
-
409
- import java.awt.*;//awtのimport
410
-
411
- import java.awt.event.*;//awtのeventのimport
412
-
413
-
414
-
415
- public class action extends JFrame implements ActionListener{
416
-
417
-
418
-
419
- static action Frame;//Frame
420
-
421
-
422
-
423
- JPanel Panel;//Panel
424
-
425
-
426
-
427
- JLabel Player;//プレイヤーの画像が入ったJLabel
428
-
429
- JLabel Block;//ブロックの画像が入ったJLabel
430
-
431
-
432
-
433
- ImageIcon PlayerIcon;//プレイヤーの画像読み込み
434
-
435
- ImageIcon BlockIcon;//ブロックの画像読み込み
436
-
437
-
438
-
439
- Timer timer;
440
-
441
- Timer Ktimer;
442
-
443
-
444
-
445
- int PlayerX = 20;//プレイヤーのX座標
446
-
447
- int PlayerY = 40;//プレイヤーのY座標
448
-
449
-
450
-
451
- static boolean Jflag = false;//ジャンプフラグ
452
-
453
- static boolean UKflag = false;//ジャンプキーフラグ
454
-
455
- static boolean LKflag = false;//左移動キーフラグ
456
-
457
- static boolean RKflag = false;//右移動キーフラグ
458
-
459
- static boolean Dflag = false;//デバックフラグ
460
-
461
-
462
-
463
- public static void main(String args[]){
464
-
465
-
466
-
467
- Frame = new action();
468
-
469
-
470
-
471
- Frame.setSize(900, 500);//ウィンドウのサイズ設定(X, Y)
472
-
473
- Frame.setTitle("アクションゲーム");//ウィンドウのタイトル
474
-
475
- Frame.setLocationRelativeTo(null);//ウィンドウを画面の中央に表示する
476
-
477
- Frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//xで閉じるようにする
478
-
479
- Frame.setVisible(true);//ウィンドウを可視化
480
-
481
-
482
-
483
- }
484
-
485
-
486
-
487
- action(){
488
-
489
-
490
-
491
- timer = new Timer(10, this);//タイマー間隔設定
492
-
493
- Ktimer = new Timer(10, this);//タイマー間隔設定
494
-
495
-
496
-
497
- Panel = new JPanel();
498
-
499
- Panel.setLayout(null);//レイアウトマネージャー無効化
500
-
501
-
502
-
503
- PlayerIcon = new ImageIcon("./PlayerIcon.png");//プレイヤーの画像指定
504
-
505
- BlockIcon = new ImageIcon("./BlockIcon.png");//ブロックの画像指定
506
-
507
-
508
-
509
- Player = new JLabel(PlayerIcon);//プレイヤー画像設定
510
-
511
- Player.setBounds(PlayerX, PlayerY, 20, 40);//プレイヤーの座標とサイズ設定
512
-
513
-
514
-
515
- Block = new JLabel(BlockIcon);//ブロック画像設定
516
-
517
- Block.setBounds(0, 442, 20, 20);//ブロックの座標とサイズ設定
518
-
519
-
520
-
521
- Panel.add(Player);//プレイヤー画像追加
522
-
523
- Panel.add(Block);//ブロック画像追加
524
-
525
-
526
-
527
- Container contentPane = getContentPane();//???
528
-
529
- contentPane.add(Panel, BorderLayout.CENTER);//???
530
-
531
-
532
-
533
- timer.start();//タイマースタート
534
-
535
-
536
-
537
- }
538
-
539
-
540
-
541
- public void actionPerformed(ActionEvent e){//タイマーの処理
542
-
543
-
544
-
545
- if(PlayerY <= 399){
546
-
547
-
548
-
549
- Jflag = true;//ジャンプフラグをtrueにする
550
-
551
-
552
-
553
- }else{
554
-
555
-
556
-
557
- Jflag = false;//ジャンプフラグをfalseにする
558
-
559
-
560
-
561
- }
562
-
563
-
564
-
565
- if(Jflag == true){//もしジャンプフラグがtrueなら
566
-
567
-
568
-
569
- PlayerY += 10;//プレイヤーのY座標を+10
570
-
571
- Player.setBounds(PlayerX, PlayerY, 20, 40);//プレイヤーの座標再設定
572
-
573
- Panel.repaint();//パネルを更新
574
-
575
-
576
-
577
- if(PlayerY >= 399){
578
-
579
-
580
-
581
- Jflag = false;
582
-
583
- timer.stop();
584
-
585
-
586
-
587
- }
588
-
589
-
590
-
591
- }
592
-
593
-
594
-
595
- if(UKflag == true){
596
-
597
-
598
-
599
- PlayerY -= 10;//プレイヤーのY座標を-10
600
-
601
- Player.setBounds(PlayerX, PlayerY, 20, 40);//プレイヤーの座標再設定
602
-
603
- Panel.repaint();//パネルを更新
604
-
605
-
606
-
607
- if(PlayerY <= 359){
608
-
609
-
610
-
611
- UKflag = false;
612
-
613
- Jflag = false;
614
-
615
- timer.stop();
616
-
617
-
618
-
619
- }
620
-
621
-
622
-
623
- }
624
-
625
-
626
-
627
- }
628
-
629
-
630
-
631
- protected void processKeyEvent(KeyEvent e){//キー入力の処理
632
-
633
-
634
-
635
- if(e.getID() == KeyEvent.KEY_PRESSED){
636
-
637
-
638
-
639
- if(e.getKeyCode() == KeyEvent.VK_UP && Jflag == false){
640
-
641
-
642
-
643
- UKflag = true;
644
-
645
- Jflag = true;
646
-
647
-
648
-
649
- timer.start();
650
-
651
-
652
-
653
- System.out.println("UP");
654
-
655
-
656
-
657
- }
658
-
659
-
660
-
661
- if(e.getKeyCode() == KeyEvent.VK_LEFT && Jflag == false){
662
-
663
-
664
-
665
- LKflag = true;
666
-
667
-
668
-
669
- timer.start();
670
-
671
-
672
-
673
- System.out.println("LEFT");
674
-
675
-
676
-
677
- }
678
-
679
-
680
-
681
- if(e.getKeyCode() == KeyEvent.VK_RIGHT && Jflag == false){
682
-
683
-
684
-
685
- RKflag = true;
686
-
687
-
688
-
689
- timer.start();
690
-
691
-
692
-
693
- System.out.println("RIGHT");
694
-
695
-
696
-
697
- }
698
-
699
-
700
-
701
- if(e.getKeyCode() == KeyEvent.VK_D && Dflag == true){
702
-
703
-
704
-
705
- System.out.println("\nJflag:" + Jflag);
706
-
707
- System.out.println("UKflag:" + UKflag);
708
-
709
- System.out.println("LKflag:" + LKflag);
710
-
711
- System.out.println("RKflag:" + RKflag);
712
-
713
- System.out.println("Dflag:" + Dflag);
714
-
715
- System.out.println("PlayerX座標:" + PlayerX);
716
-
717
- System.out.println("PlayerY座標:" + PlayerY + "\n");
718
-
719
-
720
-
721
- }
722
-
723
-
724
-
725
- if(e.getKeyCode() == KeyEvent.VK_S){
726
-
727
-
728
-
729
- if(Dflag == false){
730
-
731
-
732
-
733
- Dflag = true;
734
-
735
- System.out.println("デバック機能を有効にしました");
736
-
737
-
738
-
739
- }
740
-
741
-
742
-
743
- }
744
-
745
-
746
-
747
- if(e.getKeyCode() == KeyEvent.VK_E){
748
-
749
-
750
-
751
- Frame.dispose();
752
-
753
- System.out.println("正常に終了しました");
754
-
755
-
756
-
757
- }
758
-
759
-
760
-
761
- }
762
-
763
-
764
-
765
- }
766
-
767
-
768
-
769
- }
770
-
771
- ```
772
-
773
383
 
774
384
 
775
385
  ###試したこと