new JButton (\确定\};
private JLabel jl=new JLabel(\请输入你的学号:\
private JTextField jtxt=new JTextField();
//创建标题
Vector
head.add(\书号\head.add(\学号\head.add(\借阅时间\head.add(\还书时间\head.add(\是否过期\head.add(\是否预约\} //
Vector
DefaultTableModel dtm=new DefaultTableModel(data,head); //创建Jtable对象
JTable jt=new JTable(dtm); //将JTable封装到滚动窗格
JScrollPane jspn=new JScrollPane(jt); public ReturnBook() {
this.setLayout(new GridLayout(1,1));
//设置整个RetrunBook界面上下部分均为空布局管理器 jpt.setLayout(null); jpb.setLayout(null); //设置Label的大小及位置 jl.setBounds(5,15,100,20); //将Jlabel添加到jpt面板上 jpt.add(jl);
//为JTextField设置大小及位置 jtxt.setBounds(105,15,300,20); //把JTextField添加到jpt jpt.add(jtxt);
//设置JBuuton的大小及位置
jbArray[0].setBounds(5,50,100,20); jbArray[1].setBounds(150,50,100,20); jbArray[2].setBounds(295,50,100,20); //添加JButton并给其添加事件监听器 for(int i=0;i<3;i++)
{
jpt.add(jbArray[i]);
jbArray[i].addActionListener(this); }
//把jpt设置到jsp的上部窗格 jsp.setTopComponent(jpt); //jpb.add(jspn);
jsp.setBottomComponent(jspn); jsp.setDividerSize(4); this.add(jsp);
//设置jsp中分割条的初始位置 jsp.setDividerLocation(80); //设置窗体的大小位置及可见性
this.setBounds(10,10,800,600); this.setVisible(true); }
public void actionPerformed(ActionEvent e) {
if(e.getSource()==jbArray[2]){//事件源为\确定\按钮
if(jtxt.getText().trim().equals(\学号输入为空,提示 JOptionPane.showMessageDialog(this,\请输入学号\\消息\return; }
else{//根据学号进行查询
sql=\db=new DataBase(); db.selectDb(sql);
Vector
while(db.rs.next()){//取到结果集 k++;
Vector
str=new String(str.getBytes(\v.add(str); }
vtemp.add(v);//将各条记录添加到临时数组vtemp //更新table
jt.clearSelection();
dtm.setDataVector(vtemp,head);
jt.updateUI(); jt.repaint(); }
if(k==0){//提示
JOptionPane.showMessageDialog(this,\输入了错误的学号或该学生没有借书记录\
\消息\return; } }
catch(Exception ea){ea.printStackTrace();} } }
if(e.getSource()==jbArray[1]){//当要归还图书 int row=jt.getSelectedRow();
if(row<0){//如果未选中下部表中的某些内容,进行提示
JOptionPane.showMessageDialog(this,\请选择要归还的书!!!\消息\JOptionPane.INFORMATION_MESSAGE); return; }
str=(String)jt.getValueAt(row,0);//得到书号
int sno=Integer.parseInt((String)jt.getValueAt(row,1)); int bno=Integer.parseInt(str);
int flag=checkTime(sno,bno); //判断是否超期
if(flag==-1){//如果图书超期,则将取消该同学的借书权限 db=new DataBase();
sql=\否' where StuNO=\db.updateDb(sql); db.dbClose(); }
if(flag==0){return;}//如果图书未超期,则进行归还操作
sql=\db=new DataBase(); db.updateDb(sql);
sql=\否' where BookNO=\
db.updateDb(sql);//更新了图书记录,设该书号的数为可借 db.dbClose(); updateTable(); }
if(e.getSource()==jbArray[0]){//需要挂失图书 int row=jt.getSelectedRow(); if(row<0){
JOptionPane.showMessageDialog(this,\请选择要挂失的书!!!\消息\JOptionPane.INFORMATION_MESSAGE); return; }
loseBook(row); updateTable(); } }
public void loseBook(int row){ String bname=\int lbno=0;
int bno=Integer.parseInt((String)jt.getValueAt(row,0));//得到丢失书的书号
String sno=(String)jt.getValueAt(row,1);//得到丢失书的人学号 sql=\db=new DataBase(); db.selectDb(sql); try{
if(db.rs.next()){
bname=db.rs.getString(1).trim();//得到丢失书的书名 } }
catch(Exception e){e.printStackTrace();} //找到最大的丢失记录号
sql=\db.selectDb(sql); try{
if(db.rs.next()){
lbno=db.rs.getInt(1);//得到最大的丢失记录号 lbno++; } }
catch(Exception ea){ea.printStackTrace();} sql=\
values(\向丢书记录表中插入记录
db.updateDb(sql);
sql=\检查预约表中是否预约该书,若有,删除 db.selectDb(sql); try{
while(db.rs.next()){//删除记录
sql=\
db.updateDb(sql); } }
catch(Exception e){e.printStackTrace();}
sql=\检查超期表中是否有该书,若有,删除 db.selectDb(sql); try{
while(db.rs.next()){//从超期表中删除记录
sql=\db.updateDb(sql); } }
catch(Exception e){e.printStackTrace();}
sql=\从借书表中将丢失图书的记录删除
db.updateDb(sql);
sql=\从图书表中将丢失的书删除
int i=db.updateDb(sql); db.dbClose();
if(i>0){//提示挂失成功
JOptionPane.showMessageDialog(this,\恭喜你,挂失成功!!!\消息\JOptionPane.INFORMATION_MESSAGE); return; }
else{//提示挂失失败
JOptionPane.showMessageDialog(this,\对不起,挂失失败!!!\\信息\return; } }
public void updateTable(){//实现界面下部表格的更新
sql=\db=new DataBase();
db.selectDb(sql);//将图书信息从数据库中取出 Vector
while(db.rs.next()){
Vector
str=new String(str.getBytes(\v.add(str);