0
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);
    }

}
mKorbel
  • 109,525
  • 20
  • 134
  • 319
user2263005
  • 1
  • 1
  • 6

1 Answers1

0

Use addMouseMotionListeners rather than addMouseMotionListener to register implemented MouseListeners for GraphicsProgram

addMouseMotionListeners();
Reimeus
  • 158,255
  • 15
  • 216
  • 276