Advertisement
Ekerot

Untitled

May 27th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. package dekes03_assing1.exercise8;
  2.  
  3.  
  4. import javafx.application.Application;
  5. import javafx.event.ActionEvent;
  6. import javafx.event.EventHandler;
  7. import javafx.geometry.Insets;
  8. import javafx.scene.Scene;
  9. import javafx.scene.control.Button;
  10. import javafx.scene.control.TextField;
  11. import javafx.scene.layout.BorderPane;
  12. import javafx.scene.layout.HBox;
  13. import javafx.scene.layout.VBox;
  14. import javafx.stage.Stage;
  15.  
  16. import java.util.Random;
  17.  
  18. /**
  19. * Created by ekerot on 2016-05-27.
  20. */
  21.  
  22. public class RandomPanel extends BorderPane {
  23.  
  24. public void start(Stage primaryStage) {
  25.  
  26. BorderPane root = new BorderPane();
  27.  
  28. HBox hbox = new HBox();
  29. hbox.setPadding(new Insets(10, 10, 10, 10));
  30. hbox.setSpacing(10);
  31.  
  32. final TextField right = new TextField();
  33. right.setPrefSize(100, 20);
  34.  
  35. VBox vbox = new VBox();
  36. vbox.setPadding(new Insets(10, 10, 10, 10));
  37. vbox.setSpacing(5.0);
  38.  
  39. Button btn = new Button("New Random");
  40. btn.setPrefSize(100, 20);
  41.  
  42. btn.setLineSpacing(5.0);
  43.  
  44. vbox.getChildren().add(btn);
  45. hbox.getChildren().add(right);
  46. root.setRight(hbox);
  47. root.setLeft(vbox);
  48.  
  49. Scene scene = new Scene(root, 250, 50);
  50.  
  51. primaryStage.setTitle("New Random");
  52. primaryStage.setScene(scene);
  53. primaryStage.show();
  54.  
  55. btn.setOnAction(new EventHandler<ActionEvent>() {
  56.  
  57. @Override
  58. public void handle(ActionEvent event) {
  59.  
  60. Random rnd = new Random();
  61. int number = rnd.nextInt(100);
  62.  
  63. right.setText(String.valueOf(number));
  64.  
  65. }
  66. });
  67.  
  68. }
  69.  
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement