Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 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. public class FortuneTeller extends Application
  16. {
  17. Text fortune = new Text("");
  18. String[] fortunes = {"Test javaFx"};
  19.  
  20. @Override
  21. public void start(Stage stage) throws Exception
  22. {
  23. VBox box=new VBox();
  24. box.setPadding(new Insets(20));
  25. box.setSpacing(20);
  26. box.setAlignment(Pos.CENTER);
  27.  
  28. Text title=new Text("Hello Fortune Teller");
  29. title.setFont(Font.font("SanSerif",36));
  30. box.getChildren().add(title);
  31.  
  32. Button button = new Button("Klik JavaFx");
  33. box.getChildren().add(button);
  34.  
  35. button.setOnAction(this::buttonClick);
  36.  
  37. Scene scene=new Scene(box,500,250);
  38. stage.setTitle("Hello JavaFx");
  39. stage.setScene(scene);
  40. stage.show();
  41.  
  42. }
  43.  
  44. /**
  45. * This will be executed when the button is clicked
  46. * It increments the count by 1
  47. */
  48. private void buttonClick(ActionEvent event)
  49. {
  50. Random rand = new Random();
  51. fortune.setText(fortunes[rand.nextInt(fortunes.length)]);
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement