回答編集履歴
1
全文
answer
CHANGED
@@ -7,16 +7,57 @@
|
|
7
7
|
コントローラを取得するにはこのようにします。
|
8
8
|
|
9
9
|
```Java
|
10
|
-
|
10
|
+
package application;
|
11
11
|
|
12
|
+
import javafx.application.Application;
|
13
|
+
import javafx.fxml.FXMLLoader;
|
14
|
+
import javafx.scene.Scene;
|
15
|
+
import javafx.scene.input.KeyEvent;
|
16
|
+
import javafx.scene.layout.Pane;
|
17
|
+
import javafx.scene.layout.VBox;
|
18
|
+
import javafx.stage.Stage;
|
19
|
+
|
20
|
+
|
21
|
+
public class Main extends Application {
|
22
|
+
public static void main(String[] args) { launch(args); }
|
23
|
+
|
24
|
+
private Scene sc1, sc2;
|
25
|
+
BattleScreenController bsc;// = new BattleScreenController();
|
26
|
+
|
12
|
-
@Override
|
27
|
+
@Override
|
13
|
-
public void start(Stage primaryStage) {
|
28
|
+
public void start(Stage primaryStage) {
|
14
|
-
|
29
|
+
try {
|
30
|
+
VBox root1 = (VBox) FXMLLoader.load(getClass().getResource("Sample.fxml"));
|
31
|
+
sc1 = new Scene(root1);
|
32
|
+
|
15
|
-
//
|
33
|
+
// Pane root2 = (Pane)FXMLLoader.load(getClass().getResource("BattleScreen.fxml"));
|
16
|
-
|
34
|
+
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("BattleScreen.fxml"));
|
17
|
-
|
35
|
+
Pane root2 = (Pane) fxmlLoader.load();
|
18
|
-
|
36
|
+
sc2 = new Scene(root2);
|
19
|
-
|
37
|
+
bsc = (BattleScreenController) fxmlLoader.getController();
|
38
|
+
|
39
|
+
primaryStage.setScene(sc1);
|
40
|
+
primaryStage.show();
|
41
|
+
|
42
|
+
sc1.setOnKeyPressed(e -> primaryStage.setScene(sc2));
|
43
|
+
sc2.setOnKeyPressed(this::keyPressed);
|
44
|
+
} catch (Exception exception) {
|
45
|
+
exception.printStackTrace();
|
46
|
+
}
|
47
|
+
}
|
48
|
+
|
49
|
+
private void keyPressed(KeyEvent event) {
|
50
|
+
switch (event.getCode()) {
|
51
|
+
case ENTER:
|
52
|
+
bsc.textSet1();
|
53
|
+
break;
|
54
|
+
case BACK_SPACE:
|
55
|
+
break;
|
56
|
+
default:
|
57
|
+
break;
|
58
|
+
}
|
59
|
+
}
|
60
|
+
}
|
20
61
|
```
|
21
62
|
|
22
63
|
> またプレイヤーの入力したキーによって画面にテキストを表示するのによい方法があったら教えていただきたいです。
|