所以我有這個代碼,因爲我需要添加照片到我的JTable,所以我需要做一個抽象的表模型。然而,看到這段代碼後,我真的不知道它做了什麼,但我真的很想理解它。如果你可以請給我解釋一下,那真是太棒了! (我也不知道Icon.class在代碼中做了什麼)。代碼如下:需要解釋什麼代碼
public class TheModel extends AbstractTableModel {
private String[] columns;
private Object[][] rows;
public TheModel(){}
public TheModel(Object[][] data, String[] columnName){
this.rows = data;
this.columns = columnName;
}
public Class getColumnClass(int column){
// 4 is the index of the column image
if(column == 4){
return Icon.class;
}
else{
return getValueAt(0,column).getClass();
}
}
public int getRowCount() {
return this.rows.length;
}
public int getColumnCount() {
return this.columns.length;
}
public Object getValueAt(int rowIndex, int columnIndex) {
return this.rows[rowIndex][columnIndex];
}
public String getColumnName(int col){
return this.columns[col];
}
}
每個解釋都非常感謝!我知道這個網站主要是爲了幫助編碼問題而不是解釋,但我真的希望你們能夠例外。
*「我真的希望你們可以例外「* ...不。 –
@AndrewThompson該死的。 –
我建議你在問題導向的基礎上提問。您擁有的標題並未真正顯示您遇到問題,但會發送一個錯誤想法標題的消息。 – Pablo