📄 booklendcountaction.java
字号:
package librarymanagement.action.dialogAction;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.Iterator;
import java.util.Vector;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import librarymanagement.common.ExportInfo;
import librarymanagement.dao.booklendcountDao.BookLendCountDao;
import librarymanagement.view.common.CommonTable;
import librarymanagement.view.dialog.BooksLendCount;
import librarymanagement.vo.BookLendCountVo;
public class BookLendCountAction implements ActionListener{
BooksLendCount count;
JFileChooser filechooser;
public BookLendCountAction(BooksLendCount count) {
this.count = count;
}
public void actionPerformed(ActionEvent e) {
String name = e.getActionCommand();
if(name.equals("开始统计")){
BookLendCountDao dao = new BookLendCountDao();
Vector v = dao.getBookLendCountInfo();
JTable table = count.buildTable();
initialJTable(table,v);
}else if(name.equals("导出Excel")){
String fileName = null;
filechooser = new JFileChooser();
filechooser.setCurrentDirectory(new File("E:"));
filechooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
File file = null;
int result = filechooser.showSaveDialog(count);
if(result == filechooser.APPROVE_OPTION){
file = filechooser.getSelectedFile();
fileName = file.getAbsolutePath();
}else{
return;
}
BookLendCountDao dao = new BookLendCountDao();
Vector v = dao.getBookLendCountInfo();
ExportInfo exportInfo = new ExportInfo();
exportInfo.writeExcelFile(fileName, v);
JOptionPane.showMessageDialog(null, "已导出到指定目录下,请刷新工程");
}else if(name.equals("退出")){
count.dispose();
}
}
private void initialJTable(JTable table ,Vector v ){
DefaultTableModel model = (DefaultTableModel) table.getModel();
int row = model.getRowCount();
for(int i = row-1;i>=0;i--){
model.removeRow(i);
}
/*if(v.isEmpty()){
System.out.println("Vector中没有取到数据");
return;
}*/
Iterator iter = v.iterator();
while(iter.hasNext()){
BookLendCountVo value =(BookLendCountVo)iter.next();
/*System.out.println(value.getBook_id()+" "+value.getBook_name()+" "+value.getReader_id()+value.getReader_name()+" "+
value.getShouldReturnDate());*/
Object[] data={new Integer(value.getBook_id()),value.getBook_name(),new Integer(value.getReader_id()),
value.getReader_name(),value.getBorrow_date(),
value.getShouldReturnDate()};
//System.out.println(data[0]);
model.addRow(data);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -