Thanks for the code, Jacob. That's a good example for a loader.
I looked at the source and I miss the usage of invokeAndWait() int the initial thread to prevent concurrency problems.
It would be like this in your main:
Code:
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
new GUI().setVisible(true);
}
});
The reason is stated here:
Quote:Every program has a set of threads where the application logic begins. In standard programs, there's only one such thread: the thread that invokes the main method of the program class. In applets the initial threads are the ones that construct the applet object and invoke its init and start methods; these actions may occur on a single thread, or on two or three different threads, depending on the Java platform implementation. In this lesson, we call these threads the initial threads.
So they are run in different threads, but Swing isn't threadsafe. Because of that bugs due to concurrency problems are possible if not run by invokeAndWait or invokeLater. These errors may or may not occur. The smaller the project, the least often you get these weird bugs in my experience.
Further read:
http://docs.oracle.com/javase/tutorial/u...index.html
The way you handle updating the label to show the progress is unusual and probably won't work anymore if you add invokeAndWait to your main.
Usually the Swing GUI will freeze, if you do a task that takes very long, which is i.e. downloading the jar and loading the classes in your code. Because of that you use the SwingWorker to perform long tasks instead of doing it right away in the Event Dispatch Thread. The SwingWorker is a kind of thread designed to be used with Swing. PropertyChangeListener can listen for the progress and so you are able to display the progress.
Thanks again for your share. I love to see more code on HC.
Deque