回答編集履歴

1

全文

2020/12/11 04:22

投稿

TN8001
TN8001

スコア9350

test CHANGED
@@ -16,25 +16,107 @@
16
16
 
17
17
  ```Java
18
18
 
19
- BattleScreenController bsc;// = new BattleScreenController();
19
+ package application;
20
20
 
21
21
 
22
22
 
23
- @Override
23
+ import javafx.application.Application;
24
24
 
25
- public void start(Stage primaryStage) {
25
+ import javafx.fxml.FXMLLoader;
26
26
 
27
- try {
27
+ import javafx.scene.Scene;
28
28
 
29
- // Pane root2 = FXMLLoader.load(getClass().getResource("BattleScreen.fxml"));
29
+ import javafx.scene.input.KeyEvent;
30
30
 
31
- FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("BattleScreen.fxml"));
31
+ import javafx.scene.layout.Pane;
32
32
 
33
- Pane root2 = fxmlLoader.load();
33
+ import javafx.scene.layout.VBox;
34
34
 
35
- sc2 = new Scene(root2);
35
+ import javafx.stage.Stage;
36
36
 
37
+
38
+
39
+
40
+
41
+ public class Main extends Application {
42
+
43
+ public static void main(String[] args) { launch(args); }
44
+
45
+
46
+
47
+ private Scene sc1, sc2;
48
+
49
+ BattleScreenController bsc;// = new BattleScreenController();
50
+
51
+
52
+
53
+ @Override
54
+
55
+ public void start(Stage primaryStage) {
56
+
57
+ try {
58
+
59
+ VBox root1 = (VBox) FXMLLoader.load(getClass().getResource("Sample.fxml"));
60
+
61
+ sc1 = new Scene(root1);
62
+
63
+
64
+
65
+ // Pane root2 = (Pane)FXMLLoader.load(getClass().getResource("BattleScreen.fxml"));
66
+
67
+ FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("BattleScreen.fxml"));
68
+
69
+ Pane root2 = (Pane) fxmlLoader.load();
70
+
71
+ sc2 = new Scene(root2);
72
+
37
- bsc = fxmlLoader.getController();
73
+ bsc = (BattleScreenController) fxmlLoader.getController();
74
+
75
+
76
+
77
+ primaryStage.setScene(sc1);
78
+
79
+ primaryStage.show();
80
+
81
+
82
+
83
+ sc1.setOnKeyPressed(e -> primaryStage.setScene(sc2));
84
+
85
+ sc2.setOnKeyPressed(this::keyPressed);
86
+
87
+ } catch (Exception exception) {
88
+
89
+ exception.printStackTrace();
90
+
91
+ }
92
+
93
+ }
94
+
95
+
96
+
97
+ private void keyPressed(KeyEvent event) {
98
+
99
+ switch (event.getCode()) {
100
+
101
+ case ENTER:
102
+
103
+ bsc.textSet1();
104
+
105
+ break;
106
+
107
+ case BACK_SPACE:
108
+
109
+ break;
110
+
111
+ default:
112
+
113
+ break;
114
+
115
+ }
116
+
117
+ }
118
+
119
+ }
38
120
 
39
121
  ```
40
122