Gui鍵盤監聽事件,實作的效果就是按下鍵盤控制臺輸出你按下的鍵,比如:按下A控制臺就輸出A
public class TextKeyFlowLay {
public static void main(String[] args) {
new keyFrame();
}
}
class keyFrame extends Frame{
public keyFrame(){
setBounds(2,3,300,400);
setVisible(true);
setBackground(new Color(111, 111, 111));
//按下鍵盤按鈕
//用this呼叫該類的方法
this.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
int keyCode = e.getKeyCode();
//鍵盤的每個按鍵都有對應的16進制數字
System.out.println(keyCode);
//vk-對于鍵盤每個按鍵
if(keyCode==KeyEvent.VK_UP){
System.out.println("按下了上鍵");
}
//根據不同的輸操作,產生不同的結果
}
});
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/279241.html
標籤:java
上一篇:剛拿到阿里offer,還熱乎的信號量模型semaphore面經
下一篇:Filter詳解
