자바한지 얼마안된 초보입니다 ㅜㅜ
예제공부하다가 의문이 생겨서 질문드립니다
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class KeyTest extends JFrame {
private static final long serialVersionUID=1L;
private String str;
JTextArea area;
public KeyTest(){
Container con = getContentPane();
con.setLayout(new FlowLayout());
area=new JTextArea(10,20);
con.add(area);
area.setText("키보드를 누르세요");
addKeyListener(
new KeyAdapter(){
public void KeyPressed(KeyEvent e){
str="눌린 키는"+e.getKeyChar();
area.setText(str+"는"+e.getKeyCode()+"\n");
}
});
setLocation(500,200);
setSize(300,300);
setVisible(true);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
KeyTest obj = new KeyTest();
obj.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
}
이런코드인데
.. 제가 코드 이해한거로는 키 입력할때마다
"눌린키는"+'입력한키'+"는" +(엔터)
이런식으로 입력이 되야하지않을까.... 생각했는데 그냥 타이핑하듯이 입력이 되더라구요....
getKeyChar랑 getKeyCode의 확실한 쓰임새도 모르겟고..ㅜㅜㅜ
알려주시면 감사하겟습니다..
댓글 0