title: How to download files without making application GUI freeze
body: <p>I am creating a application that will download files from URL(My own FTP server). The problem is, when I click the "Download" button, my application will start download, but my application will not have any response when downloading but after downloading everything work fine.</p>
  
  <p>Here is some part of my code</p>
  
  <p>GUI.class</p>
  
  <pre><code>b_Download.addActionListener(new ActionListener()
          {
              public void actionPerformed(ActionEvent ae)
              {
                         String username = "Test";
                         startDownloading(username);
              }   
          });
  
  private void startDownload(String username)
      {
          downloader.println("Welcome " + username); //println will show text in a textpane(GUI) and console
          downloader.startDownloading();
      }
  </code></pre>
  
  <p>Downloader.class</p>
  
  <pre><code>public void startDownloading()
  {       
                  println("Download jobs started");
  
  
                  download.downloadLIB();    
  }
  </code></pre>
  
  <p>DownloadJob.class</p>
  
  <pre><code>public void downloadLIB()
      {
          launcher.println("Start downloading files from server...");
          String libURL = "http://www.example.com/file.jar";
          File libFile = new File("C://file.jar");
          downloadFile(libURL, libFile, "file.jar");
      }
  public void downloadFile(String url, File path, String fileName)
      {
          InputStream in = null;
          FileOutputStream fout = null;
          try
          {
              in = URI.create(url).toURL().openStream();
              fout = new FileOutputStream(path);
  
              byte data[] = new byte[1024];
              int count;
              while ((count = in.read(data, 0, 1024)) != -1)
              {
                  fout.write(data, 0, count);
              }
          }
          catch(Exception e)
          {
              launcher.println("Cannot download file : " + fileName, e);
          }
          finally
          {
              if (in != null)
                  try
                  {
                      in.close();
                  }
                  catch (IOException e)
                  {
                      e.printStackTrace();
                  }
              if(fout != null)
                  try
                  {
                      fout.close();
                  }
                  catch (IOException e)
                  {
                      e.printStackTrace();
                  }
              launcher.println("File " + fileName + " downloaded successfully");
          }
      }
  </code></pre>
  
  <p>When i press the 'Download' button, my textpane show the word 'Welcome Username' then it have no response. But my console will show the word 'Welcome Username', 'Download Jobs started' and 'Start download files from sever...'. After few minutes(when the file finish downloaded, my application will start to have response again...</p>