Skip to content

Instantly share code, notes, and snippets.

@Crazy-Newbie
Created December 14, 2020 07:18
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;
import java.util.*;
import java.awt.*;
import javafx.application.*;
import javafx.event.*;
import javafx.geometry.*;
import javafx.scene.*;
public class FortuneTeller extends Application
{
Text fortune = new Text("");
String[] fortunes = {
"You will be a successfull person",
"You'll have a bad luck in the next 3 days",
"Congratulation you'll find your soulmate in the future",
"You will find happiness in your heart",
"Bad luck will happen if you being a bad person"};
@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("Hello Fortune Teller");
title.setFont(Font.font("ARIAL", 40));
box.getChildren().add(title);
fortune.setFont(Font.font("ARIAL", 20));
box.getChildren().add(fortune);
Button button = new Button("Click to see your fortune");
box.getChildren().add(button);
button.setOnAction(this::buttonClick);
Scene scene = new Scene(box, 500, 500);
stage.setTitle("Hello Fortune Teller");
stage.setScene(scene);
stage.show();
}
//set button click
private void buttonClick(ActionEvent event)
{
//RANDOM OUTPUT
Random rand = new Random();
fortune.setText(fortunes[rand.nextInt(fortunes.length)]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment