swing:mouse_events

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

swing:mouse_events [2015/05/16 22:01]
gthanos created
swing:mouse_events [2016/02/26 11:15]
Line 1: Line 1:
-====== Mouse Events & Mouse Listeners ====== 
- 
-Κάθε φορά που μετακινείτε το ποντίκι ή πατάτε κάποιο κουμπί στο ποντίκι σας δημιουργείτε ένα //event// του τύπου [[http://​docs.oracle.com/​javase/​7/​docs/​api/​java/​awt/​event/​MouseEvent.html|MouseEvent]]. Αντίστοιχα,​ εάν μετακινείτε την ροδέλα του ποντικιού σας, τότε παράγεται ένα //event// του τύπου [[http://​docs.oracle.com/​javase/​7/​docs/​api/​java/​awt/​event/​MouseWheelEvent.html|MouseWheelEvent]]. Σε αυτή την ενότητα θα ασχοληθούμε αποκλειστικά με //​MouseEvents//​. 
- 
-Για να λάβετε ένα MouseEvent θα πρέπει να ορίσετε για τα //​Components//​ που θέλετε να ακούν τα συγκεκριμένα //events// ένα αντικείμενο του τύπου [[http://​docs.oracle.com/​javase/​7/​docs/​api/​java/​awt/​event/​MouseListener.html|MouseListener]] ή [[http://​docs.oracle.com/​javase/​7/​docs/​api/​java/​awt/​event/​MouseMotionListener.html|MouseMotionListener]] ως //​Listener//​. Ο πρώτος τύπος //​Listener//​ αφορά τα events που συνδέονται με τα πλήκτρα του ποντικιού,​ ενώ ο δεύτερος τύπος //​Listener//​ αφορά την κίνηση του ποντικού. Ας δούμε αναλυτικότερα ποιες μεθόδους περιλαμβάνει το interface //​MouseListener//​. 
- 
-<code java> 
-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. 
-</​code>​ 
- 
-Αντιστοίχως,​ οι μέθοδοι που πρέπει να υποστηρίζει κάθε αντικείμενο που υλοποιεί το interface //​MouseMotionListener//​ είναι οι παρακάτω. 
-<code java> 
-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. 
-</​code>​ 
  
swing/mouse_events.txt · Last modified: 2016/02/26 11:15 (external edit)