Hey Guys,
I've been working on a networked application in Java for the past couple of weeks. But I've hit the same stumbling block I always seem to hit when working on larger applications and it comes down to how to effectively implement a progress bar. I can never seem to get those things down.
Basically the part I'm stuck on here is the login to the application. Basically the application on the client computer accesses files stored on the server computer. I've got all the networking down, as well as the security of the connection between the two machines (hybrid algorithm) but I am trying to implement a progress bar in the login process.
The structure of the program with regards to this part of it works like this:
- There is a network/communications Thread - Class within the program that handles all of the communications between the server and client.
- There is a login screen that gathers the user's username and password as well as the location of the server (IP Addr.)
- The login screen dispatches this data to the LoginProgress panel which contains the problematic progress bar, this class is responsible for starting up the Thread that handles communications and is supposed to report back to the user through the GUI about the current state of the login process.
-> Now the problem is that I can't get this updater to work properly. Should I create another thread that handles the updating of the progress bar? Basically what I've got is this (and it's not working):
public void start() { SwingUtilities.invokeLater(new Runnable() { @SuppressWarnings("static-access") public void run() { // - Setup Communications comms = new Comms(address, username, userhash, passhash); comms.start(); // - Update Status Bar while(comms.isConnected() == false) { setStatus(comms.currentStatus); setPercent(comms.currentPercent); try{ Thread.currentThread().sleep(100); }catch(Exception e){ //Do Nothing } if(comms.getResult().startsWith("F")) { progressBar.setEnabled(false); setStatus(comms.getResult().split("-")[1]); } } // - Once Logged In if(comms.getResult().startsWith("S")) { //Successful Login setPercent(100); setStatus("Login Successful!"); try{ Thread.currentThread().sleep(2000); }catch(Exception e){ //Do Nothing } parent.setComms(comms); parent.setVisible(true); dispose(); }else{ LoginPanel lp = new LoginPanel(parent, (Config)UtilityFunctions.LoadObject("config.dbf")); lp.centerFrame(); lp.setVisible(true); dispose(); } } }); }
This is (what should be) the public static void main(String[] args) {...} function but because the function isn't static it cannot be such a functions which is why I changed it to public void start() {...}
This isn't working. It just sits at 0% and doesn't do anything, it hangs. The cancel button that I've also included on the panel doesn't work, nor does the exit X.
If anyone has any experience implementing progress bars or knows how to go about tackling this situation please let me know. I'd like to finally get down how to do progress bars.
Thanks for the help!