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; import javafx.scene.text.Text; public class HeiPerson extends Application { Button button; Text nyTekst; Label l; public TextField tekstfelt = new TextField("Skriv inn navn p? en dude/dudette/beautiful inbetweens: "); @Override public void start (Stage stage) { nyTekst = new Text(""); l = new Label("Navn her ..."); VBox root = new VBox(); button = new Button(); button.setText("Generer hilsen"); Knappebehandler knb = new Knappebehandler(); button.setOnAction(knb); root.getChildren().addAll(tekstfelt, button, nyTekst, l); stage.setScene(new Scene(root)); stage.show(); } class Knappebehandler implements EventHandler { public void handle(ActionEvent e) { String tekst = tekstfelt.getText(); nyTekst.setText("Hallo " + tekst); l.setText("Hallo " + tekst); } } public static void main(String[] args) { Application.launch(args); } }