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 9245249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:13:28+00:00 2026-06-18T09:13:28+00:00

This is my first post so if any other information is needed please let

  • 0

This is my first post so if any other information is needed please let me know.
I’m making a game in a Java GUI and just have two hopefully quick questions about which. I can currently paint a map to the screen and pan around the map with the following code:
private class MoveMap implements MouseMotionListener{

    @Override
    public void mouseDragged(MouseEvent e) {

    }

    @Override
    public void mouseMoved(MouseEvent e) {

        if(e.getX() > swidth-30){
            if(xmod+(columns*30) > swidth){
                xmod-=30;
                repaint();
            }
        }
        else if(e.getX() < 30){
            if(xmod < 0){
                xmod+=30;
                repaint();
            }
        }
        else if(e.getY() > sheight-30){
            if(ymod+(rows*30) > sheight){
                ymod-=30;
                repaint();
            }
        }
        else if(e.getY() < 30){
            if(ymod < 0){
                ymod+=30;
                repaint();
            }
        }
        else{

        }

    }

}

The only problem is the mouse must continually move at the edge of the screen to continually pan. My question is if there’s a way to have the mouse at the edge of the screen and continually pan while updating the graphics? My second question would be if this could be applied to characters moving as well? I thought maybe a thread would be a possible solution but am not familiar with using them. Thank you!

  • 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-06-18T09:13:29+00:00Added an answer on June 18, 2026 at 9:13 am

    I can think of two ways to achieve this.

    You could…

    Start a javax.swing.Timer that would update the x/y position as required and repaint the screen when ever the mouse entered within a given distance of the edge of the screen. You would, obviously stop the timer as the mouse moved back out 😉

    You could…

    Use a background Thread to monitor the mouse position and when it enters the “trigger” zone, would update the x/y values and trigger a repaint, making sure you re-sync the calls to the EDT 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my first SO post, so please forgive any faux pas. I feel
This is my first post in any forum so please bear with me. I
This is my first post in this forum, so please, be patient with me.
This is my first post on stackoverflow, so please excuse me if my question
This is my first post on Stack Overflow and I'm just wondering on the
This is my first post on Stack, so please bear with me if I
This is my first post, so please go easy on me if I say
Let me first state that I know next to nothing about LDAP and this
this is my first post so if you need clarificatrion on anything then just
This is my first post and I my first experience with jquery. I have

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.