-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHeroTableModel.java
More file actions
44 lines (35 loc) · 1.05 KB
/
Copy pathHeroTableModel.java
File metadata and controls
44 lines (35 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package pane;
import java.util.List;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.table.AbstractTableModel;
public class HeroTableModel extends AbstractTableModel {
String[] columnNames =new String[] {"id","name","hp","damage"};
public List<Hero> heros=new HeroDao().list();
public int getRowCount() {
return heros.size();
}
public int getColumnCount() {
return columnNames.length;
}
public String getColumnName(int columnIndex) {
return columnNames[columnIndex];
}
public boolean isCellEditable(int rowIndex,int columnIndex) {
return false;
}
public Object getValueAt(int rowIndex, int columnIndex) {
Hero h=heros.get(rowIndex);
if(0==columnIndex)
return h.id;
if(1==columnIndex)
return h.name;
if(2==columnIndex)
return h.hp;
if(3==columnIndex)
return h.damage;
return null;
}
}