Advertisement
Guest User

Untitled

a guest
Oct 10th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6.  
  7. import javafx.scene.control.Button;
  8. import javafx.scene.control.TextArea;
  9. import javafx.application.Application;
  10. import javafx.event.ActionEvent;
  11. import javafx.event.EventHandler;
  12. import javafx.scene.Scene;
  13. import javafx.scene.control.Alert;
  14. import javafx.scene.image.Image;
  15. import javafx.scene.image.ImageView;
  16. import javafx.scene.layout.GridPane;
  17. import javafx.stage.Stage;
  18.  
  19. /**
  20. *
  21. * @author olivi
  22. */
  23. public class HelloGUIWorld extends Application {
  24.  
  25. private GridPane root;
  26. private Button button;
  27. private Button button2;
  28.  
  29. @Override
  30. public void start(Stage primaryStage) {
  31.  
  32. root = new GridPane();
  33.  
  34. button2 = new Button();
  35. button2.setStyle("-fx-background-color: MediumSeaGreen");
  36. button2.setPrefSize(40, 40);
  37. button2.addEventHandler(ActionEvent.ACTION, new ButtonClickHandler());
  38.  
  39. button = new Button();
  40. button.setStyle("-fx-background-color: MediumSeaGreen");
  41. button.setPrefSize(40, 40);
  42.  
  43. //root.getChildren().add(button2);
  44. //root.getChildren().add(button);
  45. root.add(button2, 1, 1);
  46. root.add(button, 2, 2);
  47.  
  48. Scene scene = new Scene(root, 300, 250);
  49.  
  50. primaryStage.setTitle("Memory!");
  51. primaryStage.setScene(scene);
  52. primaryStage.show();
  53. }
  54.  
  55. private class ButtonClickHandler implements EventHandler<ActionEvent> {
  56.  
  57. @Override
  58. public void handle(ActionEvent event) {
  59.  
  60. Image image = new Image(this.getClass().getResource("resorces/apple.png").toString());
  61. ImageView secondView = new ImageView();
  62. secondView.setFitHeight(20);
  63. secondView.setFitWidth(20);
  64. secondView.setImage(image);
  65. button2.setGraphic(secondView);
  66. }
  67.  
  68. }
  69.  
  70. private void showMessage(String message) {
  71. Alert alert = new Alert(Alert.AlertType.INFORMATION);
  72. alert.setTitle("Information");
  73. alert.setHeaderText("Message from application");
  74. alert.setContentText(message);
  75. alert.show();
  76. }
  77.  
  78. /**
  79. * @param args the command line arguments
  80. */
  81. public static void main(String[] args) {
  82. launch(args);
  83. }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement