Home > Back-end >  Keyboard events failure problem about deployment headaches
Keyboard events failure problem about deployment headaches

Time:09-19

What happened is that after learning deployment headaches keyboard events today can imitate the book code. Write a according to the keyboard up and down or so mobile text,
Behind but found no response, the final test found that only keyboard events don't respond, the mouse to click ok, the keyboard Button event without any problems,
The following is the code of the test:
 
Public class KeyEventDemo extends Application {
@ Override
Public void start (Stage primaryStage) throws the Exception {
//create a common panel and text
Pane Pane=new Pane ();
The Button Button=new Button (" ok ");
The Text Text=new Text (100100, "ff");
Pane. GetChildren (). AddAll (button, text);
Button. SetOnKeyPressed (event - & gt; System. The out. Println (" dd "));
Text. SetOnKeyTyped (event - & gt; System. The out. Println (" tt "));
Text. SetOnMouseClicked (event - & gt; System. The out. Println (" ee "));

//create the Scene Scene, the panel in the, and finally put into the Scene stage
Scene Scene=new Scene (pane, 200200);
PrimaryStage. SetScene (scene);
PrimaryStage. SetTitle (" cube ");
PrimaryStage. The show ();
}
}

Test operation: randomly according to the text, click on both the three keyboard button
The test results
Ee
Ee
Dd
Dd
Dd
Say the first premise: the book says components can trigger an event, so it also has the same effect, subclasses of component
Repeat last question, why the keyboard events Text Text object is invalid?

CodePudding user response:

Text is the text display, not input, so there is no keyboard events
  • Related