This is an old revision of the document!
Mouse Events & Mouse Listeners
Κάθε φορά που μετακινείτε το ποντίκι ή πατάτε κάποιο κουμπί στο ποντίκι σας δημιουργείτε ένα event του τύπου MouseEvent. Αντίστοιχα, εάν μετακινείτε την ροδέλα του ποντικιού σας, τότε παράγεται ένα event του τύπου MouseWheelEvent. Σε αυτή την ενότητα θα ασχοληθούμε αποκλειστικά με MouseEvents.
Για να λάβετε ένα MouseEvent θα πρέπει να ορίσετε για τα Components που θέλετε να ακούν τα συγκεκριμένα events ένα αντικείμενο του τύπου MouseListener ή MouseMotionListener ως Listener. Ο πρώτος τύπος Listener αφορά τα events που συνδέονται με τα πλήκτρα του ποντικιού, ενώ ο δεύτερος τύπος Listener αφορά την κίνηση του ποντικού. Ας δούμε αναλυτικότερα ποιες μεθόδους περιλαμβάνει το interface MouseListener.
void mouseClicked(MouseEvent e) //Invoked when the mouse button has been clicked (pressed and released) on a component. void mouseEntered(MouseEvent e) //Invoked when the mouse enters a component. void mouseExited(MouseEvent e) //Invoked when the mouse exits a component. void mousePressed(MouseEvent e) //Invoked when a mouse button has been pressed on a component. void mouseReleased(MouseEvent e) //Invoked when a mouse button has been released on a component.
Αντιστοίχως, οι μέθοδοι που πρέπει να υποστηρίζει κάθε αντικείμενο που υλοποιεί το interface MouseMotionListener είναι οι παρακάτω.
void mouseDragged(MouseEvent e) //Invoked when a mouse button is pressed on a component and then dragged. void mouseMoved(MouseEvent e) //Invoked when the mouse cursor has been moved onto a component but no buttons have been pushed.