import acm.graphics.*;
import acm.program.*;
import java.awt.Color;
import java.awt.event.*;
public class TestingClass2 extends GraphicsProgram implements MouseMotionListener{
//dimensions of play board
private static final int boardWidth = 402;
private static final int boardHeight = 600;
//paddle
private static final int paddleWidth = 60;
private static final int paddleHeight = 10;
private double xPosition;
GRect paddle;
public void run(){
setSize(boardWidth, boardHeight);
setPaddle();
addMouseMotionListener(this);
}
public void mouseDragged(MouseEvent e){
xPosition = e.getX();
if(xPosition <= 0 && xPosition <= boardWidth - paddleWidth){
paddle.setLocation(xPosition, 580);
}
}
public void mouseMoved(MouseEvent e){
}
public void setPaddle(){
paddle = new GRect(boardWidth / 2 - 30.0, 580, paddleWidth, paddleHeight);
paddle.setFillColor(Color.BLACK);
paddle.setFilled(true);
add(paddle);
}
}
问问题
343 次