Home » Java » java – Why KeyListner isn't working with TextArea?-Exceptionshub

java – Why KeyListner isn't working with TextArea?-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment

Questions:

This code is working until I add TextArea.
After that all is focused on firstKeyArea and key listener doesn’t working. I tried using method requestFocus() on Stage. How fix that? TextArea should fill dynamic.

Main.scene.setOnKeyPressed(new EventHandler<KeyEvent>() {
    @Override
    public void handle(KeyEvent event) {
      if(event.getCode()== KeyCode.A){
          keyboardImageView.setImage(imageA);
          letter=encryption.sentenceEncrypting("a",3);
          setDisplayImageViev(letter);

      }
      if(event.getCode()== KeyCode.B){
          keyboardImageView.setImage(imageB);
          letter=encryption.sentenceEncrypting("b",3);
          setDisplayImageViev(letter);
      }
      if(event.getCode()== KeyCode.C){
          keyboardImageView.setImage(imageC);
          letter=encryption.sentenceEncrypting("c",3);
          setDisplayImageViev(letter);
      }
      if(event.getCode()== KeyCode.D){
          keyboardImageView.setImage(imageD);
          letter=encryption.sentenceEncrypting("d",3);
          setDisplayImageViev(letter);
           firstKeyArea.setText(Integer.toString(FirstRotor.shift));
          secondKeyArea.setText(Integer.toString(SecondRotor.shift));
          thirdKeyArea.setText(Integer.toString(ThirdRotor.shift));}}};
How to&Answers: