Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javafx.application.Application;
- import javafx.application.Platform;
- import javafx.event.ActionEvent;
- import javafx.event.EventHandler;
- import javafx.geometry.Insets;
- import javafx.geometry.Pos;
- import javafx.scene.Scene;
- import javafx.scene.control.Button;
- import javafx.scene.layout.VBox;
- import javafx.scene.text.Font;
- import javafx.scene.text.Text;
- import javafx.stage.Stage;
- import java.util.Random;
- /**
- * Write a description of JavaFX class FortuneTeller here.
- *
- * @author Muhammad Naufaldillah
- * @version 13 Desember 2020
- */
- public class FortuneTeller extends Application
- {
- Text fortune = new Text("");
- String[] fortunes = {"Test javaFx", "Lulus dengan IPK 4.0",
- "Kerja di perusahaan Start-up", "Liburan keliling dunia", "Menjadi presiden Indonesia"};
- /**
- * The start method is the main entry point for every JavaFX application.
- * It is called after the init() method has returned and after
- * the system is ready for the application to begin running.
- *
- * @param stage the primary stage for this application.
- */
- @Override
- public void start(Stage stage) throws Exception
- {
- VBox box = new VBox();
- box.setPadding(new Insets(20));
- box.setSpacing(20);
- box.setAlignment(Pos.CENTER);
- Text title = new Text("Fortune Teller");
- title.setFont(Font.font("Arial", 36));
- box.getChildren().add(title);
- fortune.setFont(Font.font("Arial", 18));
- box.getChildren().add(fortune);
- Button button = new Button("Buka Ramalan anda.");
- box.getChildren().add(button);
- button.setOnAction(this::buttonClick);
- Scene scene = new Scene(box, 500, 250);
- stage.setTitle("Fortune Teller");
- stage.setScene(scene);
- stage.show();
- }
- /**
- * This will be executed when the button is clicked
- * It increments the count by 1
- */
- private void buttonClick(ActionEvent event)
- {
- Random rand = new Random();
- fortune.setText(fortunes[rand.nextInt(fortunes.length)]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement