CSenshi

MyCanvas.java (with MouseListeners)

Jan 24th, 2021 (edited)
388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.02 KB | None | 0 0
  1. package samples;
  2.  
  3. import java.awt.event.MouseEvent;
  4. import java.awt.event.MouseListener;
  5. import java.awt.event.MouseMotionListener;
  6. import acm.graphics.GCanvas;
  7.  
  8. public class MyCanvas extends GCanvas implements MouseListener, MouseMotionListener {
  9.  
  10.     // Constructor
  11.     public MyCanvas() {
  12.         addMouseListener(this);
  13.         addMouseMotionListener(this);
  14.     }
  15.  
  16.     @Override
  17.     public void mouseClicked(MouseEvent arg0) {
  18.         System.out.println("Clicked");
  19.     }
  20.  
  21.     @Override
  22.     public void mouseEntered(MouseEvent arg0) {
  23.         System.out.println("Entered");
  24.     }
  25.  
  26.     @Override
  27.     public void mouseExited(MouseEvent arg0) {
  28.         System.out.println("Exited");
  29.     }
  30.  
  31.     @Override
  32.     public void mousePressed(MouseEvent arg0) {
  33.         System.out.println("Pressed");
  34.     }
  35.  
  36.     @Override
  37.     public void mouseReleased(MouseEvent arg0) {
  38.         System.out.println("Released");
  39.     }
  40.  
  41.     @Override
  42.     public void mouseDragged(MouseEvent arg0) {
  43.         System.out.println("Dragged");
  44.     }
  45.  
  46.     @Override
  47.     public void mouseMoved(MouseEvent arg0) {
  48.         System.out.println("Moved");
  49.     }
  50.    
  51. }
  52.  
Add Comment
Please, Sign In to add comment