回答編集履歴

2

修正

2023/08/29 02:40

投稿

jimbe
jimbe

スコア12723

test CHANGED
@@ -1,27 +1,23 @@
1
- 何がどこで必要になるのか分かりませんが動くように改造してみました。
1
+ 何がどこで必要になるのか分かりませんが編集・改造してみました。
2
2
  まだ 1 ファイルに纏めたほうが簡単そうでしたので纏めています。
3
3
  json 等はダミーにしています。
4
4
 
5
5
  TextDungeon.java
6
6
  ```java
7
- package teratail_java.q_01k9j06bos5aw6;
8
-
9
7
  import java.awt.*;
10
8
  import java.io.*;
11
9
  import java.util.Properties;
12
10
 
13
11
  import javax.swing.*;
14
12
 
15
- public class TextDungeon {
13
+ public class TextDungeon extends JFrame {
16
14
  public static void main(String[] args) throws IOException {
17
15
  PrefModel prefModel = new PrefModel(new File("C:/java/pref.properties"));
18
- SwingUtilities.invokeLater(() -> new MainFrame(prefModel).setVisible(true));
16
+ SwingUtilities.invokeLater(() -> new TextDungeon(prefModel).setVisible(true));
19
- }
17
+ }
20
- }
18
+
21
-
22
- class MainFrame extends JFrame {
23
- MainFrame(PrefModel prefModel) {
19
+ TextDungeon(PrefModel prefModel) {
24
- super("MainFrame");
20
+ super("TextDungeon");
25
21
  setDefaultCloseOperation(EXIT_ON_CLOSE);
26
22
  setSize(prefModel.getWidth(), prefModel.getHeight());
27
23
  setResizable(false);
@@ -32,7 +28,7 @@
32
28
  JMenuBar menuBar = new JMenuBar();
33
29
  JMenu confMenu = new JMenu("conf");
34
30
  JMenuItem prefItem = new JMenuItem("pref");
35
- prefItem.addActionListener(v -> new PrefDialog(MainFrame.this, prefModel).setVisible(true));
31
+ prefItem.addActionListener(v -> new PrefDialog(TextDungeon.this, prefModel).setVisible(true));
36
32
  confMenu.add(prefItem);
37
33
  menuBar.add(confMenu);
38
34
  setJMenuBar(menuBar);
@@ -53,10 +49,10 @@
53
49
 
54
50
  JPanel movePanel = new JPanel(new GridLayout(1, 2));
55
51
  JButton exprollBtn = new JButton("探検");
56
- exprollBtn.addActionListener(v -> new ExprollDialog(MainFrame.this, jsonHelper).setVisible(true));
52
+ exprollBtn.addActionListener(v -> new ExprollDialog(TextDungeon.this, jsonHelper).setVisible(true));
57
53
  movePanel.add(exprollBtn);
58
54
  JButton equipBtn = new JButton("装備");
59
- equipBtn.addActionListener(v -> new EquipmentDialog(MainFrame.this).setVisible(true));
55
+ equipBtn.addActionListener(v -> new EquipmentDialog(TextDungeon.this).setVisible(true));
60
56
  movePanel.add(equipBtn);
61
57
  add(movePanel);
62
58
  }

1

公開されたコードによって修正

2023/08/29 02:36

投稿

jimbe
jimbe

スコア12723

test CHANGED
@@ -1,13 +1,18 @@
1
1
  何がどこで必要になるのか分かりませんが動くように改造してみました。
2
+ まだ 1 ファイルに纏めたほうが簡単そうでしたので纏めています。
3
+ json 等はダミーにしています。
4
+
5
+ TextDungeon.java
2
6
  ```java
7
+ package teratail_java.q_01k9j06bos5aw6;
8
+
3
9
  import java.awt.*;
4
10
  import java.io.*;
5
11
  import java.util.Properties;
6
12
 
7
13
  import javax.swing.*;
8
14
 
9
- //このクラスは要らない(MainFrameがやれば良い)が、mainをここに入れた.
10
- public class StartController {
15
+ public class TextDungeon {
11
16
  public static void main(String[] args) throws IOException {
12
17
  PrefModel prefModel = new PrefModel(new File("C:/java/pref.properties"));
13
18
  SwingUtilities.invokeLater(() -> new MainFrame(prefModel).setVisible(true));
@@ -150,10 +155,10 @@
150
155
 
151
156
  //ダミー?
152
157
  class PrefModel {
153
- private static final String PROPKEY_WIDTH = "width";
158
+ private static final String PROPKEY_WIDTH = "widthSize";
154
- private static final String PROPKEY_HEIGHT = "height";
159
+ private static final String PROPKEY_HEIGHT = "heightSize";
155
- private static final int DEFAULT_WIDTH = 800;
160
+ private static final int DEFAULT_WIDTH = 700;
156
- private static final int DEFAULT_HEIGHT = 600;
161
+ private static final int DEFAULT_HEIGHT = 700;
157
162
 
158
163
  private File file;
159
164
  private Properties properties;
@@ -202,7 +207,7 @@
202
207
  }
203
208
  //ダミー
204
209
  class JsonHelper {
205
- String[] getDungeonName() { return new String[] {"map1","map2"}; }
210
+ String[] getDungeonName() { return new String[]{"はじまりのもり","げんそうのさばく","しんぴのうみ"}; }
206
211
  }
207
212
  //ダミー
208
213
  class DungeonModel {