thomasfelix

PBO 8 (2)

Dec 13th, 2020
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.05 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. /**
  16.  * Implementasi JavaFX: Random Waifu
  17.  *
  18.  * @author Thomas Felix
  19.  * @version 13 Desember 2020
  20.  */
  21.  
  22. public class RandomWaifu extends Application
  23. {
  24.     Text waifu = new Text("");
  25.     String[] waifus =
  26.     {
  27.         "Rem - Re:Zero",
  28.         "Emilia - Re:Zero",
  29.         "Makise Kurisu - Steins;Gate",
  30.         "Senjougahara Hitagi - Monogatari Series",
  31.         "Gasai Yuno - Mirai Nikki",
  32.         "Saber - Fate Series",
  33.         "Yuuki Asuna - Sword Art Online",
  34.         "Yukinoshita Yukino - Oregairu",
  35.         "Megumin - Konosuba",
  36.         "Miyazono Kaori - Shigatsu wa Kimi no Uso"
  37.     };
  38.  
  39.     @Override
  40.     public void start(Stage stage) throws Exception
  41.     {
  42.         VBox box = new VBox();
  43.         box.setPadding(new Insets(20));
  44.         box.setSpacing(20);
  45.         box.setAlignment(Pos.CENTER);
  46.  
  47.         Text title = new Text("Random Waifu");
  48.         title.setFont(Font.font("Highway Gothic", 36));
  49.        
  50.         box.getChildren().add(title);
  51.        
  52.         waifu.setFont(Font.font("Highway Gothic", 18));
  53.        
  54.         box.getChildren().add(waifu);
  55.        
  56.         Button button = new Button("Klik Daku!");
  57.         box.getChildren().add(button);
  58.  
  59.         button.setOnAction(this::buttonClick);
  60.  
  61.         Scene scene = new Scene(box, 500, 250);
  62.         stage.setTitle("Random Waifu");
  63.         stage.setScene(scene);
  64.         stage.show();
  65.  
  66.     }
  67.  
  68.     /**
  69.     * Fungsi akan dijalankan ketika button diklik.
  70.     * Dan akan increment++
  71.     */
  72.     private void buttonClick(ActionEvent event)
  73.     {
  74.        Random rand = new Random();
  75.        waifu.setText(waifus[rand.nextInt(waifus.length)]);
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment