Java The Complete Reference, Seventh Edition
968 Part IV: Applying Java private URL url; // download URL private int size; // size of download in bytes private int downloade ...
Chapter 33: Creating a Download Manager in Java 969 // Mark this download as having an error. private void error() { status = ER ...
970 Part IV: Applying Java // Open file and seek to the end of it. file = new RandomAccessFile(getFileName(url), "rw"); file.see ...
Chapter 33: Creating a Download Manager in Java 971 // Notify observers that this download's status has changed. private void st ...
972 Part IV: Applying Java First,run( )sets up variables for the network stream that the download’s contents will be read from a ...
Chapter 33: Creating a Download Manager in Java 973 are organized into numeric ranges of 100, and the 200 range indicates succes ...
974 Part IV: Applying Java } else { buffer = new byte[size - downloaded]; } // Read from server into buffer. int read = stream.r ...
Chapter 33: Creating a Download Manager in Java 975 // Close connection to server. if (stream != null) { try { stream.close(); } ...
976 Part IV: Applying Java // This class renders a JProgressBar in a table cell. class ProgressRenderer extends JProgressBar imp ...
Chapter 33: Creating a Download Manager in Java 977 // These are the names for the table's columns. private static final String[ ...
// Get value for a specific row and column combination. public Object getValueAt(int row, int col) { Download download = downloa ...
Chapter 33: Creating a Download Manager in Java 979 This method first registers itself with the newDownloadas anObserverinterest ...
return Download.STATUSES[download.getStatus()]; } return ""; } This method first looks up theDownloadcorresponding to the row sp ...
// Add download text field. private JTextField addTextField; // Download table's data model. private DownloadsTableModel tableMo ...
982 Part IV: Applying Java addPanel.add(addTextField); JButton addButton = new JButton("Add Download"); addButton.addActionListe ...
resumeButton.setEnabled(false); buttonsPanel.add(resumeButton); cancelButton = new JButton("Cancel"); cancelButton.addActionList ...
verifiedUrl = new URL(url); } catch (Exception e) { return null; } // Make sure URL specifies a file. if (verifiedUrl.getFile(). ...
selectedDownload = null; updateButtons(); } /* Update each button's state based off of the currently selected download's status. ...
986 Part IV: Applying Java SwingUtilities.invokeLater(new Runnable() { public void run() { DownloadManager manager = new Downloa ...
Chapter 33: Creating a Download Manager in Java 987 // Verify download URL. private URL verifyUrl(String url) { // Only allow HT ...
«
44
45
46
47
48
49
50
51
52
53
»
Free download pdf