SHARE
TWEET

Untitled

a guest May 12th, 2014 2 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.awt.Color;
  2. import java.awt.event.MouseEvent;
  3. import java.awt.event.MouseListener;
  4. import java.awt.event.MouseMotionListener;
  5. import java.util.List;
  6.  
  7. public class DrawPanelListener implements MouseListener, MouseMotionListener
  8. {
  9.         private DrawPanel panel;
  10.         private Shape drawShape;
  11.  
  12.         public DrawPanelListener(DrawPanel dp)
  13.         {
  14.                 panel = dp;
  15.         }
  16.  
  17.         public void mouseClicked(MouseEvent e)
  18.         {
  19.  
  20.         }
  21.  
  22.         public void mouseEntered(MouseEvent e)
  23.         {
  24.  
  25.         }
  26.  
  27.         public void mouseExited(MouseEvent e)
  28.         {
  29.  
  30.         }
  31.  
  32.         public void mousePressed(MouseEvent e)
  33.         {
  34.                 drawShape = getTmpShape(e.getX(), e.getY(), 2, 2);
  35.                 panel.setTmpShape(drawShape);
  36.         }
  37.  
  38.         public void mouseReleased(MouseEvent e)
  39.         {
  40.                 drawShape.setX2(e.getX());
  41.                 drawShape.setY2(e.getY());
  42.  
  43.                 List<Shape> shapes = panel.getShapes();
  44.                 shapes.add(drawShape);
  45.                 panel.setTmpShape(null);
  46.                 panel.setShapes(shapes);
  47.                 drawShape = null;
  48.  
  49.                 // panel.repaint();
  50.         }
  51.  
  52.         public void mouseDragged(MouseEvent e)
  53.         {
  54.                 drawShape.setX2(e.getX());
  55.                 drawShape.setY2(e.getY());
  56.  
  57.                 panel.setTmpShape(drawShape);
  58.                 panel.repaint();
  59.         }
  60.  
  61.         public void mouseMoved(MouseEvent e)
  62.         {
  63.  
  64.         }
  65.  
  66.         private Shape getTmpShape(int x, int y, int x2, int y2)
  67.         {
  68.                 return new Rectangle(x, y, x2, y2, Color.BLACK);
  69.  
  70.         }
  71.  
  72. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top