import javafx.application.Application; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.TextField; import javafx.scene.layout.VBox; import javafx.scene.text.Text; import javafx.stage.Stage; import javafx.scene.Scene; import javafx.event.EventHandler; import javafx.event.ActionEvent; public class HeiPerson extends Application{ TextField tekstfelt = null; Label hilsen = null; @Override public void start(Stage stage) { VBox box = new VBox(); Label merkelapp = new Label("Fyll inn navn:"); tekstfelt = new TextField("Navn"); Button knapp = new Button("Si hei!"); Knappebehandler behandler = new Knappebehandler(); knapp.setOnAction(behandler); hilsen = new Label(""); box.getChildren().addAll(merkelapp, tekstfelt, knapp, hilsen); stage.setScene(new Scene(box, 200, 100)); stage.show(); } private class Knappebehandler implements EventHandler { @Override public void handle(ActionEvent e) { String hilsetekst = tekstfelt.getText(); hilsen.setText(String.format("Hei paa deg, %s!", hilsetekst)); } } }