Question: java program Complete the following sample event program. package application; import javafx.application.Application; import javafx.event.EventHandler; import javafx.scene.Scene; import javafx.scene.control.TextField; import javafx.scene.input.KeyEvent; import javafx.scene.layout.GridPane; import javafx.stage.Stage; public

java program Complete the following sample event program. package application; import javafx.application.Application; import javafx.event.EventHandler; import javafx.scene.Scene; import javafx.scene.control.TextField; import javafx.scene.input.KeyEvent; import javafx.scene.layout.GridPane; import javafx.stage.Stage; public class Main extends Application { @Override public void start(Stage primaryStage) { try { GridPane root = new GridPane(); Scene scene = new Scene(root,400,400); TextField textField1 = new TextField(); textField1.setPromptText("Type here"); TextField textField2 = new TextField(); textField2.setPromptText("Type here"); final EventHandler keyEventHandler = new EventHandler() { public void handle(final KeyEvent keyEvent) { //Your code is missing here keyEvent.consume(); } }; textField1.setOnKeyPressed(keyEventHandler); textField2.setOnKeyPressed(keyEventHandler); root.setConstraints(textField1, 0,0); root.setConstraints(textField2, 0,1); root.getChildren().addAll(textField1,textField2); primaryStage.setScene(scene); primaryStage.show(); } catch(Exception e) { e.printStackTrace(); } } public static void main(String[] args) { launch(args); } }

The program should intercept the keys F1, F2 and F3 and a corresponding message output. After recognition, a corresponding text is written in textField2. All other keys are ignored.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!