質問編集履歴
1
コードを記載致しました
title
CHANGED
|
File without changes
|
body
CHANGED
|
@@ -1,4 +1,104 @@
|
|
|
1
1
|
JavafxのGUIで五目並べのアプリケーションを作っているのですが
|
|
2
2
|
タイトル画面からゲーム画面に遷移する方法が分かりません。
|
|
3
3
|
何か良い方法がありましたら教えてください。
|
|
4
|
-
よろしくお願い致します。
|
|
4
|
+
よろしくお願い致します。
|
|
5
|
+
(なお、タイトル画面、ゲーム画面共にまだまだ未完成の状態となっております)
|
|
6
|
+
```java
|
|
7
|
+
コード(タイトル画面)
|
|
8
|
+
import javafx.application.Application;
|
|
9
|
+
import javafx.event.ActionEvent;
|
|
10
|
+
import javafx.event.EventHandler;
|
|
11
|
+
import javafx.scene.Scene;
|
|
12
|
+
import javafx.scene.control.Alert;
|
|
13
|
+
import javafx.scene.control.Button;
|
|
14
|
+
import javafx.scene.control.Label;
|
|
15
|
+
import javafx.scene.layout.BorderPane;
|
|
16
|
+
import javafx.stage.Stage;
|
|
17
|
+
|
|
18
|
+
public class samaple extends Application{
|
|
19
|
+
|
|
20
|
+
private Label lb;
|
|
21
|
+
private Button bt1, bt2;
|
|
22
|
+
|
|
23
|
+
public static void main(String[] args)
|
|
24
|
+
{
|
|
25
|
+
launch(args);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
@Override
|
|
29
|
+
public void start(Stage stage) throws Exception {
|
|
30
|
+
// TODO 自動生成されたメソッド・スタブ
|
|
31
|
+
|
|
32
|
+
lb = new Label(" 五目並べ");
|
|
33
|
+
bt1 = new Button("ルール説明");
|
|
34
|
+
bt2 = new Button("スタート");
|
|
35
|
+
|
|
36
|
+
BorderPane bp = new BorderPane();
|
|
37
|
+
|
|
38
|
+
bp.setTop(lb);
|
|
39
|
+
bp.setBottom(bt1);
|
|
40
|
+
bp.setCenter(bt2);
|
|
41
|
+
|
|
42
|
+
bt1.setOnAction(new SampleEventHandler());
|
|
43
|
+
|
|
44
|
+
Scene sc = new Scene(bp, 300, 200);
|
|
45
|
+
|
|
46
|
+
stage.setScene(sc);
|
|
47
|
+
stage.setTitle("五目並べ");
|
|
48
|
+
stage.show();
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
class SampleEventHandler implements
|
|
54
|
+
EventHandler<ActionEvent>
|
|
55
|
+
{
|
|
56
|
+
public void handle(ActionEvent e)
|
|
57
|
+
{
|
|
58
|
+
Alert al = new Alert(Alert.AlertType.INFORMATION);
|
|
59
|
+
al.setTitle("ルール説明");
|
|
60
|
+
al.getDialogPane()
|
|
61
|
+
.setHeaderText(" ルール説明\n1:五目並べのルール");
|
|
62
|
+
al.show();
|
|
63
|
+
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
コード(ゲーム画面)
|
|
68
|
+
import javafx.application.Application;
|
|
69
|
+
import javafx.scene.Scene;
|
|
70
|
+
import javafx.scene.control.Button;
|
|
71
|
+
import javafx.scene.layout.GridPane;
|
|
72
|
+
import javafx.stage.Stage;
|
|
73
|
+
|
|
74
|
+
public class sample2 extends Application
|
|
75
|
+
{
|
|
76
|
+
private Button[][] bt = new Button[5][5];
|
|
77
|
+
|
|
78
|
+
public static void main(String[] args)
|
|
79
|
+
{
|
|
80
|
+
launch(args);
|
|
81
|
+
}
|
|
82
|
+
@Override
|
|
83
|
+
public void start(Stage stage) throws Exception
|
|
84
|
+
{
|
|
85
|
+
for(int m=0; m<bt.length; m++){
|
|
86
|
+
for(int c=0; c<bt[m].length; c++){
|
|
87
|
+
bt[m][c] = new Button(Integer.toString(c) + Integer.toString(m));
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
GridPane gp = new GridPane();
|
|
91
|
+
|
|
92
|
+
for(int m=0; m<bt.length; m++){
|
|
93
|
+
for(int c=0; c<bt.length; c++){
|
|
94
|
+
gp.add(bt[m][c], m, c);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
Scene sc = new Scene(gp, 248, 200);
|
|
99
|
+
stage.setScene(sc);
|
|
100
|
+
stage.setTitle("五目並べ");
|
|
101
|
+
stage.show();
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
```
|