farseenabdulsalam

MyDownloaderApp.java

Jan 10th, 2015
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.34 KB | None | 0 0
  1. //Import statements go here..
  2.  
  3. public class MyDownloaderApp {
  4.  
  5.  
  6.   //Lots of JavaFX GUI is supposed to go here...
  7.   //Tableview with title column and progressbar column
  8.   //I need to update the progress bar as download progresses  
  9.  
  10.   class DownloaderThread extends Thread {
  11.     private DBWrapper db;  
  12.     //constructor provides DBWrapper db
  13.     @Override
  14.     public void run() {
  15.       while(!isInterrupted()&db.hasUncompletedDownload()) {
  16.         DownloadEntry dl = db.getNextIncompleteDownload();
  17.     // Open connection, open file, write, etc.
  18.     // dl.setProgress(int percent) --- Sets the progress of download in percentage during the read write loop
  19.       // Here's where I need help
  20.       // I decided to decouple DownloaderThread from the UI
  21.       // Is this a good or bad decision?
  22.       // If this is a good decision,
  23.         // is there any better way to update UI than using a background thread like below?
  24.         // please look at initUpdateThread()
  25.       }
  26.     }
  27.        
  28.   }
  29.   public void initUpdateThread(final DBWrapper db) {
  30.     new Thread(){
  31.     @Override
  32.     public void run(){
  33.       while(true){
  34.     Thread.sleep(someInterval);
  35.     List<DownloadEntry> downloads = db.getAllDownloads();
  36.     setTableViewItems(downloads);
  37.       }
  38.      }
  39.     }.start();
  40.   }
  41.    
  42.   public void setTableViewItems(List<DownloadEntry> dls) {
  43.      //UI Update stuff..
  44.   }
  45.  }
Add Comment
Please, Sign In to add comment