質問編集履歴

3

書式改善

2020/08/24 00:02

投稿

wasabi723
wasabi723

スコア1

test CHANGED
File without changes
test CHANGED
@@ -1,4 +1,8 @@
1
- ``````StartViewController.java```
1
+ StartViewController.java
2
+
3
+ ``````
4
+
5
+
2
6
 
3
7
  //このクラスでProducutInfoクラスのオブジェクトを作成し初期値を入力したい
4
8
 

2

書式改善

2020/08/24 00:02

投稿

wasabi723
wasabi723

スコア1

test CHANGED
File without changes
test CHANGED
@@ -2,13 +2,259 @@
2
2
 
3
3
  //このクラスでProducutInfoクラスのオブジェクトを作成し初期値を入力したい
4
4
 
5
+ package application;
6
+
7
+
8
+
9
+ import java.io.IOException;
10
+
11
+
12
+
13
+ import javafx.event.ActionEvent;
14
+
15
+ import javafx.fxml.FXML;
16
+
17
+ import javafx.fxml.FXMLLoader;
18
+
19
+ import javafx.scene.Scene;
20
+
21
+ import javafx.scene.control.Button;
22
+
23
+ import javafx.scene.control.Label;
24
+
25
+ import javafx.scene.layout.BorderPane;
26
+
27
+ import javafx.stage.Stage;
28
+
29
+
30
+
31
+ public class StartViewController {
32
+
33
+
34
+
35
+ @FXML private Button button_Start;
36
+
37
+ @FXML private Button button_End;
38
+
39
+ @FXML private Label label_title;
40
+
41
+
42
+
43
+ //商品情報の初期化
44
+
45
+ String name[] = {"水","お茶","コーヒー","オレンジジュース","ヤクルト","コーラ"};
46
+
47
+ int price[] = {90,100,110,120,130,80,150} ;
48
+
49
+ int temp[] = {1,2,2,1,2,2};
50
+
51
+ int shape[] = {1,2,1,1,2,2};
52
+
53
+ int stock[] = {2,2,2,2,2,2};
54
+
55
+
56
+
57
+ @FXML
58
+
59
+ void onStartClicked(ActionEvent event) {
60
+
61
+ try {
62
+
63
+ showSecondWindow();
64
+
65
+ } catch (Exception ex) {
66
+
67
+ System.out.println(ex.getMessage());
68
+
69
+ }
70
+
71
+ }
72
+
73
+ void showSecondWindow() throws IOException
74
+
75
+ {
76
+
77
+ /*ProductInfo p = new ProductInfo();
78
+
79
+ p.Product1(name[0],price[0],temp[0],shape[0],stock[0]);
80
+
81
+ p.Product2(name[1],price[1],temp[1],shape[1],stock[1]);
82
+
83
+ p.Product3(name[2],price[2],temp[2],shape[2],stock[2]);
84
+
85
+ p.Product4(name[3],price[3],temp[3],shape[3],stock[3]);
86
+
87
+ p.Product5(name[4],price[4],temp[4],shape[4],stock[4]);
88
+
89
+ p.Product6(name[5],price[5],temp[5],shape[5],stock[5]);
90
+
91
+ */
92
+
93
+
94
+
95
+
96
+
97
+ //for(int i = 0;i < product.length;i++) {
98
+
99
+ // product[i].Product(name[i], price[i], temp[i], shape[i], stock[i]);
100
+
101
+ //}
102
+
103
+
104
+
105
+ FXMLLoader loader = new FXMLLoader(getClass().getResource("ModeView.fxml"));
106
+
107
+ BorderPane root = (BorderPane) loader.load();
108
+
109
+ Scene scene = new Scene(root);
110
+
111
+ Stage stage = new Stage();
112
+
113
+ stage.setScene(scene);
114
+
115
+
116
+
117
+ stage.showAndWait();
118
+
119
+ }
120
+
121
+
122
+
123
+ @FXML
124
+
125
+ void onEndClicked(ActionEvent event) {
126
+
127
+
128
+
129
+ }
130
+
131
+
132
+
133
+
134
+
135
+ }
136
+
5
137
  ```
6
138
 
139
+ ProductInfo.java
140
+
141
+ ```
142
+
143
+ //商品情報を格納するクラス
144
+
7
145
  package application;
8
146
 
9
147
 
10
148
 
149
+ public class ProductInfo
150
+
151
+ {
152
+
153
+ static String name; //商品名
154
+
155
+ static int price; //価格
156
+
157
+ static int temp; //温度
158
+
159
+ static int shape; //形状
160
+
161
+ static int stock; //在庫数
162
+
163
+ static String strTemp;
164
+
165
+ static String strShape;
166
+
167
+
168
+
169
+ public void Product(String name2, int price2, int temp2, int shape2, int stock2)
170
+
171
+ {
172
+
173
+
174
+
175
+ name = name2;
176
+
177
+ price = price2;
178
+
179
+ temp = temp2;
180
+
181
+ shape = shape2;
182
+
183
+ stock = stock2;
184
+
185
+
186
+
187
+ if (shape == 1)
188
+
189
+ strShape = "ペットボトル";
190
+
191
+ else
192
+
193
+ strShape = "缶";
194
+
195
+ if (temp == 1)
196
+
197
+ strTemp = "温";
198
+
199
+ else
200
+
201
+ strTemp = "冷";
202
+
203
+ }
204
+
205
+
206
+
207
+ public String outName()
208
+
209
+ {
210
+
211
+ return name;
212
+
213
+
214
+
215
+ }
216
+
217
+ public int outPrice()
218
+
219
+ {
220
+
221
+ return price;
222
+
223
+ }
224
+
225
+ public String outTemp()
226
+
227
+ {
228
+
229
+ return strTemp;
230
+
231
+ }
232
+
233
+ public String outShape()
234
+
235
+ {
236
+
237
+ return strShape;
238
+
239
+ }
240
+
241
+ public int outStock()
242
+
243
+ {
244
+
245
+ return stock;
246
+
247
+ }
248
+
249
+ }
250
+
251
+ ```BuyViewController.java
252
+
253
+ ```
254
+
255
+ //この画面に商品情報を表示したい
256
+
11
- import java.io.IOException;
257
+ package application;
12
258
 
13
259
 
14
260
 
@@ -16,7 +262,7 @@
16
262
 
17
263
  import javafx.fxml.FXML;
18
264
 
19
- import javafx.fxml.FXMLLoader;
265
+ import javafx.scene.Node;
20
266
 
21
267
  import javafx.scene.Scene;
22
268
 
@@ -24,311 +270,63 @@
24
270
 
25
271
  import javafx.scene.control.Label;
26
272
 
27
- import javafx.scene.layout.BorderPane;
28
-
29
- import javafx.stage.Stage;
273
+ import javafx.stage.Window;
30
-
31
-
32
-
274
+
275
+
276
+
277
+
278
+
33
- public class StartViewController {
279
+ public class BuyViewController {
34
-
35
-
36
-
37
- @FXML private Button button_Start;
280
+
38
-
39
- @FXML private Button button_End;
281
+
40
-
282
+
41
- @FXML private Label label_title;
283
+ @FXML private Label lavel_Title;
42
-
43
-
44
-
45
- //商品情報の初期化
284
+
46
-
47
- String name[] = {"水","お茶","コーヒー","オレンジジュース","ヤクルト","コーラ"};
48
-
49
- int price[] = {90,100,110,120,130,80,150} ;
285
+ @FXML private Label lavel_Sumitted;
50
-
286
+
51
- int temp[] = {1,2,2,1,2,2};
287
+ @FXML private Button button_Back;
52
-
288
+
53
- int shape[] = {1,2,1,1,2,2};
289
+ @FXML private Label shohin1;
54
-
290
+
55
- int stock[] = {2,2,2,2,2,2};
291
+ @FXML private Label shohin2;
292
+
56
-
293
+ @FXML private Label shohin3;
294
+
57
-
295
+ @FXML private Label shohin4;
296
+
297
+ @FXML private Label shohin5;
298
+
299
+ @FXML private Label shohin6;
300
+
301
+
302
+
303
+ void output()
304
+
305
+ {
306
+
307
+
308
+
309
+ }
58
310
 
59
311
  @FXML
60
312
 
61
- void onStartClicked(ActionEvent event) {
313
+ void onBackClicked(ActionEvent event) {
314
+
62
-
315
+ Scene scene = ((Node) event.getSource()).getScene();
316
+
63
- try {
317
+ Window window = scene.getWindow();
64
-
318
+
65
- showSecondWindow();
319
+ window.hide();
66
-
67
- } catch (Exception ex) {
320
+
68
-
69
- System.out.println(ex.getMessage());
321
+
70
-
71
- }
72
322
 
73
323
  }
74
324
 
75
- void showSecondWindow() throws IOException
76
-
77
- {
78
-
79
- /*ProductInfo p = new ProductInfo();
80
-
81
- p.Product1(name[0],price[0],temp[0],shape[0],stock[0]);
82
-
83
- p.Product2(name[1],price[1],temp[1],shape[1],stock[1]);
84
-
85
- p.Product3(name[2],price[2],temp[2],shape[2],stock[2]);
86
-
87
- p.Product4(name[3],price[3],temp[3],shape[3],stock[3]);
88
-
89
- p.Product5(name[4],price[4],temp[4],shape[4],stock[4]);
90
-
91
- p.Product6(name[5],price[5],temp[5],shape[5],stock[5]);
92
-
93
- */
94
-
95
-
96
-
97
-
98
-
99
- //for(int i = 0;i < product.length;i++) {
100
-
101
- // product[i].Product(name[i], price[i], temp[i], shape[i], stock[i]);
102
-
103
- //}
104
-
105
-
106
-
107
- FXMLLoader loader = new FXMLLoader(getClass().getResource("ModeView.fxml"));
108
-
109
- BorderPane root = (BorderPane) loader.load();
110
-
111
- Scene scene = new Scene(root);
112
-
113
- Stage stage = new Stage();
114
-
115
- stage.setScene(scene);
116
-
117
-
118
-
119
- stage.showAndWait();
120
-
121
- }
122
-
123
-
124
-
125
- @FXML
126
-
127
- void onEndClicked(ActionEvent event) {
128
-
129
-
130
-
131
- }
132
-
133
-
134
-
135
325
 
136
326
 
137
327
  }
138
328
 
139
- ```
329
+
140
-
141
- ProductInfo.java
142
-
143
- //商品情報を格納するクラス
144
-
145
- package application;
146
-
147
-
148
-
149
- public class ProductInfo
150
-
151
- {
152
-
153
- static String name; //商品名
154
-
155
- static int price; //価格
156
-
157
- static int temp; //温度
158
-
159
- static int shape; //形状
160
-
161
- static int stock; //在庫数
162
-
163
- static String strTemp;
164
-
165
- static String strShape;
166
-
167
-
168
-
169
- public void Product(String name2, int price2, int temp2, int shape2, int stock2)
170
-
171
- {
172
-
173
-
174
-
175
- name = name2;
176
-
177
- price = price2;
178
-
179
- temp = temp2;
180
-
181
- shape = shape2;
182
-
183
- stock = stock2;
184
-
185
-
186
-
187
- if (shape == 1)
188
-
189
- strShape = "ペットボトル";
190
-
191
- else
192
-
193
- strShape = "缶";
194
-
195
- if (temp == 1)
196
-
197
- strTemp = "温";
198
-
199
- else
200
-
201
- strTemp = "冷";
202
-
203
- }
204
-
205
-
206
-
207
- public String outName()
208
-
209
- {
210
-
211
- return name;
212
-
213
-
214
-
215
- }
216
-
217
- public int outPrice()
218
-
219
- {
220
-
221
- return price;
222
-
223
- }
224
-
225
- public String outTemp()
226
-
227
- {
228
-
229
- return strTemp;
230
-
231
- }
232
-
233
- public String outShape()
234
-
235
- {
236
-
237
- return strShape;
238
-
239
- }
240
-
241
- public int outStock()
242
-
243
- {
244
-
245
- return stock;
246
-
247
- }
248
-
249
- }
250
-
251
- ```
252
-
253
- BuyViewController.Java
254
-
255
- //この画面に商品情報を表示したい
256
-
257
- package application;
258
-
259
-
260
-
261
- import javafx.event.ActionEvent;
262
-
263
- import javafx.fxml.FXML;
264
-
265
- import javafx.scene.Node;
266
-
267
- import javafx.scene.Scene;
268
-
269
- import javafx.scene.control.Button;
270
-
271
- import javafx.scene.control.Label;
272
-
273
- import javafx.stage.Window;
274
-
275
-
276
-
277
-
278
-
279
- public class BuyViewController {
280
-
281
-
282
-
283
- @FXML private Label lavel_Title;
284
-
285
- @FXML private Label lavel_Sumitted;
286
-
287
- @FXML private Button button_Back;
288
-
289
- @FXML private Label shohin1;
290
-
291
- @FXML private Label shohin2;
292
-
293
- @FXML private Label shohin3;
294
-
295
- @FXML private Label shohin4;
296
-
297
- @FXML private Label shohin5;
298
-
299
- @FXML private Label shohin6;
300
-
301
-
302
-
303
- void output()
304
-
305
- {
306
-
307
-
308
-
309
- }
310
-
311
- @FXML
312
-
313
- void onBackClicked(ActionEvent event) {
314
-
315
- Scene scene = ((Node) event.getSource()).getScene();
316
-
317
- Window window = scene.getWindow();
318
-
319
- window.hide();
320
-
321
-
322
-
323
- }
324
-
325
-
326
-
327
- }
328
-
329
-
330
-
331
- ```
332
330
 
333
331
 
334
332
 

1

.javaファイルを追加しました。ロジックが検討できずうまく記載ができていません。

2020/08/24 00:01

投稿

wasabi723
wasabi723

スコア1

test CHANGED
File without changes
test CHANGED
@@ -1,7 +1,341 @@
1
+ ``````StartViewController.java```
2
+
3
+ //このクラスでProducutInfoクラスのオブジェクトを作成し初期値を入力したい
4
+
5
+ ```
6
+
7
+ package application;
8
+
9
+
10
+
11
+ import java.io.IOException;
12
+
13
+
14
+
15
+ import javafx.event.ActionEvent;
16
+
17
+ import javafx.fxml.FXML;
18
+
19
+ import javafx.fxml.FXMLLoader;
20
+
21
+ import javafx.scene.Scene;
22
+
23
+ import javafx.scene.control.Button;
24
+
25
+ import javafx.scene.control.Label;
26
+
27
+ import javafx.scene.layout.BorderPane;
28
+
29
+ import javafx.stage.Stage;
30
+
31
+
32
+
33
+ public class StartViewController {
34
+
35
+
36
+
37
+ @FXML private Button button_Start;
38
+
39
+ @FXML private Button button_End;
40
+
41
+ @FXML private Label label_title;
42
+
43
+
44
+
45
+ //商品情報の初期化
46
+
47
+ String name[] = {"水","お茶","コーヒー","オレンジジュース","ヤクルト","コーラ"};
48
+
49
+ int price[] = {90,100,110,120,130,80,150} ;
50
+
51
+ int temp[] = {1,2,2,1,2,2};
52
+
53
+ int shape[] = {1,2,1,1,2,2};
54
+
55
+ int stock[] = {2,2,2,2,2,2};
56
+
57
+
58
+
59
+ @FXML
60
+
61
+ void onStartClicked(ActionEvent event) {
62
+
63
+ try {
64
+
65
+ showSecondWindow();
66
+
67
+ } catch (Exception ex) {
68
+
69
+ System.out.println(ex.getMessage());
70
+
71
+ }
72
+
73
+ }
74
+
75
+ void showSecondWindow() throws IOException
76
+
77
+ {
78
+
79
+ /*ProductInfo p = new ProductInfo();
80
+
81
+ p.Product1(name[0],price[0],temp[0],shape[0],stock[0]);
82
+
83
+ p.Product2(name[1],price[1],temp[1],shape[1],stock[1]);
84
+
85
+ p.Product3(name[2],price[2],temp[2],shape[2],stock[2]);
86
+
87
+ p.Product4(name[3],price[3],temp[3],shape[3],stock[3]);
88
+
89
+ p.Product5(name[4],price[4],temp[4],shape[4],stock[4]);
90
+
91
+ p.Product6(name[5],price[5],temp[5],shape[5],stock[5]);
92
+
93
+ */
94
+
95
+
96
+
97
+
98
+
99
+ //for(int i = 0;i < product.length;i++) {
100
+
101
+ // product[i].Product(name[i], price[i], temp[i], shape[i], stock[i]);
102
+
103
+ //}
104
+
105
+
106
+
107
+ FXMLLoader loader = new FXMLLoader(getClass().getResource("ModeView.fxml"));
108
+
109
+ BorderPane root = (BorderPane) loader.load();
110
+
111
+ Scene scene = new Scene(root);
112
+
113
+ Stage stage = new Stage();
114
+
115
+ stage.setScene(scene);
116
+
117
+
118
+
119
+ stage.showAndWait();
120
+
121
+ }
122
+
123
+
124
+
125
+ @FXML
126
+
127
+ void onEndClicked(ActionEvent event) {
128
+
129
+
130
+
131
+ }
132
+
133
+
134
+
135
+
136
+
137
+ }
138
+
139
+ ```
140
+
141
+ ProductInfo.java
142
+
143
+ //商品情報を格納するクラス
144
+
145
+ package application;
146
+
147
+
148
+
149
+ public class ProductInfo
150
+
151
+ {
152
+
153
+ static String name; //商品名
154
+
155
+ static int price; //価格
156
+
157
+ static int temp; //温度
158
+
159
+ static int shape; //形状
160
+
161
+ static int stock; //在庫数
162
+
163
+ static String strTemp;
164
+
165
+ static String strShape;
166
+
167
+
168
+
169
+ public void Product(String name2, int price2, int temp2, int shape2, int stock2)
170
+
171
+ {
172
+
173
+
174
+
175
+ name = name2;
176
+
177
+ price = price2;
178
+
179
+ temp = temp2;
180
+
181
+ shape = shape2;
182
+
183
+ stock = stock2;
184
+
185
+
186
+
187
+ if (shape == 1)
188
+
189
+ strShape = "ペットボトル";
190
+
191
+ else
192
+
193
+ strShape = "缶";
194
+
195
+ if (temp == 1)
196
+
197
+ strTemp = "温";
198
+
199
+ else
200
+
201
+ strTemp = "冷";
202
+
203
+ }
204
+
205
+
206
+
207
+ public String outName()
208
+
209
+ {
210
+
211
+ return name;
212
+
213
+
214
+
215
+ }
216
+
217
+ public int outPrice()
218
+
219
+ {
220
+
221
+ return price;
222
+
223
+ }
224
+
225
+ public String outTemp()
226
+
227
+ {
228
+
229
+ return strTemp;
230
+
231
+ }
232
+
233
+ public String outShape()
234
+
235
+ {
236
+
237
+ return strShape;
238
+
239
+ }
240
+
241
+ public int outStock()
242
+
243
+ {
244
+
245
+ return stock;
246
+
247
+ }
248
+
249
+ }
250
+
251
+ ```
252
+
253
+ BuyViewController.Java
254
+
255
+ //この画面に商品情報を表示したい
256
+
257
+ package application;
258
+
259
+
260
+
261
+ import javafx.event.ActionEvent;
262
+
263
+ import javafx.fxml.FXML;
264
+
265
+ import javafx.scene.Node;
266
+
267
+ import javafx.scene.Scene;
268
+
269
+ import javafx.scene.control.Button;
270
+
271
+ import javafx.scene.control.Label;
272
+
273
+ import javafx.stage.Window;
274
+
275
+
276
+
277
+
278
+
279
+ public class BuyViewController {
280
+
281
+
282
+
283
+ @FXML private Label lavel_Title;
284
+
285
+ @FXML private Label lavel_Sumitted;
286
+
287
+ @FXML private Button button_Back;
288
+
289
+ @FXML private Label shohin1;
290
+
291
+ @FXML private Label shohin2;
292
+
293
+ @FXML private Label shohin3;
294
+
295
+ @FXML private Label shohin4;
296
+
297
+ @FXML private Label shohin5;
298
+
299
+ @FXML private Label shohin6;
300
+
301
+
302
+
303
+ void output()
304
+
305
+ {
306
+
307
+
308
+
309
+ }
310
+
311
+ @FXML
312
+
313
+ void onBackClicked(ActionEvent event) {
314
+
315
+ Scene scene = ((Node) event.getSource()).getScene();
316
+
317
+ Window window = scene.getWindow();
318
+
319
+ window.hide();
320
+
321
+
322
+
323
+ }
324
+
325
+
326
+
327
+ }
328
+
329
+
330
+
331
+ ```
332
+
333
+
334
+
1
- ### 前提・実現したいこと
335
+ ```### 前提・実現したいこと
2
336
 
3
337
  JavaFxを用いて自動販売機を模したシステムを大学の課題で作成しています。
4
338
 
5
339
  商品情報をクラス間(ウインドウ間)で値を保持して表示したり、在庫数の変更などを行いたいです。
6
340
 
7
- 現在Aクラスで商品情報(商品名や価格)をまとめるクラスBのオブジェクトを作成し初期値を代入しました。これを今度はクラスCで表示したいです。
341
+ 現在StartViewControllerクラスで商品情報(商品名や価格)をまとめるProductInfoクラスのオブジェクトを作成し初期値を代入しました。これを今度はBuyViewControllerクラスで表示したいです。