Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.74 KB | None | 0 0
  1. import javafx.application.Application;
  2. import javafx.application.Platform;
  3. import javafx.event.ActionEvent;
  4. import javafx.event.EventHandler;
  5. import javafx.geometry.Insets;
  6. import javafx.geometry.Pos;
  7. import javafx.scene.Scene;
  8. import javafx.scene.control.Button;
  9. import javafx.scene.layout.VBox;
  10. import javafx.scene.text.Font;
  11. import javafx.scene.text.Text;
  12. import javafx.stage.Stage;
  13. import java.util.Random;
  14.  
  15. public class FortuneTeller extends Application
  16. {
  17.     Text fortune = new Text("");
  18.     String[] fortunes = {"Ending 1: Imprisoned",
  19.         "Ending 2: Escape",
  20.         "Ending 3: Release",
  21.         "Ending 4: Lost",
  22.         "You will get Null Element",
  23.         "You will meet your beloved one",
  24.         "You have discovered every secret within Grey Holm"};
  25.  
  26.     @Override
  27.     public void start(Stage stage) throws Exception
  28.     {
  29.         VBox box = new VBox();
  30.         box.setPadding(new Insets(20));
  31.         box.setSpacing(20);
  32.         box.setAlignment(Pos.CENTER);
  33.        
  34.         Text title = new Text("Fortune Teller");
  35.         title.setFont(Font.font("SanSerif", 36));
  36.        
  37.         box.getChildren().add(title);
  38.        
  39.         fortune.setFont(Font.font("SanSerif", 18));
  40.        
  41.         box.getChildren().add(fortune);
  42.        
  43.         Button button = new Button("Change Your Fate");
  44.         box.getChildren().add(button);
  45.        
  46.         button.setOnAction(this::buttonClick);
  47.        
  48.         Scene scene = new Scene(box, 500, 300);
  49.         stage.setTitle("Fortune Teller");
  50.         stage.setScene(scene);
  51.         stage.show();
  52.     }
  53.  
  54.     private void buttonClick(ActionEvent event)
  55.     {
  56.         Random rand = new Random();
  57.         fortune.setText(fortunes[rand.nextInt(fortunes.length)]);
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement