Advertisement
rburgosnavas

DrawBoard - MouseListener stuff

Dec 15th, 2012
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.70 KB | None | 0 0
  1. @Override
  2. public void mousePressed(MouseEvent e)
  3. {
  4.     if (e.getButton() == MouseEvent.BUTTON1)
  5.     {
  6.         System.out.println("mousePressed() added line to index = " + index);
  7.         undoClearArray.clear();
  8.         clearBtn.setText("Clear");
  9.                 x1 = e.getX();
  10.         y1 = e.getY();
  11.         x2 = x1;
  12.         y2 = y1;
  13.         if (optionNum == 0)
  14.                 s = new Line(x1, y1, x2, y2, c, stroke);
  15.         else if (optionNum == 1)
  16.                 s = new Rect(x1, y1, x2, y2, c, stroke);
  17.         else if (optionNum == 2)
  18.                 s = new SolidRect(x1, y1, x2, y2, c, stroke);
  19.         else if (optionNum == 3)
  20.                 s = new Circle(x1, y1, x2, y2, c, stroke);
  21.         else if (optionNum == 4)
  22.                 s = new SolidCircle(x1, y1, x2, y2, c, stroke);
  23.         else if (optionNum == 5)
  24.         {
  25.                 if (text == null || text == "") text = "@";
  26.                 s = new Text(x1, y1, (int)(stroke * 6.4), text, c);            
  27.         }
  28.         drawPanel.shape.add(s);
  29.         drawPanel.repaint();
  30.     }
  31. }
  32.  
  33. @Override
  34. public void mouseDragged(MouseEvent e)
  35. {
  36.     x2 = e.getX();
  37.     y2 = e.getY(); 
  38.     if (optionNum == 0)
  39.     {
  40.         ((Line) s).setX2(x2);
  41.         ((Line) s).setY2(y2);          
  42.     }
  43.     else if (optionNum == 1)
  44.     {
  45.         ((Rect) s).setX2(x2);
  46.         ((Rect) s).setY2(y2);          
  47.     }
  48.     else if (optionNum == 2)
  49.     {
  50.         ((SolidRect) s).setX2(x2);
  51.         ((SolidRect) s).setY2(y2);         
  52.     }
  53.     else if (optionNum == 3)
  54.     {
  55.         ((Circle) s).setX2(x2);
  56.         ((Circle) s).setY2(y2);        
  57.     }
  58.     else if (optionNum == 4)
  59.     {
  60.         ((SolidCircle) s).setX2(x2);
  61.         ((SolidCircle) s).setY2(y2);           
  62.     }
  63.     else if (optionNum == 5)
  64.     {
  65.         ((Text) s).setX1(x2);
  66.         ((Text) s).setY1(y2);              
  67.     }
  68.     drawPanel.repaint();
  69. }
  70.  
  71. @Override
  72. public void mouseReleased(MouseEvent e)
  73. {
  74.     if (e.getButton() == MouseEvent.BUTTON1)
  75.     {
  76.         drawPanel.repaint();
  77.         cleanLineArray();
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement