import javafx.application.Application; import javafx.stage.Stage; import javafx.scene.Scene; import javafx.scene.layout.VBox; import javafx.scene.control.Label; import javafx.scene.control.Button; import javafx.event.EventHandler; import javafx.event.ActionEvent; import javafx.geometry.Pos; import javafx.scene.control.TextField; public class HeiPerson extends Application { public TextField tekstfelt = null; public Label tekst = null; @Override public void start (Stage stage) { VBox vbox = new VBox(); tekstfelt = new TextField("Skriv inn navnet ditt her..."); Button knapp = new Button("Klikk for hilsen"); Knappebehandler event = new Knappebehandler(); knapp.setOnAction(event); tekst = new Label("hehe"); vbox.getChildren().add(tekstfelt); vbox.getChildren().add(knapp); vbox.getChildren().add(tekst); stage.setScene(new Scene(vbox)); stage.show(); } class Knappebehandler implements EventHandler { public void handle(ActionEvent e){ String navn = tekstfelt.getText(); tekst.setText("Hei " + navn + ". Velkommen HEHE :)"); } } }