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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:50:25+00:00 2026-05-31T01:50:25+00:00

Hi everybody I am a bit of stack here. When I run the program

  • 0

Hi everybody I am a bit of stack here. When I run the program and press the button submit it is supposed to change 4 pictures in every 2 seconds.However it is not redisplaying the images. If anyone can give me a hand it would be great. I am using eclipse and the program is compiling and running. Here is the code.

/** Here is the GUI of the program
 * class name SlideShowGui.java
 * @author Kiril Anastasov
 * @date 07/03/2012
 */

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;   

public class SlideShowGui extends JPanel  implements ActionListener, Runnable
{
    JLabel name, comments, images;
    JTextField namejtf, commentsjtf, captionjtf;
    JButton submit;
    ImageIcon pictures1, pictures2, pictures3, pictures4;
    //ImageIcon []pictures2 = {galileo1.jpg};


    SlideShowGui()
    {


        name = new JLabel("Name:");
        this.add(name);

        namejtf = new JTextField(15);
        this.add(namejtf);

        comments = new JLabel("Comments:");
        this.add(comments);

        commentsjtf = new JTextField(15);
        this.add(commentsjtf);

        submit = new JButton("Submit");
        this.add(submit);
        submit.addActionListener(this);


        pictures1 = new ImageIcon("galileo1.jpg");
        images = new JLabel(pictures1);
        this.add(images);


        pictures2 = new ImageIcon("galileo2.jpg");
        this.add(images);
        pictures3 = new ImageIcon("galileo3.jpg");
        this.add(images);
        pictures4 = new ImageIcon("galileo4.jpg");
        this.add(images);



        captionjtf = new JTextField(24);
        this.add(captionjtf);
        //pictures = new ImageIcon("galileo1.jpg");
       // images.setIcon(pictures);  
    }

    public void actionPerformed(ActionEvent ae)
    {
        Thread t = new Thread(this);
        t.start();

        if(ae.getSource() == submit)
        {

            int i = 0;
            boolean go = true;
            while(go)
            {

                i++;
                System.out.println(i);

                try 
                { 
                    Thread.sleep(2000);

                      if(i == 1)
                      {
                            pictures1 = new ImageIcon("galileo1.jpg");
                            images.setIcon(pictures1);                                                                                                      
                            System.out.println("picture 1 should be displayed here");
                      }
                      if(i == 2)
                      {
                            pictures2 = new ImageIcon("galileo2.jpg");
                            images.setIcon(pictures2);   
                            System.out.println("picture 2 should be displayed here");

                      }
                      if(i == 3)
                      {
                           pictures3 = new ImageIcon("galileo3.jpg");
                            images.setIcon(pictures3);   
                           System.out.println("picture 3 should be displayed here");  
                      }
                      if(i == 4)
                      {
                            pictures4 = new ImageIcon("galileo4.jpg");
                            images.setIcon(pictures4);   
                           System.out.println("picture 4 should be displayed here");  
                      }


                      if(i == 4)
                      {
                              i = 0;
                      }


                } 
                catch (InterruptedException ie) 
                {
                     System.out.println("thread exception");
                }

        }
    }

}

    public void run() 
    {

    }
}

/**The driver class of the program. Here is the JFrame 
 * class name TestSlideShow.java
 * @author Kiril Anastasov
 * @date 07/03/2012
 */

import java.awt.*;
import javax.swing.*;
public class TestSlideShow 
{
    public static void main(String[] args) 
    {
        JFrame application = new JFrame();
        SlideShowGui panel = new SlideShowGui();
        application.add(panel);
        application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        application.setSize(300,600);
        application.setLocation(400,100);
        application.setVisible(true);


    }

}
  • 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-31T01:50:26+00:00Added an answer on May 31, 2026 at 1:50 am

    Always use javax.swing.Timer never use Thread.sleep(...) in Swing atleast. Here try this code, but do replace the path to your images :

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    
    public class SlideShow extends JPanel
    {
        private int i = 0;
        private Timer timer;
        private JLabel images = new JLabel();
        private Icon bg = UIManager.getIcon("OptionPane.warningIcon");
        private Icon red = UIManager.getIcon("OptionPane.errorIcon");
        private Icon blue =  UIManager.getIcon("OptionPane.informationIcon");
        private ImageIcon pictures1, pictures2, pictures3, pictures4;
        private ActionListener action = new ActionListener()
        {
            public void actionPerformed(ActionEvent ae)
            {           
    
                boolean go = true;
    
                i++;
                System.out.println(i);
    
                if(i == 1)
                {
                    images.setIcon(bg);                                                                                                      
                    System.out.println("picture 1 should be displayed here");
                }
                if(i == 2)
                {
                    images.setIcon(red);   
                    System.out.println("picture 2 should be displayed here");
                }
                if(i == 3)
                {
                    images.setIcon(blue);   
                    System.out.println("picture 3 should be displayed here");  
                }
                if(i == 4)
                {
                    images.setIcon(bg);   
                    System.out.println("picture 4 should be displayed here");  
                }
                if(i == 5)
                {
                    go = false;
                    timer.stop();
                    System.exit(0);
                }
                revalidate();
                repaint();
            }
        };
    
        public SlideShow()
        {
            JFrame frame = new JFrame("SLIDE SHOW");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setLocationByPlatform(true);
    
            frame.getContentPane().add(this);
    
            add(images);
    
            frame.setSize(300, 300);
            frame.setVisible(true); 
            timer = new Timer(2000, action);    
            timer.start();  
        }
    
        public static void main(String... args)
        {
            SwingUtilities.invokeLater(new Runnable()
            {
                public void run()
                {
                    new SlideShow();
                }
            });
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi everybody: let me do a bit of concept mining here: I am involved
It seems that everybody knows you're supposed to have a clear distinction between the
Good day everybody. I've doing a bit of training at working with Flex and
Hi everybody that's my first post here, so i'll try to be as clear
This is a bit noob question but.. Its happens sometimes to everybody. I never
Everybody knows that you should close a connection immediately after you finish using it.
everybody; I have this problem in asp.net, I have a page where I insert
everybody! Could I ask you to help me to decode this JSON code: $json
Hi everybody. The problem: elcipse-3.5.0 (Galileo) spits with an error when I try to
Greetings everybody. I have seen examples of such operations for so many times that

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.