Esempio n. 1
0
 public void mouseMoved(MouseEvent e) {
   if ((e.getX() > PADDLE_WIDTH / 2) && (e.getX() < WIDTH - PADDLE_WIDTH / 2)) {
     double x = e.getX() - PADDLE_WIDTH / 2;
     double y = HEIGHT - BRICK_Y_OFFSET - PADDLE_HEIGHT;
     paddle.setLocation(x, y);
   }
 }
Esempio n. 2
0
 /** Called on mouse press to record the starting coordinates */
 public void mousePressed(MouseEvent e) {
   startX = e.getX();
   startY = e.getY();
   lastX = e.getX();
   lastY = e.getY();
   gobj = getElementAt(startX, startY);
   if (gobj == null) {
     currentRect = new GRect(startX, startY, 0, 0);
     currentRect.setFilled(true);
     add(currentRect);
   }
 }
Esempio n. 3
0
 /** Called on mouse drag to reshape the current rectangle */
 public void mouseDragged(MouseEvent e) {
   if (gobj != null) {
     gobj.move(e.getX() - lastX, e.getY() - lastY);
     lastX = e.getX();
     lastY = e.getY();
   } else {
     double x = Math.min(e.getX(), startX);
     double y = Math.min(e.getY(), startY);
     double width = Math.abs(e.getX() - startX);
     double height = Math.abs(e.getY() - startY);
     currentRect.setBounds(x, y, width, height);
   }
 }
Esempio n. 4
0
 public void mouseMoved(MouseEvent e) {
   if (label != null) remove(label);
   label = new GLabel("X: " + e.getX() + " Y: " + e.getY());
   add(label, (getWidth() - label.getWidth()) / 2, (getHeight() - label.getHeight()) / 2);
 }
Esempio n. 5
0
 /** When mouse moved: move the board */
 public void mouseMoved(MouseEvent e) {
   board.move(e.getX() - board.getX() - BOARD_WIDTH / 2, 0);
 }