Moving GRect: Bad Code or Bug?
Hi Forum Members,
I'm trying to move a shape around the screen, wherever my mouse pointer is. However, moving around the pointer seems to "smear" the shape, for lack of better words. Is this coding issue, or a bug? I'm using Eclipse on my mac.
Here's the code:
Code:
import acm.graphics.*;
import acm.program.*;
import acm.util.*;
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class Breakout extends GraphicsProgram {
/** Dimensions of the paddle */
private static final int PADDLE_WIDTH = 60;
private static final int PADDLE_HEIGHT = 10;
/** Offset of the paddle up from the bottom */
private static final int PADDLE_Y_OFFSET = 30;
public void run() {
addMouseListeners();
}
public void mouseMoved(MouseEvent e) {
GRect paddle = new GRect(PADDLE_WIDTH, PADDLE_HEIGHT, (getWidth() - PADDLE_WIDTH)/2, getHeight() - PADDLE_Y_OFFSET);
paddle.setFilled(false);
add(paddle);
paddle.move(e.getX(), egetY());
}
}
Here's what it looks like when I move the paddle around:
http://lh5.ggpht.com/_TiNp2GhKp2c/S9...47.37%20PM.png
Am I doing something wrong with my code?
Thanks in advance,
Adam