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