animationを使い、動くタイトル画面を作成したのですが
先に作っていた2つのbuttonのゲームスタートボタンとルール説明画面が表示されなくなってしまいました。
両方を共存させる方法がありましたらお教え下さい。
よろしくお願い致します。
java
1コード 2import javafx.animation.Animation; 3import javafx.animation.Transition; 4import javafx.application.Application; 5import javafx.event.ActionEvent; 6import javafx.event.EventHandler; 7import javafx.geometry.Pos; 8import javafx.scene.Scene; 9import javafx.scene.control.Alert; 10import javafx.scene.control.Button; 11import javafx.scene.control.Label; 12import javafx.scene.layout.BorderPane; 13import javafx.scene.text.Font; 14import javafx.stage.Stage; 15import javafx.util.Duration; 16 17public class タイトルB extends Application{ 18 19 20 private Button bt1, bt2; 21 22 public static void main(String[] args) 23 { 24 launch(args); 25 } 26 27 @Override 28 public void start(Stage stage) throws Exception { 29 // TODO 自動生成されたメソッド・スタブ 30 31 32 bt1 = new Button("ルール説明"); 33 bt2 = new Button("ゲームスタート"); 34 35 BorderPane bp = new BorderPane(); 36 37 38 bp.setBottom(bt1); 39 bp.setCenter(bt2); 40 41 bt1.setOnAction(new SampleEventHandler()); 42 43 stage.setTitle("五目並べ"); 44 stage.setWidth(300); 45 stage.setHeight(200); 46 47 //ここから下のanimation.play();までを消すとスタートとルール説明が表示されます。 48 49 final String content = "五目並べ!!"; 50 final Label label = new Label(""); 51 label.setFont(new Font(30)); 52 label.setAlignment(Pos.CENTER); 53 stage.setScene(new Scene(label)); 54 stage.show(); 55 56 final Animation animation = new Transition(){ 57 { 58 setCycleDuration(Duration.millis(3000)); 59 } 60 61 protected void interpolate(double frac) { 62 final int length = content.length(); 63 final int n = Math.round(length * (float) frac); 64 label.setText(content.substring(0, n)); 65 } 66 }; 67 animation.play(); 68 69 70 71 } 72 73 class SampleEventHandler implements 74 EventHandler<ActionEvent> 75 { 76 public void handle(ActionEvent e) 77 { 78 Alert al = new Alert(Alert.AlertType.INFORMATION); 79 al.setTitle("ルール説明"); 80 al.getDialogPane() 81 .setHeaderText(" ルール説明\n1:五目並べのルール"); 82 al.show(); 83 84} 85} 86}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/06/06 08:20
2017/06/06 08:59