Hi, i want to do a listener and this is what i have at the moment:
class MyListener extends MouseInputAdapter implements KeyListener{
@Override
public void mousePressed(MouseEvent e) {
if(e.getButton()==1){
out.println("MSE press "+e.BUTTON1_MASK);
}else if (e.getButton()==2){
out.println("MSE press "+e.BUTTON2_MASK);
}else if (e.getButton()==3){
out.println("MSE press "+e.BUTTON3_MASK);
}
}
@Override
public void mouseMoved(MouseEvent e) {
int x = e.getX();
int y = e.getY();
out.println("MSE move "+x+" "+y);
}
@Override
public void mouseDragged(MouseEvent e) {
int x = e.getX();
int y = e.getY();
out.println("MSE drag "+x+" "+y);
}
@Override
public void mouseReleased(MouseEvent e) {
if(e.getButton()==1){
out.println("MSE release "+e.BUTTON1_MASK);
}else if(e.getButton() ==2) {
out.println("MSE release "+e.BUTTON2_MASK);
}else if(e.getButton() ==3) {
out.println("MSE release "+e.BUTTON3_MASK);
}
}
@Override
public void keyTyped(KeyEvent e){
}
@Override
public void keyPressed(KeyEvent e){
out.println("KEY press "+e.getKeyCode());
System.out.println("Say it!");
}
@Override
public void keyReleased(KeyEvent e){
out.println("KEY release "+e.getKeyCode());
System.out.println("Say it!");
}
}
and then i add it to a JLabel this way:
MyListener ml = new MyListener();
label.addMouseListener(ml);
label.addMouseMotionListener(ml);
label.addKeyListener(ml);
My label catches the mouse events but no key events. Can this be done somehow... or should i just make a separate key listener?