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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:13:21+00:00 2026-05-26T05:13:21+00:00

I am trying to implement an image using the method below, so that when

  • 0

I am trying to implement an image using the method below, so that when the send action is performed, the GIF image should show within a specified time(As implemented by the threadRunner pause method).

The problem is it doesn’t show. And on testing, when I disable the stop() it appears at the same time as delIveryReport Textarea which shouldn’t be. How do I solve this.

 private void sendActionPerformed(java.awt.event.ActionEvent evt) {              

            threadRunner t = new threadRunner();
            String fone = "";
            SendSMS sms = new SendSMS();
            String[] arMSISDN = msisdn.split(",");
            for (int i = 0; i < arMSISDN.length; i++) {

                fone = arMSISDN[i];
                fone = fone.trim();
                try {

                    Cursor cursor = new Cursor(Cursor.WAIT_CURSOR);
                    setCursor(cursor);
                    t.pause(loading);

                    sms.sendSMS(user, pass, fone, senderIDString, msgString);


                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                    Cursor normal = new Cursor(Cursor.DEFAULT_CURSOR);
                    setCursor(normal);
                    t.stop(loading);
                    deliveryReport.append(fone + ": " + sms.response + "\n");
                }

            }

    //        JOptionPane.showMessageDialog(rootPane, deliveryReport);
            deliveryReport.setVisible(true);
            jScrollPane2.setVisible(true);



            redo.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
            redo.setForeground(new java.awt.Color(223, 90, 46));
            redo.setText("Would you like to send another Message?");
            yes.setEnabled(true);
            no.setEnabled(true);
            yes.setText("Yes");
            no.setText("No");
            back.setEnabled(false);
            send.setEnabled(false);


        } 

THREADRUNNER

public void pause(JLabel label){

        try {
            Thread.sleep(5000);
            label.setVisible(true);    
        } catch (InterruptedException ex) {
            Logger.getLogger(threadRunner.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void stop(JLabel l){
        l.setVisible(false);
    } 
  • 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-26T05:13:22+00:00Added an answer on May 26, 2026 at 5:13 am

    It seems to me that your application is doing the actual work on the EDT, while your thread takes care of showing and hiding the progress label. I might be wrong, but if that is the case, then I’d recommend that you do the complete opposite of what you are doing. Updating SWING components should only be done from the EDT (Event Dispatch Thread) and no other threads.

    If this is a SWING desktop application, then my recommendation would be that you take a look at SwingWorker which is a class that is specifically designed to handle long running tasks withough blocking the EDT. You could then do something like outlined below (my code might not compile 100%, but it should give you an idea of what i mean.

    private void sendActionPerformed(java.awt.event.ActionEvent evt) {  
      //implement code to show progress label here
      SMSWorker w = new SMSWorker(user, pass, senderIdString, msgString, msisdn.split(","));
      w.execute();
    }
    
    public SMSWorker extends SwingWorker<Void, DeliveryReport> {
    
      private final String user;
      private final String pass;
      private final String senderIdString;
      private final String msgString;
      private final String[] arMSISDN;
    
      // this constructor runs on the current (EDT) thread.
      public SMSWorker(String user, String pass, String senderIdString, String msgString, String[] arMSISDN) {
        this.user = user;
        this.pass = pass;
        this.senderIdString = senderIdString;
        this.msgString = msgString;
        this.arMSISDN = arMSISDN;
      }
    
      // this function runs in a separate thread.
      public Boolean doInBackground() {
    
           // Instantiate SMS gateway client.
           SendSMS sms = new SendSMS();
    
           // Assuming a delivery report can be created like this.
           DeliveryReport deliveryReport = new DeliveryReport();
    
           for (int i = 0; i < arMSISDN.length; i++) {
    
                fone = arMSISDN[i];
                fone = fone.trim();
                try {
                    sms.sendSMS(user, pass, fone, senderIDString, msgString);
    
                } catch (Exception e) {
                    // you can notify users about exception using the publish() method.
    
                } finally {
                    deliveryReport.append(fone + ": " + sms.response + "\n");
                }
    
            }
    
            return deliveryReport;
    
      }
    
      // this function runs on the current (EDT) thread.
      public void done() {
        try {
          // synchronize worker thread with EDT.
          DeliveryReport deliveryReport = get();
        } catch (Exception e) {
          //implement code to notify user about errors here.
        } finally {
          //implement code to hide progress label here.
        }
    }
    

    As for your question : just set the animated gif as the JLabel’s icon – and SWING should take care of showing it. As long as your SMS sending code runs on another thread, SWING should happily be able to render the GIF animations without being blocked by the SMS sending code.

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

Sidebar

Related Questions

I am trying to implement share this method. I am using the code as
I'm trying to implement the Minimum Distance Algorithm for image classification using GDAL and
I'm working on a project that's trying to implement some editing features using a
I am trying to implement image as checkbox. I have a list with 2
I am trying to implement a image recognition program in C++ . I had
greetings, im trying to implement an image rollover on a collection of PictureBox (es)
I am trying to implement a custom broken image icon to appear if I
trying to implement a dialog-box style behaviour using a separate div section with all
I'm trying to implement an image zoom effect, a bit like how the zoom
I'm trying to implement a JQuery script to process some areas inside an image

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.