document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  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. * Write a description of JavaFX class FortuneTeller here.
  17. *
  18. * @author (ivannizar)
  19. * @version (0.1)
  20. */
  21. public class FortuneTeller extends Application
  22. {
  23.     Text fortune = new Text("");
  24.     String[] fortunes = {"Test javaFx"};
  25.  
  26.     @Override
  27.     public void start(Stage stage) throws Exception
  28.         {
  29.             VBox box=new VBox();
  30.             box.setPadding(new Insets(20));
  31.             box.setSpacing(20);
  32.             box.setAlignment(Pos.CENTER);
  33.  
  34.             Text title=new Text("Hello Fortune Teller");
  35.             title.setFont(Font.font("SanSerif",36));
  36.             box.getChildren().add(title);
  37.  
  38.             Button button = new Button("Klik JavaFx");
  39.             box.getChildren().add(button);
  40.  
  41.             button.setOnAction(this::buttonClick);
  42.  
  43.             Scene scene=new Scene(box,500,250);
  44.             stage.setTitle("Hello JavaFx");
  45.             stage.setScene(scene);
  46.             stage.show();
  47.  
  48. }
  49.  
  50. /**
  51. * This will be executed when the button is clicked
  52. * It increments the count by 1
  53. */
  54.     private void buttonClick(ActionEvent event)
  55.     {
  56.         Random rand = new Random();
  57.         fortune.setText(fortunes[rand.nextInt(fortunes.length)]);
  58.     }
  59. }
');