简体   繁体   中英

Java delete key compare

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?

You can use KeyEvent constants to check whether delete key was pressed, eg:

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

Here 's javadoc for KeyEvent class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM