Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (101.8 KB, 6 trang )
Các lớp adapter
49
• Mộtsố lớp adapter
Interface Adapter class
ComponentListener ComponentAdapter
ContainerListener ContainerAdapter
FocusListener FocusAdapter
KeyListener KeyAdapter
MouseListener MouseAdapter
MouseMotionListener MouseMotionAdapter
WindowListener WindowAdapter
Các sự kiện bàn phím
50
• Mộtlớpmuốn nghe sự kiện bàn phím
phảicàiđặtgiaotiếp KeyListener
• void keyTyped(KeyEvent e);
• void keyPressed(KeyEvent e);
• void keyReleased(KeyEvent e);
• Chú ý: Có thể sử dụng KeyAdapter thay cho
dùng giao tiếp KeyListener
Các sự kiện bàn phím
51
// Cac import can thiet
public class DemoKey extends Applet implements KeyListener
{
private String key;
public void init()
{
addKeyListener(this);
key = "";
}