模块 java.desktop

类 KeyAdapter

java.lang.Object
java.awt.event.KeyAdapter
所有已实现的接口:
KeyListener , EventListener
已知子类:
BasicComboBoxUI.KeyHandler , BasicComboPopup.InvocationKeyHandler , BasicTreeUI.KeyHandler

public abstract class KeyAdapter extends Object implements KeyListener
用于接收键盘事件的抽象适配器类。这个类中的方法是空的。此类的存在是为了方便创建监听对象。

扩展此类以创建KeyEvent 监听器并覆盖感兴趣事件的方法。 (如果你实现了KeyListener接口,你必须在其中定义所有的方法。这个抽象类为它们都定义了空方法,所以你只需为你关心的事件定义方法。)

使用扩展类创建监听器对象,然后使用组件的 addKeyListener 方法将其注册到组件。当按下、释放或键入某个键时,将调用监听器对象中的相关方法,并将 KeyEvent 传递给它。

自从:
1.1
参见:
  • 构造方法详细信息

    • KeyAdapter

      protected KeyAdapter()
      构造一个 KeyAdapter
  • 方法详情

    • keyTyped

      public void keyTyped(KeyEvent  e)
      当键入一个键时调用。当按下键后松开键时,会发生此事件。
      指定者:
      keyTyped 在接口 KeyListener
      参数:
      e - 要处理的事件
    • keyPressed

      public void keyPressed(KeyEvent  e)
      按下某个键时调用。
      指定者:
      keyPressed 在接口 KeyListener
      参数:
      e - 要处理的事件
    • keyReleased

      public void keyReleased(KeyEvent  e)
      释放键时调用。
      指定者:
      keyReleased 在接口 KeyListener
      参数:
      e - 要处理的事件