Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- import javafx.scene.control.Button;
- import javafx.scene.control.TextArea;
- import javafx.application.Application;
- import javafx.event.ActionEvent;
- import javafx.event.EventHandler;
- import javafx.scene.Scene;
- import javafx.scene.control.Alert;
- import javafx.scene.image.Image;
- import javafx.scene.image.ImageView;
- import javafx.scene.layout.GridPane;
- import javafx.stage.Stage;
- /**
- *
- * @author olivi
- */
- public class HelloGUIWorld extends Application {
- private GridPane root;
- private Button button;
- private Button button2;
- @Override
- public void start(Stage primaryStage) {
- root = new GridPane();
- button2 = new Button();
- button2.setStyle("-fx-background-color: MediumSeaGreen");
- button2.setPrefSize(40, 40);
- button2.addEventHandler(ActionEvent.ACTION, new ButtonClickHandler());
- button = new Button();
- button.setStyle("-fx-background-color: MediumSeaGreen");
- button.setPrefSize(40, 40);
- //root.getChildren().add(button2);
- //root.getChildren().add(button);
- root.add(button2, 1, 1);
- root.add(button, 2, 2);
- Scene scene = new Scene(root, 300, 250);
- primaryStage.setTitle("Memory!");
- primaryStage.setScene(scene);
- primaryStage.show();
- }
- private class ButtonClickHandler implements EventHandler<ActionEvent> {
- @Override
- public void handle(ActionEvent event) {
- Image image = new Image(this.getClass().getResource("resorces/apple.png").toString());
- ImageView secondView = new ImageView();
- secondView.setFitHeight(20);
- secondView.setFitWidth(20);
- secondView.setImage(image);
- button2.setGraphic(secondView);
- }
- }
- private void showMessage(String message) {
- Alert alert = new Alert(Alert.AlertType.INFORMATION);
- alert.setTitle("Information");
- alert.setHeaderText("Message from application");
- alert.setContentText(message);
- alert.show();
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- launch(args);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement