Home > Back-end >  Questions about Java keyPressed.
Questions about Java keyPressed.

Time:10-30

For example:
Public void keyPressed KeyEvent (e) {
System. The out. Println (" hello world ");
}
If I always according to the key, it will have been circulating print hello world, how can you let me have been according to the key, and then executed only once,

CodePudding user response:

A flag bit in the set, detection flags and then output

CodePudding user response:

Set flags words
Public void keyPressed KeyEvent (e) {
If (condition) {
Condition=! Condition;
System. The out. Println (" hello world ");
}
}
When should let the condition is true?

CodePudding user response:

Set int I=0, for example, when testing the key i++, when I==1 output

CodePudding user response:

Such key events to turn into a one-off, and if I hold the keys, i++ processing of fast, skip the if the execution of the statement

CodePudding user response:

I can I reset in keyReleased, thank the bosses

CodePudding user response:

This method set the keyReleased () is not good
  • Related