キーリスニング

1420 ワード

public class Test extends JFrame {
	private static final long serialVersionUID = -37927920298166521L;
	private JFrame frame;

	public static void main(String[] args) {
		new Test();
	}

	public Test() {
		frame = new JFrame();
		frame.setTitle(" ");
		frame.setLocation(300, 150);
		frame.setSize(780, 470);
		frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
		JTextArea textArea = new JTextArea(3, 30);
		frame.add(textArea);
		MYKeyLisenter my = new MYKeyLisenter();
		textArea.addKeyListener(my);
		frame.setVisible(true);
	}

	public class MYKeyLisenter extends KeyAdapter {
		@Override
		public void keyPressed(KeyEvent ef) {
			super.keyPressed(ef);
			switch (ef.getKeyCode()) {
			case KeyEvent.VK_UP:
				System.out.println(" ");
				break;
			case KeyEvent.VK_DOWN:
				System.out.println(" ");
				break;
			case KeyEvent.VK_LEFT:
				System.out.println(" ");
				break;
			case KeyEvent.VK_RIGHT:
				System.out.println(" ");
				break;
			case KeyEvent.VK_0:
				System.out.println("0");
				break;
			case KeyEvent.VK_D:
				System.out.println("d");
				break;
			}
		}
	}
}