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); } }
/** 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); } }
/** 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); } }
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); }
/** When mouse moved: move the board */ public void mouseMoved(MouseEvent e) { board.move(e.getX() - board.getX() - BOARD_WIDTH / 2, 0); }