Advertisement
Guest User

Untitled

a guest
Feb 21st, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.41 KB | None | 0 0
  1. package helloworld;
  2.  
  3. import javafx.application.Application;
  4. import javafx.event.ActionEvent;
  5. import javafx.event.EventHandler;
  6. import javafx.geometry.Insets;
  7. import javafx.scene.Scene;
  8. import javafx.scene.control.Button;
  9. import javafx.scene.control.TextArea;
  10. import javafx.scene.layout.VBox;
  11. import javafx.stage.Stage;
  12.  
  13.  
  14. public class HelloWorld extends Application {
  15.    
  16.     private int helloCounter = 0;
  17.    
  18.     @Override
  19.     public void start(Stage primaryStage) {
  20.         Button btn = new Button();
  21.         btn.setText("Say 'Hello World'");
  22.         final TextArea textArea = new TextArea();
  23.        
  24.         btn.setOnAction(new EventHandler<ActionEvent>() {
  25.             @Override
  26.             public void handle(ActionEvent event) {
  27.                 textArea.setText(textArea.getText()+"Hello World! ("+helloCounter+")\n");
  28.                 helloCounter++;
  29.             }
  30.         });
  31.        
  32.         VBox root = new VBox(10);
  33.         root.setPadding(new Insets(10));
  34.         root.getChildren().add(btn);
  35.        
  36.         root.getChildren().add(textArea);
  37.        
  38.         Scene scene = new Scene(root, 300, 250);
  39.        
  40.         primaryStage.setTitle("Hello World!");
  41.         primaryStage.setScene(scene);
  42.         primaryStage.show();
  43.     }
  44.  
  45.     /**
  46.      * @param args the command line arguments
  47.      */
  48.     public static void main(String[] args) {
  49.         launch(args);
  50.     }
  51.    
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement