import javafx.application.Application; import javafx.event.EventHandler; import javafx.geometry.Pos; import javafx.event.ActionEvent; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.TextField; import javafx.scene.control.Label; import javafx.scene.layout.VBox; import javafx.stage.Stage; public class HeiVerden extends Application { TextField textfelt = null; Button knapp = null; Label hilsenTekst = null; @Override public void start (Stage stage) { VBox pane = new VBox(); pane.setAlignment(Pos.CENTER); Label skrivNavnTekst = new Label("Skriv inn navnet ditt: "); textfelt = new TextField("Navn"); knapp = new Button("Si hei!"); hilsenTekst = new Label(""); KnappetrykksBehandler behandler = new KnappetrykksBehandler(); knapp.setOnAction(behandler); pane.getChildren().addAll(skrivNavnTekst, textfelt, knapp, hilsenTekst); stage.setScene(new Scene(pane, 200, 100)); stage.show(); } class KnappetrykksBehandler implements EventHandler { @Override public void handle(ActionEvent event) { String hilsen = "Hei paa deg, " + textfelt.getText() + "!"; hilsenTekst.setText(hilsen); } } }