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 hilsen = null; @Override public void start(Stage stage) { VBox rot = new VBox(); rot.setAlignment(Pos.CENTER); Label merkelapp = new Label("Fyll inn navn: "); tekstfelt = new TextField("- navn - "); Button knapp = new Button("Klikk her!"); KnappBehandler behandler = new KnappBehandler(); knapp.setOnAction(behandler); hilsen = new Label(""); rot.getChildren().addAll(merkelapp, tekstfelt, knapp, hilsen); stage.setScene(new Scene(rot, 300, 100)); stage.setTitle("Personlig hilsen"); stage.show(); } public static void main(String[] args) { Application.launch(args); } class KnappBehandler implements EventHandler { @Override public void handle(ActionEvent e) { String navn = tekstfelt.getText(); hilsen.setText("Hei paa deg, " + navn + "!"); } } }