java 键盘事件

package 键盘事件;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		KeyEvent1 win=new KeyEvent1();
		win.setTitle("键盘事件");
	}

}

package 键盘事件;
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
public class KeyEvent1 extends JFrame implements KeyListener{
	JTextArea textInput,textShow;
	KeyEvent1(){
		setLayout(new FlowLayout());
		init();
		setBounds(10,10,446,236);
		setVisible(true);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
	void init()
	{
		textInput=new JTextArea(10,15);
		textShow=new JTextArea(10,15);
		add(new JScrollPane(textInput));
		add(new JScrollPane(textShow));
		textInput.addKeyListener(this);
	}
	public void keyPressed(KeyEvent e){
		textShow.append(KeyEvent.getKeyText(e.getKeyCode())+"\n");
	}
	public void keyTyped(KeyEvent e){
		
	}
	public void keyReleased(KeyEvent e){
		
	}

}
java 键盘事件_第1张图片

你可能感兴趣的:(java,键盘事件)