return Download.STATUSES[download.getStatus()];
}
return "";
}
This method first looks up theDownloadcorresponding to the row specified. Next, the
column specified is used to determine which one of theDownload’s property values to return.
The update( ) Method
Theupdate( )method is shown here. It fulfills theObserverinterface contract allowing the
DownloadsTableModelclass to receive notifications fromDownloadobjects when they
change.
/* Update is called when a Download notifies its
observers of any changes. */
public void update(Observable o, Object arg) {
int index = downloadList.indexOf(o);
// Fire table row update notification to table.
fireTableRowsUpdated(index, index);
}
This method is passed a reference to theDownloadthat has changed, in the form of an
Observableobject. Next, an index to that download is looked up in the list of downloads,
and that index is then used to fire a table row update event notification, which alerts the
table that the given row has been updated. The table will then rerender the row with the
given index, reflecting its new values.
The DownloadManager Class
Now that the foundation has been laid by explaining each of the Download Manager ’s helper
classes, we can look closely at theDownloadManagerclass. TheDownloadManagerclass is
responsible for creating and running the Download Manager ’s GUI. This class has amain( )
method declared, so on execution it will be invoked first. Themain( )method instantiates a
newDownloadManagerclass instance and then calls itsshow( )method, which causes it to
be displayed.
TheDownloadManagerclass is shown here. Notice that it extendsJFrameand implements
Observer. The following sections examine it in detail.
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
// The Download Manager.
public class DownloadManager extends JFrame
implements Observer
{
980 Part IV: Applying Java