I want to be able to add a new feature that lets me control the paddle to move left and right in a straight line.
I already included the event library for mouse listeners but I dont know what to fill in the MouseClicked and MouseDragged
methods to create the motion of the paddle.
Any hints or tips will be greatly appreciated.
Here's the code:
import acm.graphics.*;
import acm.program.*;
import java.awt.Color;
import java.awt.event.*;
public class paddle extends GraphicsProgram{
/** Dimensions of the paddle */
private static final int PADDLE_WIDTH = 60;
private static final int PADDLE_HEIGHT = 10;
/** Dimensions of game board */
public static final int APPLICATION_WIDTH = 400;
public static final int APPLICATION_HEIGHT = 600;
/** Dimensions of game board */
private static final int WIDTH = APPLICATION_WIDTH;
private static final int HEIGHT = APPLICATION_HEIGHT;
public void run(){
paddleSetup();
addMouseListeners();
}
private void paddleSetup(){
GRect paddle = new GRect(200,450 ,PADDLE_WIDTH,PADDLE_HEIGHT);
paddle.setFillColor(Color.MAGENTA);
paddle.setFilled(true);
add(paddle);
}
// mouse listeners to drag the mouse ONLY left and right
public void MouseClicked(MouseEvent e){
}
public void MouseDragged(MouseEvent e){
}
// instance variable for the paddle
private GRect paddle;
}