处理键和鼠标侦听器

时间:2014-04-29 16:20:33

标签: java swing awt keylistener mouselistener

如何在JPanel中同时处理鼠标和键监听器? 我尝试添加混合侦听器,并设置JPanel的setFocusable(true):

class MyListener implements MouseListener, KeyListener {

    public void mouseClicked(MouseEvent e) {}
    public void mousePressed(MouseEvent e) {}
    public void mouseReleased(MouseEvent e) {}
    public void mouseEntered(MouseEvent e) {}
    public void mouseExited(MouseEvent e) {}

    public void keyTyped(KeyEvent e) {}
    public void keyPressed(KeyEvent e) {}
    public void keyReleased(KeyEvent e) {}
}

但是当按下键时,鼠标监听器不会听动作,如何处理?

0 个答案:

没有答案