質問編集履歴

1

訂正

2019/01/30 07:03

投稿

P_Beginner
P_Beginner

スコア99

test CHANGED
File without changes
test CHANGED
@@ -16,4 +16,296 @@
16
16
 
17
17
 
18
18
 
19
+
20
+
21
+ ### ファイル構造
22
+
23
+ testパッケージ直下に以下のファイル
24
+
25
+ Login.java
26
+
27
+ LoginController.java
28
+
29
+ MenuController.java
30
+
31
+ Login.fxml
32
+
33
+ Menu.fxml
34
+
35
+
36
+
37
+ (Login.javaのようにMenu.javaも作ったほうがいいんでしょうか・・・?)
38
+
39
+
40
+
41
+
42
+
43
+ ### プログラムソース(Login.java)
44
+
45
+ ```Java
46
+
47
+ package testSystem;
48
+
49
+ import javafx.application.Application;
50
+
51
+ import javafx.fxml.FXMLLoader;
52
+
53
+ import javafx.scene.Parent;
54
+
55
+ import javafx.scene.Scene;
56
+
57
+ import javafx.stage.Stage;
58
+
59
+
60
+
61
+ public class Login extends Application {
62
+
63
+ @Override
64
+
65
+ public void start(Stage primaryStage) {
66
+
67
+ try {
68
+
69
+ //FXMLからのシーングラフの読み込み
70
+
71
+ FXMLLoader loader = new FXMLLoader(getClass().getResource("Login.fxml"));
72
+
73
+ Parent root = loader.load();
74
+
75
+
76
+
77
+ //シーングラフのルートノードを設定したシーンの作成
78
+
79
+ Scene scene = new Scene(root,600,400);
80
+
81
+ //ステージへのシーンの設定
82
+
83
+ primaryStage.setScene(scene);
84
+
85
+ primaryStage.setTitle("ログイン画面");
86
+
87
+ primaryStage.show();
88
+
89
+ } catch(Exception e) {
90
+
91
+ e.printStackTrace();
92
+
93
+ }
94
+
95
+ }
96
+
97
+ public static void main(String[] args) {
98
+
99
+ launch(args);
100
+
101
+ }
102
+
103
+ }
104
+
105
+
106
+
107
+ ```
108
+
109
+
110
+
111
+ ### プログラムソース(LoginController.java)
112
+
113
+ ```Java
114
+
115
+ package testSystem;
116
+
117
+
118
+
119
+ import java.net.URL;
120
+
121
+ import java.util.ResourceBundle;
122
+
123
+
124
+
125
+ import javafx.beans.binding.BooleanBinding;
126
+
127
+ import javafx.event.ActionEvent;
128
+
129
+ import javafx.fxml.FXML;
130
+
131
+ import javafx.scene.control.Button;
132
+
133
+ import javafx.scene.control.Hyperlink;
134
+
135
+ import javafx.scene.control.Label;
136
+
137
+ import javafx.scene.control.PasswordField;
138
+
139
+ import javafx.scene.control.TextField;
140
+
141
+
142
+
143
+ public class LoginController {
144
+
145
+
146
+
147
+ @FXML
148
+
149
+ private ResourceBundle resources;
150
+
151
+
152
+
153
+ @FXML
154
+
155
+ private URL location;
156
+
157
+
158
+
159
+ @FXML
160
+
161
+ private TextField id;
162
+
163
+
164
+
165
+ @FXML
166
+
167
+ private PasswordField passwd;
168
+
169
+
170
+
171
+ @FXML
172
+
173
+ private Button loginButton;
174
+
175
+
176
+
177
+ @FXML
178
+
179
+ private Hyperlink createLink;
180
+
181
+
182
+
183
+ @FXML
184
+
185
+ private Label warning;
186
+
187
+
188
+
189
+ @FXML
190
+
191
+ void initialize() {
192
+
193
+ assert id != null : "fx:id=\"id\" was not injected: check your FXML file 'Login.fxml'.";
194
+
195
+ assert passwd != null : "fx:id=\"passwd\" was not injected: check your FXML file 'Login.fxml'.";
196
+
197
+ assert loginButton != null : "fx:id=\"loginButton\" was not injected: check your FXML file 'Login.fxml'.";
198
+
199
+ assert createLink != null : "fx:id=\"createLink\" was not injected: check your FXML file 'Login.fxml'.";
200
+
201
+ assert warning != null : "fx:id=\"warning\" was not injected: check your FXML file 'Login.fxml'.";
202
+
203
+ BooleanBinding idIsEmpty = id.textProperty().isEmpty();
204
+
205
+ BooleanBinding passwdIsEmpty = passwd.textProperty().isEmpty();
206
+
207
+ loginButton.disableProperty().bind(idIsEmpty.or(passwdIsEmpty));
208
+
209
+ }
210
+
211
+
212
+
213
+ @FXML
214
+
215
+ public void OnClick(ActionEvent event) {
216
+
217
+ String idNumber = id.getText();
218
+
219
+ String password = passwd.getText();
220
+
221
+
222
+
223
+ if(idNumber.equals("test")&&password.equals("test")) {
224
+
19
- 現段階でできているソースで判断したい場合は[前回の質問](https://teratail.com/questions/171397)を参照してください.
225
+ System.out.print("id:"+idNumber+" pass:"+password+" → ");
226
+
227
+ System.out.println("成功");
228
+
229
+ id.setText("");
230
+
231
+ passwd.setText("");
232
+
233
+ warning.setText("OK");//確認用,通常はここで画面遷移
234
+
235
+ }
236
+
237
+ else {
238
+
239
+ System.out.print("id:"+idNumber+" pass:"+password+" → ");
240
+
241
+ System.out.println("失敗");
242
+
243
+ id.setText("");
244
+
245
+ passwd.setText("");
246
+
247
+ warning.setText("※正しいアカウント情報を入力してください");
248
+
249
+ }
250
+
251
+ }
252
+
253
+ }
254
+
255
+
256
+
257
+ ```
258
+
259
+
260
+
261
+ ### プログラムソース(MenuController.java)
262
+
263
+ まあ,テスト用なので遷移先の画面はまだ作っていません.
264
+
265
+ ただ,ログイン状態からログアウトもできるようにしたいので,こちらからログイン画面(Login.fxml)へ遷移できるようにもしたいです.
266
+
267
+ ```Java
268
+
269
+ package testSystem;
270
+
271
+
272
+
273
+ import java.net.URL;
274
+
275
+ import java.util.ResourceBundle;
276
+
277
+
278
+
279
+ import javafx.fxml.FXML;
280
+
281
+
282
+
283
+ public class MenuController {
284
+
285
+
286
+
287
+ @FXML
288
+
289
+ private ResourceBundle resources;
290
+
291
+
292
+
293
+ @FXML
294
+
295
+ private URL location;
296
+
297
+
298
+
299
+ @FXML
300
+
301
+ void initialize() {
302
+
303
+ }
304
+
305
+ }
306
+
307
+
308
+
309
+
310
+
311
+ ```