Java Reference
In-Depth Information
L ISTING 8.9 Continued
DownloadServiceListener dsl = ds.getDefaultProgressWindow();
ds.loadResource(url, null, dsl);
} catch (Exception e) {
System.out.println(“Loading Resource: “ + e);
}
}
public static void main(String[] args) {
Splash splash1 = Splash.getInstance();
splash1.showUp(true);
splash1.run();
}
180:}
First of all, we should discuss some design considerations. Given its nature, a splash window is
inherently a singleton; that is, a class that could have at most one instance at time (see Chapter
11 for some details on this design pattern). Inevitably, many details have been omitted. Given
the space we have here, we necessarily have to limit features to the essential ones. It is up to
you to expand the proposed code, as needed. Chapter 13 describes a whole application in
detail.
The singleton is implemented, as usual, via a private constructor and a getInstance() static
method. Note that the window pop-up and thread run have been kept separate for more
flexibility.
T IP
If you want to make the class threaded, add the following line in the main method,
just before invoking the run method:
Thread t = new Thread(splash1);
We omitted it for simplicity because the example is so simple that it doesn't really
need any multithreaded support. Anyway, real-world installers often extensively use
threads for improving performances.
Something that has been kept sketched in the code is the way data is passed on to the installer,
by means of static arrays. One can figure out more flexible mechanisms, such as main() para-
meters or system properties (as illustrated in other code examples), which are less hard-wired
and modifiable from outside the Java class. Also, the initialization of the codebase variable at
Search WWH ::




Custom Search