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

質問編集履歴

3

書式改善

2020/08/24 00:02

投稿

wasabi723
wasabi723

スコア1

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

2

書式改善

2020/08/24 00:02

投稿

wasabi723
wasabi723

スコア1

title CHANGED
File without changes
body CHANGED
@@ -1,6 +1,5 @@
1
1
  ``````StartViewController.java```
2
2
  //このクラスでProducutInfoクラスのオブジェクトを作成し初期値を入力したい
3
- ```
4
3
  package application;
5
4
 
6
5
  import java.io.IOException;
@@ -69,6 +68,7 @@
69
68
  }
70
69
  ```
71
70
  ProductInfo.java
71
+ ```
72
72
  //商品情報を格納するクラス
73
73
  package application;
74
74
 
@@ -123,8 +123,8 @@
123
123
  return stock;
124
124
  }
125
125
  }
126
+ ```BuyViewController.java
126
127
  ```
127
- BuyViewController.Java
128
128
  //この画面に商品情報を表示したい
129
129
  package application;
130
130
 
@@ -163,7 +163,6 @@
163
163
 
164
164
  }
165
165
 
166
- ```
167
166
 
168
167
  ```### 前提・実現したいこと
169
168
  JavaFxを用いて自動販売機を模したシステムを大学の課題で作成しています。

1

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

2020/08/24 00:01

投稿

wasabi723
wasabi723

スコア1

title CHANGED
File without changes
body CHANGED
@@ -1,4 +1,171 @@
1
+ ``````StartViewController.java```
2
+ //このクラスでProducutInfoクラスのオブジェクトを作成し初期値を入力したい
3
+ ```
4
+ package application;
5
+
6
+ import java.io.IOException;
7
+
8
+ import javafx.event.ActionEvent;
9
+ import javafx.fxml.FXML;
10
+ import javafx.fxml.FXMLLoader;
11
+ import javafx.scene.Scene;
12
+ import javafx.scene.control.Button;
13
+ import javafx.scene.control.Label;
14
+ import javafx.scene.layout.BorderPane;
15
+ import javafx.stage.Stage;
16
+
17
+ public class StartViewController {
18
+
19
+ @FXML private Button button_Start;
20
+ @FXML private Button button_End;
21
+ @FXML private Label label_title;
22
+
23
+ //商品情報の初期化
24
+ String name[] = {"水","お茶","コーヒー","オレンジジュース","ヤクルト","コーラ"};
25
+ int price[] = {90,100,110,120,130,80,150} ;
26
+ int temp[] = {1,2,2,1,2,2};
27
+ int shape[] = {1,2,1,1,2,2};
28
+ int stock[] = {2,2,2,2,2,2};
29
+
30
+ @FXML
31
+ void onStartClicked(ActionEvent event) {
32
+ try {
33
+ showSecondWindow();
34
+ } catch (Exception ex) {
35
+ System.out.println(ex.getMessage());
36
+ }
37
+ }
38
+ void showSecondWindow() throws IOException
39
+ {
40
+ /*ProductInfo p = new ProductInfo();
41
+ p.Product1(name[0],price[0],temp[0],shape[0],stock[0]);
42
+ p.Product2(name[1],price[1],temp[1],shape[1],stock[1]);
43
+ p.Product3(name[2],price[2],temp[2],shape[2],stock[2]);
44
+ p.Product4(name[3],price[3],temp[3],shape[3],stock[3]);
45
+ p.Product5(name[4],price[4],temp[4],shape[4],stock[4]);
46
+ p.Product6(name[5],price[5],temp[5],shape[5],stock[5]);
47
+ */
48
+
49
+
50
+ //for(int i = 0;i < product.length;i++) {
51
+ // product[i].Product(name[i], price[i], temp[i], shape[i], stock[i]);
52
+ //}
53
+
54
+ FXMLLoader loader = new FXMLLoader(getClass().getResource("ModeView.fxml"));
55
+ BorderPane root = (BorderPane) loader.load();
56
+ Scene scene = new Scene(root);
57
+ Stage stage = new Stage();
58
+ stage.setScene(scene);
59
+
60
+ stage.showAndWait();
61
+ }
62
+
63
+ @FXML
64
+ void onEndClicked(ActionEvent event) {
65
+
66
+ }
67
+
68
+
69
+ }
70
+ ```
71
+ ProductInfo.java
72
+ //商品情報を格納するクラス
73
+ package application;
74
+
75
+ public class ProductInfo
76
+ {
77
+ static String name; //商品名
78
+ static int price; //価格
79
+ static int temp; //温度
80
+ static int shape; //形状
81
+ static int stock; //在庫数
82
+ static String strTemp;
83
+ static String strShape;
84
+
85
+ public void Product(String name2, int price2, int temp2, int shape2, int stock2)
86
+ {
87
+
88
+ name = name2;
89
+ price = price2;
90
+ temp = temp2;
91
+ shape = shape2;
92
+ stock = stock2;
93
+
94
+ if (shape == 1)
95
+ strShape = "ペットボトル";
96
+ else
97
+ strShape = "缶";
98
+ if (temp == 1)
99
+ strTemp = "温";
100
+ else
101
+ strTemp = "冷";
102
+ }
103
+
104
+ public String outName()
105
+ {
106
+ return name;
107
+
108
+ }
109
+ public int outPrice()
110
+ {
111
+ return price;
112
+ }
113
+ public String outTemp()
114
+ {
115
+ return strTemp;
116
+ }
117
+ public String outShape()
118
+ {
119
+ return strShape;
120
+ }
121
+ public int outStock()
122
+ {
123
+ return stock;
124
+ }
125
+ }
126
+ ```
127
+ BuyViewController.Java
128
+ //この画面に商品情報を表示したい
129
+ package application;
130
+
131
+ import javafx.event.ActionEvent;
132
+ import javafx.fxml.FXML;
133
+ import javafx.scene.Node;
134
+ import javafx.scene.Scene;
135
+ import javafx.scene.control.Button;
136
+ import javafx.scene.control.Label;
137
+ import javafx.stage.Window;
138
+
139
+
140
+ public class BuyViewController {
141
+
142
+ @FXML private Label lavel_Title;
143
+ @FXML private Label lavel_Sumitted;
144
+ @FXML private Button button_Back;
145
+ @FXML private Label shohin1;
146
+ @FXML private Label shohin2;
147
+ @FXML private Label shohin3;
148
+ @FXML private Label shohin4;
149
+ @FXML private Label shohin5;
150
+ @FXML private Label shohin6;
151
+
152
+ void output()
153
+ {
154
+
155
+ }
156
+ @FXML
157
+ void onBackClicked(ActionEvent event) {
158
+ Scene scene = ((Node) event.getSource()).getScene();
159
+ Window window = scene.getWindow();
160
+ window.hide();
161
+
162
+ }
163
+
164
+ }
165
+
166
+ ```
167
+
1
- ### 前提・実現したいこと
168
+ ```### 前提・実現したいこと
2
169
  JavaFxを用いて自動販売機を模したシステムを大学の課題で作成しています。
3
170
  商品情報をクラス間(ウインドウ間)で値を保持して表示したり、在庫数の変更などを行いたいです。
4
- 現在Aクラスで商品情報(商品名や価格)をまとめるクラスBのオブジェクトを作成し初期値を代入しました。これを今度はクラスCで表示したいです。
171
+ 現在StartViewControllerクラスで商品情報(商品名や価格)をまとめるProductInfoクラスのオブジェクトを作成し初期値を代入しました。これを今度はBuyViewControllerクラスで表示したいです。