예제 #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);
   }
 }
예제 #2
0
 public void run() {
   // divido el ancho de la pantalla en 2 para saber donde está
   // la mitad exacta de la pantalla
   distanciaX = getWidth() / 2;
   distanciaY = getHeight() / 2;
   rectangulo.setLocation(
       distanciaX - rectangulo.getWidth() / 2, distanciaY - rectangulo.getHeight() / 2);
 }
 /** Bind the paddle to the mouse cursor */
 private void muvedPaddle(MouseEvent e) {
   int y = HEIGHT - PADDLE_HEIGHT - PADDLE_Y_OFFSET;
   int x;
   if (e.getX()
       > WIDTH
           - PADDLE_WIDTH
               / 2) { // Makes it impossible to exit the paddle over the right part of the window
     x = WIDTH - PADDLE_WIDTH;
   } else if (e.getX()
       < PADDLE_WIDTH
           / 2) { // Makes it impossible to exit the paddle over the left part of the window
     x = 0;
   } else {
     x = e.getX() - PADDLE_WIDTH / 2; // Bind the paddle to the center of the cursor
   }
   paddle.setLocation(x, y);
 }