Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6226685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:04:40+00:00 2026-05-24T09:04:40+00:00

Simple question – why wouldn’t an object move if it’s the object of .move()

  • 0

Simple question – why wouldn’t an object move if it’s the object of .move() inside onMouseMoved()? I’m trying to write Breakout as part of the Stanford 106A exercises on iTunes U and for some reason I can’t get the paddle to track the mouse. I’m a java noob, so I’m sure it’s something really simple. Could someone please take a look at this code?

/** Runs the Breakout program. */
    public void run() {
        setupBoard();
        addMouseListeners();
    }

    /** Provides the initial GCanvas and blocks for the game */
    private void setupBoard(){
        this.setSize(APPLICATION_WIDTH,APPLICATION_HEIGHT);
        addBricks();
        paddle = new GRect(PADDLE_WIDTH, PADDLE_HEIGHT);
        add(paddle, WIDTH/2-PADDLE_WIDTH/2,HEIGHT-PADDLE_Y_OFFSET);

    }

    public void MouseMoved(MouseEvent e){
        paddle.move(e.getX()-paddle.getX(), 0);
        }

    private GRect paddle;
}

I’m not sure if having paddle be an instance variable is appropriate in this case, since its “value” doesn’t change (the paddle’s always the paddle), but if I just define it as a new GRect within setupBoard I get an error in the MouseMoved() method.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T09:04:40+00:00Added an answer on May 24, 2026 at 9:04 am

    Your class that has the mouseMoved() method needs to implement the interface MouseMotionListener, and add the motion listener. Moreover, the event handler is mouseMoved() not MouseMoved(). So, e.g.:

    public class Game extends JPanel implements MouseMotionListener {
        public void run() {
            addMouseMotionListener(this);
            //...        
        }
        public void mouseMoved(MouseEvent e) {                  
            paddle.move(e.getX()-paddle.getX(), 0); 
        } 
        //...
    };  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to ask a question about how you would approach a simple object-oriented
Simple question: Part of my repository looks like this public class CustomerRepository : IRepository<Customer>
This may seem like a simple question however i've spent the last hour trying
I know this is probably a very simple question but how would I do
A simple question, how would I go about declaring a clause which would produce
A simple question, but could someone provide sample code as to how would someone
This is hopefully a simple question: I have an OpenGL texture and would like
This is probably a really simple question but... I would like to do a
This question is simple. What function would I use in a PHP script to
I know there is no simple answer to my question but I would appreciate

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.