?? downloadstablemodel.java
字號:
import java.util.*;
import javax.swing.*;
import javax.swing.table.*;
class DownloadsTableModel extends AbstractTableModel implements Observer {
private static final String[] columnNames = {"下載地址", "大小", "進度", "狀態"};
private static final Class[] columnClasses = {String.class, String.class, JProgressBar.class, String.class};
private ArrayList downloadList = new ArrayList();
public void addDownload(Download download) {
download.addObserver(this);
downloadList.add(download);
fireTableRowsInserted(getRowCount() - 1, getRowCount() - 1);
}
public Download getDownload(int row) {
return (Download) downloadList.get(row);
}
public void clearDownload(int row) {
downloadList.remove(row);
fireTableRowsDeleted(row, row);
}
public int getColumnCount() {
return columnNames.length;
}
public String getColumnName(int col) {
return columnNames[col];
}
public Class getColumnClass(int col) {
return columnClasses[col];
}
public int getRowCount() {
return downloadList.size();
}
public Object getValueAt(int row, int col) {
Download download = (Download) downloadList.get(row);
switch (col) {
case 0: // 地址
return download.getUrl();
case 1: // 文件大小
int size = download.getSize();
return (size == -1) ? "" : Integer.toString(size);
case 2: // 進度條
return new Float(download.getProgress());
case 3: // 狀態欄
return Download.STATUSES[download.getStatus()];
}
return "";
}
public void update(Observable o, Object arg) {
int index = downloadList.indexOf(o);
fireTableRowsUpdated(index, index);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -