質問編集履歴
4
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -218,14 +218,6 @@
|
|
218
218
|
}
|
219
219
|
}
|
220
220
|
}
|
221
|
-
|
222
|
-
```java
|
223
|
-
public class TextDungeon {
|
224
|
-
|
225
|
-
public static void main(String[] args) {
|
226
|
-
new StartController();
|
227
|
-
}
|
228
|
-
}
|
229
221
|
```
|
230
222
|
|
231
223
|
```java
|
3
コードの編集をしました
test
CHANGED
File without changes
|
test
CHANGED
@@ -93,7 +93,6 @@
|
|
93
93
|
JsonHelper jsonHelper = new JsonHelper();
|
94
94
|
|
95
95
|
MainFrame() {
|
96
|
-
// TODO 自動生成されたコンストラクター・スタブ
|
97
96
|
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
98
97
|
setSize(PrefModel.WIDTH, PrefModel.HEIGHT);
|
99
98
|
setLocationRelativeTo(rootPane);
|
2
文の追加をしました
test
CHANGED
File without changes
|
test
CHANGED
@@ -348,6 +348,7 @@
|
|
348
348
|
}
|
349
349
|
}
|
350
350
|
```
|
351
|
+
ファイル
|
351
352
|
pref.properties
|
352
353
|
#sizePref
|
353
354
|
#Sun Aug 27 20:03:34 JST 2023
|
1
コードを追加しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
外部クラスにjframeを継承したメインウィンドウを作り、
|
4
4
|
その中のボタンをクリックによって新しいウィンドウを描画しています。
|
5
5
|
setDefaultCloseOperation(EXIT_ON_CLOSE)メソッドは、外部クラスのjframeにコードを書いています。
|
6
|
-
内部クラスの新しいウィンドウの
|
6
|
+
内部クラスの新しいウィンドウの×ボタンをクリックすると、プログラムがすべて終了してしまいます。
|
7
7
|
なぜなのかを教えて下さい。
|
8
8
|
|
9
9
|
おそらく該当箇所ですが、メインフレームを変数に入れなければ、新しいウィンドウを消しても古いウィンドウは残り思った通りに動きます。
|
@@ -13,7 +13,6 @@
|
|
13
13
|
public class StartController {
|
14
14
|
static MainFrame mainFrame = null;
|
15
15
|
public StartController() {
|
16
|
-
// TODO 自動生成されたコンストラクター・スタブ
|
17
16
|
File file = new File("C:/java/pref.properties");
|
18
17
|
|
19
18
|
if (file.exists()) {
|
@@ -33,7 +32,6 @@
|
|
33
32
|
```java
|
34
33
|
public class StartController {
|
35
34
|
public StartController() {
|
36
|
-
// TODO 自動生成されたコンストラクター・スタブ
|
37
35
|
File file = new File("C:/java/pref.properties");
|
38
36
|
|
39
37
|
if (file.exists()) {
|
@@ -72,7 +70,6 @@
|
|
72
70
|
public class StartController {
|
73
71
|
static MainFrame mainFrame = null;
|
74
72
|
public StartController() {
|
75
|
-
// TODO 自動生成されたコンストラクター・スタブ
|
76
73
|
File file = new File("C:/java/pref.properties");
|
77
74
|
|
78
75
|
if (file.exists()) {
|
@@ -114,7 +111,6 @@
|
|
114
111
|
}
|
115
112
|
|
116
113
|
public void actionPerformed(ActionEvent e) {
|
117
|
-
// TODO 自動生成されたメソッド・スタブ
|
118
114
|
if (e.getSource() == prefItem) {
|
119
115
|
new PrefFrame();
|
120
116
|
}
|
@@ -179,7 +175,6 @@
|
|
179
175
|
}
|
180
176
|
|
181
177
|
public void actionPerformed(ActionEvent e) {
|
182
|
-
// TODO 自動生成されたメソッド・スタブ
|
183
178
|
if (e.getSource() == questBtn) {
|
184
179
|
DungeonModel.setDungeonData((String) dungeonBox.getSelectedItem());
|
185
180
|
StartController.mainFrame.setEnabled(true);
|
@@ -190,7 +185,6 @@
|
|
190
185
|
|
191
186
|
class EquipmentFrame extends JFrame {
|
192
187
|
EquipmentFrame() {
|
193
|
-
// TODO 自動生成されたコンストラクター・スタブ
|
194
188
|
setBounds(60, 60, 500, 500);
|
195
189
|
setVisible(true);
|
196
190
|
}
|
@@ -204,7 +198,6 @@
|
|
204
198
|
JButton cancelBtn = new JButton("cancel");
|
205
199
|
|
206
200
|
PrefFrame() {
|
207
|
-
// TODO 自動生成されたコンストラクター・スタブ
|
208
201
|
setBounds(60, 60, 500, 500);
|
209
202
|
setLayout(new GridLayout(3, 1));
|
210
203
|
getContentPane().add(textField);
|
@@ -218,7 +211,6 @@
|
|
218
211
|
}
|
219
212
|
|
220
213
|
public void actionPerformed(ActionEvent e) {
|
221
|
-
// TODO 自動生成されたメソッド・スタブ
|
222
214
|
if (e.getSource() == saveBtn) {
|
223
215
|
PrefModel.WIDTH = Integer.valueOf(textField.getText());
|
224
216
|
PrefModel.savePrefModel();
|
@@ -228,4 +220,146 @@
|
|
228
220
|
}
|
229
221
|
}
|
230
222
|
|
231
|
-
|
223
|
+
```java
|
224
|
+
public class TextDungeon {
|
225
|
+
|
226
|
+
public static void main(String[] args) {
|
227
|
+
new StartController();
|
228
|
+
}
|
229
|
+
}
|
230
|
+
```
|
231
|
+
|
232
|
+
```java
|
233
|
+
import java.io.FileReader;
|
234
|
+
import java.io.FileWriter;
|
235
|
+
import java.io.IOException;
|
236
|
+
import java.util.Properties;
|
237
|
+
|
238
|
+
public class PrefModel {
|
239
|
+
|
240
|
+
public static int WIDTH, HEIGHT;
|
241
|
+
|
242
|
+
public static void loadPrefModel() {
|
243
|
+
|
244
|
+
FileReader fr;
|
245
|
+
try {
|
246
|
+
fr = new FileReader("C:/java/pref.properties");
|
247
|
+
Properties p = new Properties();
|
248
|
+
p.load(fr);
|
249
|
+
WIDTH = Integer.parseInt(p.getProperty("widthSize"));
|
250
|
+
HEIGHT = Integer.parseInt(p.getProperty("heightSize"));
|
251
|
+
p.getProperty("widthSize");
|
252
|
+
fr.close();
|
253
|
+
} catch (IOException e) {
|
254
|
+
e.printStackTrace();
|
255
|
+
}
|
256
|
+
|
257
|
+
}
|
258
|
+
|
259
|
+
public static void savePrefModel() {
|
260
|
+
FileWriter fw;
|
261
|
+
try {
|
262
|
+
fw = new FileWriter("C:/java/pref.properties");
|
263
|
+
Properties p = new Properties();
|
264
|
+
p.setProperty("widthSize", Integer.valueOf(WIDTH).toString());
|
265
|
+
p.setProperty("heightSize", Integer.valueOf(HEIGHT).toString());
|
266
|
+
p.store(fw, "sizePref");
|
267
|
+
fw.close();
|
268
|
+
} catch (IOException e) {
|
269
|
+
// TODO 自動生成された catch ブロック
|
270
|
+
e.printStackTrace();
|
271
|
+
}
|
272
|
+
}
|
273
|
+
|
274
|
+
public static void createPrefModel() {
|
275
|
+
WIDTH = 700;
|
276
|
+
HEIGHT = 700;
|
277
|
+
FileWriter fw;
|
278
|
+
try {
|
279
|
+
fw = new FileWriter("C:/java/pref.properties");
|
280
|
+
Properties p = new Properties();
|
281
|
+
p.setProperty("widthSize", Integer.valueOf(WIDTH).toString());
|
282
|
+
p.setProperty("heightSize", Integer.valueOf(HEIGHT).toString());
|
283
|
+
p.store(fw, "sizePref");
|
284
|
+
fw.close();
|
285
|
+
} catch (IOException e) {
|
286
|
+
e.printStackTrace();
|
287
|
+
}
|
288
|
+
}
|
289
|
+
}
|
290
|
+
```
|
291
|
+
```java
|
292
|
+
import java.io.Serializable;
|
293
|
+
|
294
|
+
public class PrefDate implements Serializable{
|
295
|
+
public int HEIGT,WIDTH;
|
296
|
+
}
|
297
|
+
|
298
|
+
```
|
299
|
+
```java
|
300
|
+
import java.io.File;
|
301
|
+
import java.io.IOException;
|
302
|
+
import java.util.Vector;
|
303
|
+
|
304
|
+
import com.fasterxml.jackson.databind.JsonNode;
|
305
|
+
import com.fasterxml.jackson.databind.ObjectMapper;
|
306
|
+
|
307
|
+
public class JsonHelper {
|
308
|
+
public Vector<String> getDungeonName() {
|
309
|
+
Vector<String> nameVector = new Vector<String>();
|
310
|
+
File file = new File("C:/java/dungeonname.json");
|
311
|
+
ObjectMapper mapper = new ObjectMapper();
|
312
|
+
JsonNode rootNode;
|
313
|
+
try {
|
314
|
+
rootNode = mapper.readTree(file);
|
315
|
+
JsonNode currentNode;
|
316
|
+
for(int i=0;(currentNode = rootNode.get("dungeon").get(i)) != null; i++) {
|
317
|
+
nameVector.add(currentNode.get("name").textValue());
|
318
|
+
}
|
319
|
+
} catch (IOException e) {
|
320
|
+
e.printStackTrace();
|
321
|
+
}
|
322
|
+
|
323
|
+
return nameVector;
|
324
|
+
}
|
325
|
+
}
|
326
|
+
|
327
|
+
```
|
328
|
+
|
329
|
+
```java
|
330
|
+
|
331
|
+
public class DungeonModel {
|
332
|
+
public static String queDungeonName = "";
|
333
|
+
public static boolean queBool;
|
334
|
+
public static void setDungeonData(String nameString,boolean que){
|
335
|
+
queDungeonName = nameString;
|
336
|
+
queBool = que;
|
337
|
+
}
|
338
|
+
public static String getDungeonName() {
|
339
|
+
return queDungeonName;
|
340
|
+
}
|
341
|
+
}
|
342
|
+
```
|
343
|
+
```java
|
344
|
+
public class TextDungeon {
|
345
|
+
|
346
|
+
public static void main(String[] args) {
|
347
|
+
new StartController();
|
348
|
+
}
|
349
|
+
}
|
350
|
+
```
|
351
|
+
pref.properties
|
352
|
+
#sizePref
|
353
|
+
#Sun Aug 27 20:03:34 JST 2023
|
354
|
+
widthSize=1200
|
355
|
+
heightSize=700
|
356
|
+
|
357
|
+
gungeonname.json
|
358
|
+
{
|
359
|
+
"dungeon":[
|
360
|
+
{"name":"はじまりのもり"},
|
361
|
+
{"name":"げんそうのさばく"},
|
362
|
+
{"name":"しんぴのうみ"}
|
363
|
+
]
|
364
|
+
}
|
365
|
+
|