52ky 发表于 2022-9-28 11:18:33

JAVA_精通swing程序设计

1.KeyEvent类还有两个方法也常常被用到,那就是getKeyCode()与getKeyModifiersText(intmodifiers).键盘上每一个按钮都有对应码(Code),可用来查知用户按了啥键,如键code为16。使用getKeyCode()方法就可以得知这个码,不过读者要注意,这个方法在keyTyped()上是无法检测出来的,由于keyTyped()只管用户输入的字符,而不会管到键盘的对应码,算是管理比较高层事情的方法。也就是说keyTyped()方法是keyboadindependent,由于不一样的键盘可能有不一样的对应码(如WindowsU.S.keyboard与windowsFrenchkeyboard就有不一样的对应码)。因而你必定要将getKeyCode()方法写在keyPressed()或keyReleased()方法中才会有效,由于这两个方法是管理比较低层的方法。
JAVA_精通swing程序设计.chm

(1. There are also two methods in the KeyEvent class that are often used, namely getKeyCode() and getKeyModifiersText(intmodifiers). Each button on the keyboard has a corresponding code (Code), which can be used to find out what key the user has pressed, such as The key code is 16. This code can be obtained by using the getKeyCode() method, but the reader should note that this method cannot be detected on keyTyped(), because keyTyped() only cares about the characters entered by the user, but not the corresponding code of the keyboard. It's a way to manage things at a higher level. That is to say, the keyTyped() method is keyboadindependent, because different keyboards may have different corresponding codes (for example, WindowsU.S.keyboard and windowsFrenchkeyboard have different corresponding codes). Therefore, you must write the getKeyCode() method in the keyPressed() or keyReleased() method to be effective, because these two methods are relatively low-level management methods.
JAVA_Proficient in swing programming.chm)




页: [1]
查看完整版本: JAVA_精通swing程序设计