0
I just want to run two frames concurrently, one contains drag and drop feature which i am using to write file to ftp server and other one to display the progress bar to show how much file is written(uploaded you can say).
But the problem is my progress bar frame remains white i.e, GUI is not done on it.why???
please give me a solution.

here is my first class which is a homePage frame which calls another class called ProgressSample which writes data to the output stream and also updates the progress bar simultaneously.

FTPConnect.java
SwingWorker<Void , Integer> worker = new SwingWorker<Void , Integer>(){


                @Override
                protected Void doInBackground() throws Exception {

                    ProgressSample.main(secondLocalFile , bytesIn , inputStream , outputStream);

                    return null;
                }

                protected void done(){
                    ProgressSample.frame.dispose();
                }

            };
            worker.execute();

this is the second class ... when i call its main(......) method just a frame with white color on it appears nothing is added on it plz plz plz help me with ur suggestions as soon as possible...

ProgressSample.java

package encdec;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JProgressBar;
public class ProgressSample
{  
        static JFrame frame;
        JProgressBar progressBar;
        public static void main(File file , byte[] bytesIn, InputStream inputStream , OutputStream outputStream)throws IOException
        {  
            ProgressSample obj=new ProgressSample();
            obj.redfile(file , bytesIn , inputStream , outputStream);
        }  
        public ProgressSample()
        {
            frame = new JFrame();
            frame.setBounds(100, 100, 400, 200);
            frame.getContentPane().setLayout(null);
            progressBar = new JProgressBar();
            progressBar.setBounds(102, 40, 150, 16);
            frame.getContentPane().add(progressBar);
            progressBar.setStringPainted(true);
            frame.setVisible(true);
        }
        public void redfile(File f , byte[] bytesIn, InputStream inputStream , OutputStream outputStream)
        {
            try {


                long totalLength = f.length();

                double lengthPerPercent = 100.0 / totalLength;
                long readLength = 0;
                int read;
                System.out.println(totalLength);
                while ((read = inputStream.read(bytesIn)) != -1) {



                    readLength += read;
                    progressBar.setValue((int) Math.round(lengthPerPercent * readLength)); 

                    outputStream.write(bytesIn, 0, read);



                }
                progressBar.setValue(100);
               frame.dispose();
               JOptionPane.showMessageDialog(null, "Upload Successful");


            } catch (Exception e) {

            }
        }

    }
Aman
  • 23
  • 4
  • can you post some of the code you have? – Donal Sep 03 '14 at 11:32
  • 1) Don't block the EDT, the GUI will freeze up. Instead use a Swing `Timer` for repeating tasks or a `SwingWorker` for long running tasks. See [Concurrency in Swing](http://docs.oracle.com/javase/tutorial/uiswing/concurrency/) for more details. 2) See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/q/9554636/418556) 3) For better help sooner, post an [MCVE](http://stackoverflow.com/help/mcve) (Minimal, Complete, Verifiable Example). – Andrew Thompson Sep 03 '14 at 11:40
  • BTW - is this using Swing? It originally had the [tag:swing] tag but it seems to have been removed now. – Andrew Thompson Sep 03 '14 at 11:40
  • yes thompson this is swing – Aman Sep 04 '14 at 05:11

0 Answers0