Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  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. /**
  16.  * JavaFX application that tells your fortune.
  17.  *
  18.  * @author CPD
  19.  * @version 1.0
  20.  */
  21. public class FortuneTeller extends Application
  22. {
  23.     Text fortune = new Text("");
  24.     String[] fortunes = {"masa depan anda cerah",
  25.         "masa depan anda kelam",
  26.         "anda akan jadi orang menengah ke atas","anda akan mengalami kemunduran dalam sebulan kedepan",};
  27.  
  28.     @Override
  29.     public void start(Stage stage) throws Exception
  30.     {
  31.         VBox box = new VBox();
  32.         box.setPadding(new Insets(20));
  33.         box.setSpacing(20);
  34.         box.setAlignment(Pos.CENTER);
  35.        
  36.         Text title = new Text("Fortune Teller");
  37.         title.setFont(Font.font("SanSerif", 36));
  38.        
  39.         box.getChildren().add(title);
  40.        
  41.         fortune.setFont(Font.font("SanSerif", 18));
  42.        
  43.         box.getChildren().add(fortune);
  44.        
  45.         Button button = new Button("New Fortune");
  46.         box.getChildren().add(button);
  47.        
  48.         button.setOnAction(this::buttonClick);
  49.        
  50.         Scene scene = new Scene(box, 500, 250);
  51.         stage.setTitle("Fortune Teller");
  52.         stage.setScene(scene);
  53.         stage.show();
  54.     }
  55.  
  56.     private void buttonClick(ActionEvent event)
  57.     {
  58.         Random rand = new Random();
  59.         fortune.setText(fortunes[rand.nextInt(fortunes.length)]);
  60.     }
  61. }