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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:30:12+00:00 2026-05-27T08:30:12+00:00

I have a problem.. I have a image painted on my java applet and

  • 0

I have a problem.. I have a image painted on my java applet and a for loop to make the x move up 5 every time.. but it leaves behind the old image for a bit then it will erase it..

for(int tohouse = 0; tohouse <= 520; tohouse+=2) {
  try {
    x+=5;
    tohouse+=10;

    if (pos == 0) {
      rectX+=5;
      g.drawImage(picture1,x,150,this);
      pos = 1;
    } else if (pos == 1) {
      rectX+=4;
      g.drawImage(picture2,x,150,this);
      pos = 2;
    } else if (pos == 2) {
      rectX+=5;
      g.drawImage(picture3,x,150,this);
      pos = 0;
    }
  }
}

Heres a image:

Image

  • 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-27T08:30:13+00:00Added an answer on May 27, 2026 at 8:30 am

    You can’t do animation by looping in your paintComponent() or paint() method. Those methods are asking you to paint yourself at a specific point in time (i.e. the current frame).

    Instead, you need to decouple the logic of “moving” your sprite from “rendering” your sprite. Look for something like this

    private int x;
    
    protected void paintComponent(Graphics g) {
        //draw the images at location x
    }
    
    // elsewhere, initialize a javax.swing.Timer to increment x every 15 ms
    new Timer(15, new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            x += 5;
            repaint();
        }
    }.start();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with loading image with java 2ME. I have a image
I have problem with dynamically created image (JavaScript). I want to change the innerHTML
I have a problem with an image preview that comes up when you hover
I have a problem when I'm trying to delete an image file. I always
I have a problem... In my view i have Image.If i click on image
I have a strange problem where an onclick event on an input image is
I have the following simple button with an image as the template. The problem
Problem Hello all! I have this code which takes my jpg image loops through
I've some CSS problem in Firefox 3. I have several image buttons on my
i have one image background of table with following syntax style=background-image(URL) the problem is

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.