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;
/**
* JavaFX application that tells your fortune.
*
* @author Aaron Astonvilla
* @version 1.0
*/
public class FortuneTeller extends Application
{
Text fortune = new Text("");
String[] fortunes = {"masa depan anda cerah",
"masa depan anda kelam",
"anda akan jadi orang menengah ke atas","anda akan mengalami kemunduran dalam sebulan kedepan",};
@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("SanSerif", 36));
box.getChildren().add(title);
fortune.setFont(Font.font("SanSerif", 18));
box.getChildren().add(fortune);
Button button = new Button("New Fortune");
box.getChildren().add(button);
button.setOnAction(this::buttonClick);
Scene scene = new Scene(box, 500, 250);
stage.setTitle("Fortune Teller");
stage.setScene(scene);
stage.show();
}
private void buttonClick(ActionEvent event)
{
Random rand = new Random();
fortune.setText(fortunes[rand.nextInt(fortunes.length)]);
}
}