📄 booktablemodellistener.java
字号:
package frame;import javax.swing.table.*;import javax.swing.event.*;import book.*;import userexception.*;public class BookTableModelListener implements TableModelListener{ private BookTableModel tm = null; private BookList bl = null; private LendList ll = null; //constructor public BookTableModelListener(BookTableModel tm, BookList bl, LendList ll) { this.tm = tm; this.bl = bl; this.ll = ll; } //actions public void tableChanged(TableModelEvent e) { if(e.getType() == TableModelEvent.UPDATE) { int row = e.getFirstRow(); int col = e.getColumn(); //get the key position : in which column int keyPos = col; String[] names = tm.getColNames(); for(int i = 0; i < names.length; i++) { if(names[i].equals(Book.KEY)) { keyPos = i; break; } } System.out.println("KEY POS:" + keyPos); if(! (keyPos == col)) { //do update Book bk = new Book(0,"","",0,0,""); String key = (String)tm.getValueAt(row,keyPos); System.out.println("KEY:" + key); String ChangeValue = tm.getValueAt(row,col).toString(); System.out.println(ChangeValue); /* //tm.setValueAt(ChangeValue,row,col); for(int i = 0; i< names.length; i++) { if(names[i].equals(Book.KEY)) bk.setBookId(Integer.parseInt((String)tm.getValueAt(row,i))); else if(names[i].equals(Book.AUTHOR)) bk.setAuthor((String)tm.getValueAt(row,i)); else if(names[i].equals(Book.NAME)) bk.setName((String)tm.getValueAt(row,i)); else if(names[i].equals(Book.TYPE)) bk.setBookType(Integer.parseInt((String)tm.getValueAt(row,i))); else if(names[i].equals(Book.COST)) bk.setCost(Double.parseDouble((String)tm.getValueAt(row,i))); else if(names[i].equals(Book.PUBLISH)) bk.setFrom((String)tm.getValueAt(row,i)); } try { bl.modifyBook(bk); } catch(BookNotFoundException evt) { System.out.println(evt.getMessage()); } */ } } else if(e.getType() == TableModelEvent.INSERT) { } else if(e.getType() == TableModelEvent.DELETE) { } } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -