Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transactions On Large Scale Data And Knowledge Centered Systems Xxiv Special Issue On Database And Expert Systems Applications Lncs 9510

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Hendrik Decker ,Lenka Lhotska ,Sebastian Link

1st Edition

366249213X, 978-3662492130

Students also viewed these Databases questions

Question

1.who the father of Ayurveda? 2. Who the father of taxonomy?

Answered: 1 week ago

Question

Commen Name with scientific name Tiger - Wolf- Lion- Cat- Dog-

Answered: 1 week ago