teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

2

コードの追加

2020/12/31 06:07

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -27,4 +27,103 @@
27
27
  ##実行環境
28
28
  OS:Windows10
29
29
  JDK:14
30
- Eclipse:Eclipse IDE for Java Developers - 2020-09
30
+ Eclipse:Eclipse IDE for Java Developers - 2020-09
31
+
32
+ ##追記
33
+ 実際のコードを載せるようにとのご指摘がありましたのでこちらに追記いたします。
34
+ ご指摘ありがとうございます。
35
+
36
+ **Mainクラス**
37
+ ```Java
38
+ package com.original_game.janken;
39
+
40
+ import java.io.File;
41
+
42
+ import javax.sound.sampled.Clip;
43
+ import javax.swing.JFrame;
44
+
45
+ public class GameMain {
46
+
47
+ public static void main(String[] args) throws Exception {
48
+ JFrame frame = new JFrame("じゃんけんゲーム");
49
+ frame.setSize(800,600);
50
+ frame.setLocationRelativeTo(null);
51
+ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
52
+ frame.setResizable(false);
53
+
54
+ Panel.createPanel(frame);
55
+
56
+ frame.setVisible(true);
57
+
58
+ File file = new File("C:\Users\user\Desktop\sample.wav");
59
+ Clip clip = Sound.createClip(file);
60
+ clip.start();
61
+ clip.loop(Clip.LOOP_CONTINUOUSLY);
62
+ Thread.sleep(3 * 1000);
63
+ clip.close();
64
+
65
+ }
66
+ }
67
+
68
+ ```
69
+
70
+ **Panelクラス**
71
+ ```java
72
+ package com.original_game.janken;
73
+
74
+ import java.awt.BorderLayout;
75
+ import java.awt.Color;
76
+ import java.awt.Dimension;
77
+ import java.awt.Font;
78
+
79
+ import javax.swing.JFrame;
80
+ import javax.swing.JLabel;
81
+ import javax.swing.JPanel;
82
+
83
+ public class Panel {
84
+ public static JLabel headerLabel;
85
+ public static JLabel contentsLabel;
86
+
87
+ public static void createPanel(JFrame frame) {
88
+ //ヘッダーパネル
89
+ Dimension headerPanelDimension = new Dimension(800, 50);
90
+ JPanel headerPanel = setPanel(Color.GRAY, headerPanelDimension);
91
+ headerLabel = new JLabel("「さあ、じゃんけんで勝負だ!」");
92
+ headerLabel = setFont(Color.ORANGE,headerLabel,24);
93
+ headerPanel.add(headerLabel);
94
+ frame.add(headerPanel,BorderLayout.NORTH);
95
+
96
+ //コンテンツパネル
97
+ Dimension contentsPanelDimension = new Dimension(800, 450);
98
+ JPanel contentsPanel = setPanel(Color.WHITE,contentsPanelDimension);
99
+ contentsLabel = new JLabel("じゃんけん・・・");
100
+ contentsLabel = setFont(Color.BLACK,contentsLabel,36);
101
+ contentsPanel.add(contentsLabel);
102
+ frame.add(contentsPanel,BorderLayout.CENTER);
103
+
104
+ //フッターパネル
105
+ Dimension footerPanelDimension = new Dimension(800, 100);
106
+ JPanel footerPanel = setPanel(Color.WHITE, footerPanelDimension);
107
+ Player.createButton(footerPanel);
108
+ frame.add(footerPanel,BorderLayout.SOUTH);
109
+
110
+ }
111
+
112
+ public static JPanel setPanel(Color color, Dimension PanelDimension) {
113
+ JPanel panel = new JPanel();
114
+ panel.setPreferredSize(PanelDimension);
115
+ panel.setLayout(new BorderLayout());
116
+ panel.setBackground(color);
117
+ return(panel);
118
+ }
119
+ public static JLabel setFont(Color clr, JLabel label, int strSize) {
120
+ label.setForeground(clr);
121
+ Font labelFont = new Font("Serif", Font.BOLD,strSize);
122
+ label.setFont(labelFont);
123
+ label.setHorizontalAlignment(JLabel.CENTER);
124
+ label.setVerticalAlignment(JLabel.CENTER);
125
+ return(label);
126
+ }
127
+ }
128
+
129
+ ```

1

情報の追加

2020/12/31 06:07

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -18,8 +18,10 @@
18
18
  この部分はEclipseで実行できていたときから書いていましたが、今までなんのエラーも出ていませんでした。
19
19
 
20
20
  ググったところImportができていないと表示されるそうですが、Panelクラスは同じパッケージ内にあります。同じパッケージ内であればImportはいらないはずですよね?
21
+ ちなみにcdでGameMainやPanelといったクラスが存在するディレクトリまで移動しています。
22
+
23
+
21
24
  なぜプロンプトから実行するとこのようなエラーが出るのでしょうか。
22
-
23
25
  よろしくお願いいたします。
24
26
 
25
27
  ##実行環境