0

I created a pinging program to ping 5 server. How do I have the progressbar to get run while the progress is being run. When the ping is done the progressbar will be 100%

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

        try {

            pingserver1();
            pingserver2();
            pingserver3();
            pingserver4();
            pingserver5();

    }     

   public void pingserver1() throws UnknownHostException, IOException {

        InetAddress addr = InetAddress.getByName("127.0.0.1");

        System.out.println("Sending Ping Request to " + addr);
        boolean status = addr.isReachable(5000);

    }

....
BeyondProgrammer
  • 893
  • 2
  • 15
  • 32
  • 1
    Possible duplicate of many similar questions. A little searching and a simple read of the JProgressBar tutorial will tell you to use a SwingWorker. – Hovercraft Full Of Eels Dec 17 '13 at 04:45
  • possible duplicate of [Using SwingWorker to add a progress bar in a GUI](http://stackoverflow.com/questions/14928213/using-swingworker-to-add-a-progress-bar-in-a-gui) – Infinite Recursion Dec 17 '13 at 04:55

1 Answers1

1

You could create yourself an SwingWorker, within the doInBackground method, you would execute your pingserverx methods.

You could then use the SwingWorkers progress API to send notifications about updates to the progress and within the ProperyChangeListener, update the UI.

For example and example

Take a look at Concurrency in Swing for more details

Community
  • 1
  • 1
MadProgrammer
  • 343,457
  • 22
  • 230
  • 366