Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Import statements go here..
- public class MyDownloaderApp {
- //Lots of JavaFX GUI is supposed to go here...
- //Tableview with title column and progressbar column
- //I need to update the progress bar as download progresses
- class DownloaderThread extends Thread {
- private DBWrapper db;
- //constructor provides DBWrapper db
- @Override
- public void run() {
- while(!isInterrupted()&db.hasUncompletedDownload()) {
- DownloadEntry dl = db.getNextIncompleteDownload();
- // Open connection, open file, write, etc.
- // dl.setProgress(int percent) --- Sets the progress of download in percentage during the read write loop
- // Here's where I need help
- // I decided to decouple DownloaderThread from the UI
- // Is this a good or bad decision?
- // If this is a good decision,
- // is there any better way to update UI than using a background thread like below?
- // please look at initUpdateThread()
- }
- }
- }
- public void initUpdateThread(final DBWrapper db) {
- new Thread(){
- @Override
- public void run(){
- while(true){
- Thread.sleep(someInterval);
- List<DownloadEntry> downloads = db.getAllDownloads();
- setTableViewItems(downloads);
- }
- }
- }.start();
- }
- public void setTableViewItems(List<DownloadEntry> dls) {
- //UI Update stuff..
- }
- }
Add Comment
Please, Sign In to add comment