0

Hi I ve got one problem:

I write a little calculator in Java Swing. I ve got buttons bind with KeyBindings and then in actionPerformed I check which key was pressed, it's something like that:

if(event.getActionCommand().equals("\b")) {
}

My question is: is there any way to compare delete button, like backspace button is compared above?

MyWash
  • 1

1 Answers1

0

You can use KeyEvent constants to check whether delete key was pressed, e.g.:

if (event.getExtendedKeyCode() == KeyEvent.VK_DELETE) {
    //do something
}

Here's javadoc for KeyEvent class.

Darshan Mehta
  • 30,102
  • 11
  • 68
  • 102
  • Yes I know but there is written that its better to use key bindings so im trying to do this that way – MyWash Feb 26 '17 at 10:03
  • No, it's not. Using key bindings is not a good practice. Have a look at this answer : http://stackoverflow.com/a/22741216/1120793 – Darshan Mehta Feb 26 '17 at 10:09