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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:52:32+00:00 2026-06-04T07:52:32+00:00

i having problem with draw image in applet. i want to display all images

  • 0

i having problem with draw image in applet. i want to display all images one by one in applet but it shows only last image of the folder my code is given below.

public class ImageInSwingTest extends JApplet
{
    String filePath="C:\\Users\\yogi\\Pictures\\pictures"; //all .png files more than 200 files
    String files;
    File folder=new File(filePath);
    File[] listOfFiles;
    Image m;

    @Override
    public void init()
    {
        listOfFiles=folder.listFiles();
        for(int i=0;i<listOfFiles.length;i++)
        {
            if(listOfFiles[i].isFile())
            {
                files=listOfFiles[i].getName();
                if(files.endsWith(".png"))
                {
                    String filepath=listOfFiles[i].getAbsolutePath();
                    System.out.println(filepath);
                    try {
                         m = ImageIO.read(new File(filepath));
                        paint(ImageInSwingTest.this.getGraphics());

                    } catch (IOException ex) {
                        Logger.getLogger(ImageInSwingTest.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            }

        }
    }
    public void paint(Graphics g)
    {
        g.drawImage(m, 0, 0, this);

    }

}

so, please can any one tell me how can i display all images one by one.?
Thanks.

  • 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-04T07:52:34+00:00Added an answer on June 4, 2026 at 7:52 am

    so, please can any one tell me how can i display all images one by one.? Thanks.

    • because each of loop inside for(int i=0;i<listOfFiles.length;i++) replacing JApplet‘s contents

    • put JPanel to the JApplet

    • put Images to the array of Icon[]

    • put Icon to the JLabel

    • use GridLayout for placing JLabel with Icons to the JPanel

    • don’t paint to the JApplet directly, use JPanel or JComponent with override method paintComponent() instead of paint()

    EDIT

    actually i want all images to replace each other so all images are look like playing movie

    • you have to pause this process by Thread.sleep(int);

    • you can use Thread.sleep(int); inside SwingWorker or Runnable#Thread,

    • don’t use Thread.sleep(int); other ways in the Swing GUI, because to block Event Dispatch Thread, and is possible that nothing will be painted or only the last image too

    • Runnable#Thread would be better and easiest, but any output from Runnable#Thread to the Swing GUI you have to wrap JLabel.setIcon(myIcon) to the invokeLater

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

Sidebar

Related Questions

so having a canvas and canvasContext I want to draw an image onto that
Having problem with the middle Div not expanding to the width http://acs.graphicsmayhem.com/images/middiv.jpg Ok, how
I'm having a problem with matplotlib where it only plots a line the first
I'm working with java images for the first time and having a problem viewing
I am having problem of displaying PNG image where as JPG image is Displaying
Having problems loading/showing an image in a java applet. Not sure if I'm loading
I am having a problem with setting an ImageView image to an image which
I'm having a problem with the rotation of images Graphics2D g2 = (Graphics2D) g;
I'm Basically programming a simple game engine but I'm having problems with my sprites/images
I'm trying to make a very basic image creator using PySide. But I'm having

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.