📄 booktablemodel.java
字号:
package frame;import javax.swing.table.*;import java.util.*;import book.*;public class BookTableModel extends DefaultTableModel { private static String colNames[]; //constructor private BookTableModel(Vector myData, Vector cols) { super(myData, cols); } //static method to new a object public static BookTableModel getBookModel(Collection data, String names[]) { colNames = names; Vector myData = genData(data); Vector cols = genColNames(names); return new BookTableModel(myData, cols); } //method to get the colNames Array public String[] getColNames() { return this.colNames; } //method to generate colnames public static Vector genColNames (String names[]) { Vector result = new Vector(); for(int i = 0; i < names.length ; i++) { result.add(names[i]); } return result; } //method to generate multi-column data public static Vector genData(Collection data) { Vector result = new Vector(); Vector tem = null; Book bk = null; Iterator i = data.iterator(); while(i.hasNext()) { bk = (Book)i.next(); tem = genRowData(bk); result.add(tem); } return result; } //method to generate single row data public static Vector genRowData(Book bk) { // System.out.println(bk); Vector result = new Vector(); for(int i = 0; i < colNames.length; i++) { if(colNames[i].equals(Book.KEY)) result.add(new Integer(bk.getBookId())); else if(colNames[i].equals(Book.NAME)) result.add(bk.getName()); else if(colNames[i].equals(Book.AUTHOR)) result.add(bk.getAuthor()); else if(colNames[i].equals(Book.PUBLISH)) result.add(bk.getFrom()); else if(colNames[i].equals(Book.TYPE)) result.add(new Integer(bk.getBookType())); else if(colNames[i].equals(Book.COST)) result.add(new Double(bk.getCost())); } return result; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -