Java Reference
In-Depth Information
The width and height attributes, which also can be used with the other kind of icon
graphic, specify the image's display size in pixels.
This second icon element should be placed inside the information element.
NOTE
For more information on using the technology with your own appli-
cations, visit Sun's Java Web Start site at the following address:
http://java.sun.com/products/javawebstart
Improving Performance with SwingWorker
The responsiveness of a Swing application depends largely on how well the software
handles time-consuming tasks in response to user input.
Applications ordinarily execute tasks in one thread, so if something takes a long time to
accomplish, such as loading a large file or parsing data from an XML document, the user
might notice a lag in performance while this is taking place.
Swing programs also require all user-interface components to be running within the same
thread.
The best way to take care of both requirements is to use SwingWorker , a new class in the
javax.swing package that's designed to run time-consuming tasks in their own worker
thread and report the result.
SwingWorker is an abstract class that must be subclassed by applications that require a
worker:
public class DiceWorker extends SwingWorker {
// ...
}
The doInBackground() method should be overridden in the new class to perform the
task, as in this example that rolls six-sided dice a large number of times and tracks the
results:
doInBackground() {
for (int i = 0; i < timesToRoll; i++) {
int sum = 0;
for (int j = 0; j < 3; j++) {
sum += Math.floor(Math.random() * 6);
}
 
Search WWH ::




Custom Search