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 outputCodePudding user response:
Set flags wordsPublic 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 outputCodePudding 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 statementCodePudding user response:
I can I reset in keyReleased, thank the bossesCodePudding user response:
This method set the keyReleased () is not good