import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Sample7 extends JApplet{
/**
*
*/
private static final long serialVersionUID = 1L;
private JLabel lb1;
private JLabel lb2;
public void init()
{
lb1 = new JLabel("請輸入按鍵");
lb2 = new JLabel();
add(lb1,BorderLayout.NORTH);
add(lb2,BorderLayout.SOUTH);
//登錄傾聽者
addKeyListener(new SampleKeyListener());
}
//類別
class SampleKeyListener extends KeyAdapter
{
//方法
public void keyPressed(KeyEvent e)
{
int keyCode = e.getKeyCode();
String keyText = KeyEvent.getKeyText(keyCode);
System.out.println( keyText);
}
}
}
沒有留言:
張貼留言