java图书管理系统代码版
图书管理系统java代码
组员分工: 刘会敏:图书管理(增,删,查询,修改图书信息)方法 及部分页面, 链接数据库 (DatabaseConn2) 宁俊明:主界面(bookMain),登录注册界面面板(RLogin), 修改个人信息,添加、删除成员 方法 王盛开:登录注册方法(userbean),查看我借的书页面,添加删除成员页面,添加删除图书 页面
} // end main method
@Override public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub //String sex, type;
// 用户点击登录确定按钮 if (e.getSource() == btn_ok1) {
增加图书 (bookAdd, bookbean) 修改图书信息 (bookEdit, bookbean) 删除图书 (bookDel, bookbean) 添加成员 (memberAdd, memberBean) 删除成员 (memberDelete, memberBean )
修改个人信息 (personInfo, personBean) 查看我借的书 (mybook, lookMybook)
登录: 姓名:
注册:
姓名
பைடு நூலகம்密码
学号
密码:
我是:本科生 研 究生
所在院教系师
登录
专业 注册
设置变量: username,sex, password, userID,userType, department, major
向 user 表 插入数据
登录注册页面:
package bookDB;
import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener;
基于java的图书管理系统源代码
声明:本系统是基于C/S的图书管理系统,主要使用的是Oracle数据库,下面附所有实现代码package library;public class book_add extends JFrame implements ActionListener{DataBaseManager db=new DataBaseManager();ResultSet rs;JPanel panel1,panel2;JLabel book_id_label,book_name_label,author_label,press_label,press_date_label,price_label,book_num_label,borrowed_num_label,address;JTextField book_id_TextField,book_name_TextField,author_TextField,press_TextField,press_date_TextField,price_TextField,book_num_TextField,borrowed_count;JComboBox addresst;Container c;JButton clear,add,exit;public book_add(){super("添加图书信息");c=getContentPane();c.setLayout(new BorderLayout());book_id_label=new JLabel("编号",JLabel.CENTER);book_name_label=new JLabel("名称",JLabel.CENTER);author_label=new JLabel("作者",JLabel.CENTER);press_label=new JLabel("出版社",JLabel.CENTER);press_date_label=new JLabel("出版日期",JLabel.CENTER);price_label=new JLabel("价格",JLabel.CENTER);book_num_label=new JLabel("库存数",JLabel.CENTER);borrowed_num_label=new JLabel("已借阅数",JLabel.CENTER);address=new JLabel("藏书地址",JLabel.CENTER);book_id_TextField=new JTextField(15);book_name_TextField=new JTextField(15);author_TextField=new JTextField(15);press_TextField=new JTextField(15);press_date_TextField=new JTextField(15);price_TextField=new JTextField(15);book_num_TextField=new JTextField(15);borrowed_count=new JTextField(15);borrowed_count.setText("0");addresst=new JComboBox();addresst.addItem("扬子津图书馆");addresst.addItem("荷花池图书馆");addresst.addItem("瘦西湖图书馆");addresst.addItem("淮海路图书馆");panel1=new JPanel();panel1.setLayout(new GridLayout(9,2));panel1.add(book_id_label);panel1.add(book_id_TextField);panel1.add(book_name_label);panel1.add(book_name_TextField);panel1.add(press_label);panel1.add(press_TextField);panel1.add(author_label);panel1.add(author_TextField);panel1.add(press_date_label);panel1.add(press_date_TextField);panel1.add(price_label);panel1.add(price_TextField);panel1.add(book_num_label);panel1.add(book_num_TextField);panel1.add(borrowed_num_label);panel1.add(borrowed_count);panel1.add(address);panel1.add(addresst);panel2=new JPanel();panel2.setLayout(new GridLayout(1,3));clear=new JButton("清空");clear.addActionListener(this);add=new JButton("添加");add.addActionListener(this);exit=new JButton("退出");exit.addActionListener(this);panel2.add(clear);panel2.add(add);panel2.add(exit);c.add(panel1,BorderLayout.CENTER);c.add(panel2,BorderLayout.SOUTH);setVisible(true);}public void actionPerformed(ActionEvent e) {if(e.getSource()==exit){this.dispose();}else if(e.getSource()==clear){book_id_TextField.setText("");book_name_TextField.setText("");author_TextField.setText("");press_TextField.setText("");press_date_TextField.setText("");price_TextField.setText("");book_num_TextField.setText("");}else if(e.getSource()==add){if(book_id_TextField.getText().trim().equals("")){JOptionPane.showMessageDialog(null, "书号不能为空");}else if(book_name_TextField.getText().trim().equals("")){JOptionPane.showMessageDialog(null, "书名不能为空");}else if(author_TextField.getText().trim().equals("")){JOptionPane.showMessageDialog(null, "作者不能为空");}else if(press_TextField.getText().trim().equals("")){JOptionPane.showMessageDialog(null, "出版社不能为空");}else if(press_date_TextField.getText().trim().equals("")){JOptionPane.showMessageDialog(null, "出版日期不能为空");}else if(price_TextField.getText().trim().equals("")){JOptionPane.showMessageDialog(null, "价格不能为空");}else if(book_num_TextField.getText().trim().equals("")){JOptionPane.showMessageDialog(null, "库存不能为空");}else if(borrowed_count.getText().trim().equals("")){JOptionPane.showMessageDialog(null, "借阅数不能为空");}else {try{String strSQL="insert into book(book_id,book_name,press,author,press_date,price,book_count,borrowed_count,store_addres s) values('"+book_id_TextField.getText().trim()+"','"+book_name_TextField.getText().trim()+"','"+press_TextField.getText().trim()+"','"+author_TextField.getText().trim()+"','"+press_date_TextField.getText().trim()+"','"+price_TextField.getText().trim()+"','"+book_num_TextField.getText().trim()+"','"+borrowed_count.getText().trim()+"','"+addresst.getSelectedItem()+"')";if(db.updateSql(strSQL)){this.dispose();JOptionPane.showMessageDialog(null,"添加图书成功");}else{JOptionPane.showMessageDialog(null,"添加图书失败");this.dispose();}db.closeConnection();}catch(Exception ex){}}}}}package library;import javax.swing.*;import java.awt.*;public class book_delete extends JFrame implements ActionListener{DataBaseManager db=new DataBaseManager();ResultSet rs;Container c;JLabel TipLabel=new JLabel("请选择要删除的书名",JLabel.CENTER);JComboBox bb=new JComboBox();JButton yes,exit;JPanel panel1=new JPanel();public book_delete(){super("删除图书信息");c=getContentPane();c.setLayout(new BorderLayout());try{String strSQL="select book_name from book where book_count>borrowed_count";rs=db.getResult(strSQL);while(rs.next()){bb.addItem(rs.getString(1));}}catch(SQLException sqle){}catch(Exception ex){}c.add(TipLabel,BorderLayout.NORTH);c.add(bb,BorderLayout.CENTER);yes=new JButton("确定");exit=new JButton("退出");yes.addActionListener(this);exit.addActionListener(this);panel1.add(yes);panel1.add(exit);c.add(panel1,BorderLayout.SOUTH);setVisible(true);}public void actionPerformed(ActionEvent e){if(e.getSource()==exit){this.dispose();}else if(e.getSource()==yes){try{String strSQL="select borrowed_count from book where book_name='"+bb.getSelectedItem()+"'";rs=db.getResult(strSQL);if(!rs.first()){JOptionPane.showMessageDialog(null,"书库里没有你要删除的书");}else{String strSql="delete from book where book_name='"+bb.getSelectedItem()+"'and borrowed_count=0";rs.first();int count=rs.getInt(1);if(!(count==0)){JOptionPane.showMessageDialog(null,"此书还有学生没有还,不可删除");}else if(db.updateSql(strSql)){JOptionPane.showMessageDialog(null,"删除成功");db.closeConnection();this.dispose();}else{JOptionPane.showMessageDialog(null,"删除失败");db.closeConnection();this.dispose();}}}catch(SQLException sqle){}catch(Exception ex){}}}}package library;public class book_modify extends JFrame implements ActionListener{DataBaseManager db=new DataBaseManager();ResultSet rs;JPanel panel1,panel2,panel3;JLabel TipLabel=new JLabel("输入书名点确定,将调出此书的相关信息");JLabel book_name_label,author_label,press_label,press_date_label,price_label;JTextField book_name_TextField,author_TextField,press_TextField,press_date_TextField,price_TextField;Container c;JButton clear,yes,update,exit;public book_modify(){super("修改图书信息");c=getContentPane();c.setLayout(new BorderLayout());panel3=new JPanel();panel3.add(TipLabel);c.add(panel3,BorderLayout.NORTH);book_name_label=new JLabel("名称",JLabel.CENTER);author_label=new JLabel("作者",JLabel.CENTER);press_label=new JLabel("出版社",JLabel.CENTER);press_date_label=new JLabel("出版日期",JLabel.CENTER);price_label=new JLabel("价格",JLabel.CENTER);book_name_TextField=new JTextField(15);author_TextField=new JTextField(15);press_TextField=new JTextField(15);press_date_TextField=new JTextField(15);price_TextField=new JTextField(15);panel1=new JPanel();panel1.setLayout(new GridLayout(6,2));panel1.add(book_name_label);panel1.add(book_name_TextField);panel1.add(author_label);panel1.add(author_TextField);panel1.add(press_label);panel1.add(press_TextField);panel1.add(press_date_label);panel1.add(press_date_TextField);panel1.add(price_label);panel1.add(price_TextField);panel2=new JPanel();panel2.setLayout(new GridLayout(1,4));clear=new JButton("清空");yes=new JButton("确定");update=new JButton("更新");exit=new JButton("退出");panel2.add(clear);panel2.add(yes);panel2.add(update);panel2.add(exit);clear.addActionListener(this);yes.addActionListener(this);update.addActionListener(this);exit.addActionListener(this);update.setEnabled(false);c.add(panel1,BorderLayout.CENTER);c.add(panel2,BorderLayout.SOUTH);setVisible(true);}public void actionPerformed(ActionEvent e){if(e.getSource()==exit){this.dispose();;}else if(e.getSource()==clear){book_name_TextField.setText("");author_TextField.setText("");press_TextField.setText("");press_date_TextField.setText("");price_TextField.setText("");}else if(e.getSource()==yes){try{String strSQL="select * from book where book_name='"+book_name_TextField.getText().trim()+"'";rs=db.getResult(strSQL);while(rs.next()){book_name_TextField.setText(rs.getString("book_name"));author_TextField.setText(rs.getString("author"));press_TextField.setText(rs.getString("press"));press_date_TextField.setText(rs.getString("press_date"));price_TextField.setText(rs.getString("price"));}update.setEnabled(true);}catch(NullPointerException upe){}catch(Exception es){}}else if(e.getSource()==update){try{String strSQL="update book set book_name='"+book_name_TextField.getText().trim()+"',press='"+press_TextField.getText().trim()+"',author='"+author_TextField.getText().trim()+"',press_date='"+press_date_TextField.getText().trim()+"',price='"+price_TextField.getText().trim()+"' where book_name='"+book_name_TextField.getText().trim()+"'";if(db.updateSql(strSQL)){this.dispose();JOptionPane.showMessageDialog(null,"更新图书成功");}else {JOptionPane.showMessageDialog(null,"更新图书失败");}db.closeConnection();}catch(Exception sqle){}}}}package library;public class bookborrow extends JFrame implements ActionListener{DataBaseManager db=new DataBaseManager();ResultSet rs;Container c;JPanel panel1,panel2;JLabel borrowname,bookname,borrowdate,returndate,is_return_label;JTextField borrowdateField,returndateField,is_return;JButton clear,yes,cancel;JComboBox borrownameBox=new JComboBox();JComboBox booknameBox=new JComboBox();public bookborrow(){super("书籍出借");c=getContentPane();c.setLayout(new BorderLayout());Calendar cal = Calendar.getInstance();int year,month,day;// year=cal.get(Calendar.YEAR);// month=cal.get(Calendar.MONTH)+3;//从0开始的// day=cal.get(Calendar.DAY_OF_MONTH);// String cdate = sdf.format(cal.getTime());// String da=Integer.toString(year)+"-0"+Integer.toString(month)+"-"+Integer.toString(day);borrowname=new JLabel("借阅者姓名",JLabel.CENTER);bookname=new JLabel("书名",JLabel.CENTER);borrowdate=new JLabel("借书日期",JLabel.CENTER);// returndate=new JLabel("应还日期",JLabel.CENTER);is_return_label=new JLabel("是否归还",JLabel.CENTER);borrowdateField=new JTextField(15);// borrowdateField.setText(cdate);// returndateField=new JTextField(15);// returndateField.setText(da);is_return=new JTextField(15);is_return.setText("否");try{String strSql="select student_name from reader ";rs=db.getResult(strSql);while(rs.next()){borrownameBox.addItem(rs.getString(1));}}catch(SQLException sqle){}catch(Exception ex){}try{String strSQL="select book_name from book where book_count>borrowed_count";rs=db.getResult(strSQL);while(rs.next()){booknameBox.addItem(rs.getString(1));}}catch(SQLException sqle){}catch(Exception ex){}panel1=new JPanel();panel1.setLayout(new GridLayout(5,2));panel1.add(borrowname);panel1.add(borrownameBox);panel1.add(bookname);panel1.add(booknameBox);panel1.add(borrowdate);panel1.add(borrowdateField);// panel1.add(returndate);// panel1.add(returndateField);panel1.add(is_return_label);panel1.add(is_return);c.add(panel1,BorderLayout.CENTER);panel2=new JPanel();panel2.setLayout(new GridLayout(1,3));clear=new JButton("清空");yes=new JButton("确定");cancel=new JButton("取消");clear.addActionListener(this);yes.addActionListener(this);cancel.addActionListener(this);panel2.add(clear);panel2.add(yes);panel2.add(cancel);c.add(panel2,BorderLayout.SOUTH);setVisible(true);setSize(300,300);}public void actionPerformed(ActionEvent e){if(e.getSource()==cancel){this.dispose();}else if(e.getSource()==clear){borrowdateField.setText("");// returndateField.setText("");is_return.setText("");}else if(e.getSource()==yes){if(borrownameBox.getSelectedItem().equals("")){JOptionPane.showMessageDialog(null, "对不起,没有读者借阅");}else if(booknameBox.getSelectedItem().equals("")){JOptionPane.showMessageDialog(null, "对不起,现在书库没有书");}else {try{//系统计算归还日期//获取输入的借阅日期,自动加两个月String startDate=borrowdateField.getText().trim();SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");Date dateStart=format.parse(startDate);Calendar cd=Calendar.getInstance();cd.setTime(dateStart);cd.add(Calendar.MONTH, 2);String returnDate=format.format(cd.getTime());String strSQL="insert into borrow(student_name,book_name,borrow_date,return_date,is_returned) values('"+borrownameBox.getSelectedItem()+"','"+booknameBox.getSelectedItem()+"','"+borrowdateField.getText().trim()+"','"+returnDate+"','"+is_return.getText().trim()+"')";if(db.updateSql(strSQL)){JOptionPane.showMessageDialog(null, "借阅完成");strSQL = "update reader set borrow_count=borrow_count+1 where student_name='"+borrownameBox.getSelectedItem()+"'";db.updateSql(strSQL);strSQL="update book set borrowed_count=borrowed_count+1 where book_name='"+booknameBox.getSelectedItem()+"'";db.updateSql(strSQL);db.closeConnection();this.dispose();}else{JOptionPane.showMessageDialog(null, "借阅失败");db.closeConnection();this.dispose();}}catch(Exception se){}}}}}package library;import javax.swing.*;import java.awt.*;public class bookborrowlist extends JFrame implements ActionListener{DataBaseManager db=new DataBaseManager();ResultSet rs;Container c;JPanel panel1,panel2;JLabel bookname,studentname;JTextField booknamet,studentnamet;JButton search,exit;JTable table=null;DefaultTableModel defaultModel=null;public bookborrowlist(){super("借阅列表");c=getContentPane();c.setLayout(new BorderLayout());bookname=new JLabel("书名",JLabel.CENTER);studentname=new JLabel("人名",JLabel.CENTER);booknamet=new JTextField(15);studentnamet=new JTextField(15);search=new JButton("查询");exit=new JButton("退出");search.addActionListener(this);exit.addActionListener(this);Box box1=Box.createHorizontalBox();box1.add(studentname);box1.add(studentnamet);box1.add(search);Box box2=Box.createHorizontalBox();box2.add(bookname);box2.add(booknamet);box2.add(exit);Box boxH=Box.createVerticalBox();boxH.add(box1);boxH.add(box2);boxH.add(Box.createVerticalGlue());panel1=new JPanel();panel1.add(boxH);panel2=new JPanel();String []name={"读者","书名","借阅时间","应还时间","是否归还"};String [][]data=new String[0][0];defaultModel=new DefaultTableModel(data,name);table=new JTable(defaultModel);table.setPreferredScrollableViewportSize(new Dimension(400,80));JScrollPane s=new JScrollPane(table);panel2.add(s);c.add(panel1,BorderLayout.NORTH);c.add(panel2,BorderLayout.SOUTH);}public void actionPerformed(ActionEvent e){if(e.getSource()==exit){db.closeConnection();this.dispose();}else if(e.getSource()==search){String strSQL="select student_name,book_name,borrow_date,return_date,is_returned from borrow";String strSql=null;if(studentnamet.getText().trim().equals("")&&booknamet.getText().trim().equals("")){strSql=strSQL;}else if(studentnamet.getText().trim().equals("")){strSql="select student_name,book_name,borrow_date,return_date,is_returned from borrow where book_name='"+booknamet.getText().trim()+"'";}else if(booknamet.getText().trim().equals("")){strSql="select student_name,book_name,borrow_date,return_date,is_returned from borrow where student_name='"+studentnamet.getText().trim()+"'";}else{strSql="select student_name,book_name,borrow_date,return_date,is_returned from borrow where student_name='"+studentnamet.getText().trim()+"'and book_name='"+booknamet.getText().trim()+"'";JOptionPane.showMessageDialog(null, "你借的书还还有7天超期");}try{int rowCount=defaultModel.getRowCount()-1;int j=rowCount;for(int i=0;i<=rowCount;i++){defaultModel.removeRow(j);defaultModel.setRowCount(j);j=j-1;}rs=db.getResult(strSql);while(rs.next()){Vector insertRow=new Vector();insertRow.addElement(rs.getString(1));insertRow.addElement(rs.getString(2));insertRow.addElement(rs.getString(3));insertRow.addElement(rs.getString(4));insertRow.addElement(rs.getString(5));defaultModel.addRow(insertRow);}table.revalidate();}catch(SQLException sqle){}catch(Exception ex){}}}}package library;import javax.swing.*;import java.awt.*;public class bookborrowModify extends JFrame implements ActionListener{DataBaseManager db=new DataBaseManager();ResultSet rs;JPanel panel1,panel2,panel3;Container c;JLabel tiplabel=new JLabel("输入借阅者姓名和书名单击确定,将调出此书的相关信息");JLabel borrowlabel,namelabel,borrowdate;JTextField borrowField,nameField,dateField;JButton clear,yes,update,cancel;public bookborrowModify(){super("修改图书出借信息");c=getContentPane();c.setLayout(new BorderLayout());panel3=new JPanel();panel3.add(tiplabel);c.add(panel3,BorderLayout.NORTH);borrowlabel=new JLabel("借阅者姓名",JLabel.CENTER);namelabel=new JLabel("书名",JLabel.CENTER);borrowdate=new JLabel("借书日期",JLabel.CENTER);borrowField=new JTextField(15);nameField=new JTextField(15);dateField=new JTextField(15);panel1=new JPanel();panel1.setLayout(new GridLayout(3,2));panel1.add(borrowlabel);panel1.add(borrowField);panel1.add(namelabel);panel1.add(nameField);panel1.add(borrowdate);panel1.add(dateField);c.add(panel1,BorderLayout.CENTER);panel2=new JPanel();panel2.setLayout(new GridLayout(1,4));clear=new JButton("清空");yes=new JButton("确定");update=new JButton("更新");cancel=new JButton("取消");clear.addActionListener(this);yes.addActionListener(this);update.addActionListener(this);cancel.addActionListener(this);panel2.add(clear);panel2.add(yes);panel2.add(update);panel2.add(cancel);c.add(panel2,BorderLayout.SOUTH);setVisible(true);setSize(400,200);}public void actionPerformed(ActionEvent e){if(e.getSource()==clear){borrowField.setText("");nameField.setText("");dateField.setText("");}else if(e.getSource()==cancel){this.dispose();}else if(e.getSource()==yes){try{String strSQL="select student_name,book_name,borrow_date from borrow where student_name='"+borrowField.getText().trim()+"'and book_name='"+nameField.getText().trim()+"'";rs=db.getResult(strSQL);if(!rs.first()){JOptionPane.showMessageDialog(null,"此学生没有借过书或者没有此书");}else{borrowField.setText(rs.getString(1));nameField.setText(rs.getString(2));dateField.setText(rs.getString(3));update.setEnabled(true);}}catch(Exception ex){}}else if(e.getSource()==update){String strSQL="update borrow set borrow_date='"+dateField.getText().trim()+"' where student_name='"+borrowField.getText().trim()+"'and book_name='"+nameField.getText().trim()+"'";if(db.updateSql(strSQL)){JOptionPane.showMessageDialog(null,"更新成功");db.closeConnection();this.dispose();}else{JOptionPane.showMessageDialog(null,"更新失败");db.closeConnection();this.dispose();}}}}package library;import javax.swing.*;import java.awt.*;public class booklist extends JFrame implements ActionListener{ DataBaseManager db=new DataBaseManager();ResultSet rs;Container c;JPanel panel1,panel2,panel3;JLabel bookname,authorname,press;JTextField booknamet,authornamet,presst;JButton search,exit;JTable table=null;DefaultTableModel defaultModel=null;public booklist(){super("书籍信息查询");c=getContentPane();c.setLayout(new BorderLayout());bookname=new JLabel("书名",JLabel.CENTER);authorname=new JLabel("作者",JLabel.CENTER);press=new JLabel("出版社",JLabel.CENTER);booknamet=new JTextField(15);authornamet=new JTextField(15);presst=new JTextField(15);search=new JButton("查询");exit=new JButton("退出");search.addActionListener(this);exit.addActionListener(this);panel1=new JPanel();panel1.add(bookname);panel1.add(booknamet);panel1.add(authorname);panel1.add(authornamet);panel2=new JPanel();panel2.add(press);panel2.add(presst);panel2.add(search);panel2.add(exit);String []name={"书号","书名","出版社","作者","出版日期","价格","图书数目","已借数目","剩余数目","藏书地址"};String [][]data=new String[0][0];defaultModel=new DefaultTableModel(data,name);table=new JTable(defaultModel);table.setPreferredScrollableViewportSize(new Dimension(400,80));JScrollPane s=new JScrollPane(table);panel3=new JPanel();panel3.add(s);c.add(panel1,BorderLayout.NORTH);c.add(panel2,BorderLayout.CENTER);c.add(panel3,BorderLayout.SOUTH);}public void actionPerformed(ActionEvent e){if(e.getSource()==exit){db.closeConnection();this.dispose();}else if(e.getSource()==search){String strSQL="select book_id,book_name,press,author,press_date,price,book_count,borrowed_count,book_count-borro wed_count,store_address from book";String strSql=null;if(booknamet.getText().trim().equals("")&&authornamet.getText().trim().equals("")&&presst. getText().trim().equals("")){strSql=strSQL;}elseif(booknamet.getText().trim().equals("")&&authornamet.getText().trim().equals("")){strSql="selectbook_id,book_name,press,author,press_date,price,book_count,borrowed_count,book_count-borro wed_count,store_address from book where press='"+presst.getText().trim()+"'";}else if(authornamet.getText().trim().equals("")&&presst.getText().trim().equals("")){strSql="selectbook_id,book_name,press,author,press_date,price,book_count,borrowed_count,book_count-borro wed_count,store_address from book where book_name='"+booknamet.getText().trim()+"'";}else if(booknamet.getText().trim().equals("")&&presst.getText().trim().equals("")){strSql="selectbook_id,book_name,press,author,press_date,price,book_count,borrowed_count,book_count-borro wed_count,store_address from book where author='"+authornamet.getText().trim()+"'";}else{strSql="selectbook_id,book_name,press,author,press_date,price,book_count,borrowed_count,book_count-borro wed_count,store_address from book where book_name='"+booknamet.getText().trim()+"'and author='"+authornamet.getText().trim()+"'and press='"+presst.getText().trim()+"'";}try{int rowCount=defaultModel.getRowCount()-1;int j=rowCount;for(int i=0;i<=rowCount;i++){defaultModel.removeRow(j);defaultModel.setRowCount(j);j=j-1;}rs=db.getResult(strSql);while(rs.next()){Vector insertRow=new Vector();insertRow.addElement(rs.getString(1));insertRow.addElement(rs.getString(2));insertRow.addElement(rs.getString(3));insertRow.addElement(rs.getString(4));insertRow.addElement(rs.getString(5));insertRow.addElement(rs.getString(6));insertRow.addElement(rs.getString(7));insertRow.addElement(rs.getString(8));insertRow.addElement(rs.getString(9));insertRow.addElement(rs.getString(10));defaultModel.addRow(insertRow);}table.revalidate();}catch(SQLException sqle){}catch(Exception ex){}}}}package library;import javax.swing.*;import java.awt.*;public class bookreturn extends JFrame implements ActionListener{DataBaseManager db=new DataBaseManager();ResultSet rs;JPanel panel1,panel2;Container c;JLabel namelabel,booklabel,returndatelabel;JTextField returnField;JButton clear,yes,cancel;JComboBox bookname=new JComboBox();JComboBox readername=new JComboBox();public bookreturn(){super("图书还入");c=getContentPane();c.setLayout(new BorderLayout());Calendar cal = Calendar.getInstance();String cdate = sdf.format(cal.getTime());namelabel=new JLabel("还书者姓名",JLabel.CENTER);booklabel =new JLabel("书名",JLabel.CENTER);returndatelabel=new JLabel("日期",JLabel.CENTER);returnField=new JTextField(15);returnField.setText(cdate);try{String s="";String strSQL="select student_name from reader where borrow_count!=0";rs=db.getResult(strSQL);while(rs.next()){readername.addItem(rs.getString(1));}}catch(SQLException sqle){}catch(Exception ex){}。
用java做的一个图书管理系统的源代码
用java做的一个图书管理系统的源代码import .*;import .*;public class T{public static void main(String[] args) throws Exception{Connection conn=null;Statement stmt=null;ResultSet rs=null;while(true){Scanner scanner=new Scanner;"请输入用户名:");String username2=();"请输入密码:");String password2=();if(!("")||(""))){try{("");conn=("jdbc:odbc:book","","");String sql="select * from ww where username='"+username2+"'";stmt=();rs=(sql);if()){if("password").equals(password2)){"***欢迎来山东科技大学图书馆管理系统**");while(true){" 1.图书信息");" 2.读者信息");" 3.管理员信息");" 4.借阅信息");" 5.还书信息");" 6.逾期罚款或损坏赔偿信息");出");" 请输入选择功能的序号:");int a=();switch(a){case 1:" 图书信息: ");" 1. 查询图书信息: ");" 2. 插入图书信息: ");" 3. 删除图书信息: ");" 4. 修改图书信息: ");int a1=();switch(a1){case 1:" 欢迎进入图书信息查询系统: ");" 1. 无条件查询图书信息: ");" 2. 条件查询图书信息: ");int d=();switch(d){case 1:int llll=0;无条件查询图书信息: ");String Sql0 = "SELECT * FROM systembook ";rs= (Sql0);while()){String bookID =(1);String bookNo =(2);String bookName =(3);String bookWriter =(4);String bookPub =(5);","+bookNo+","+bookName+","+ bookWriter+","+bookPub);}"是否继续插入yes/no no返回主菜单");String k=();if("yes"))};if("no")){llll=1;};}break;条件查询图书信息: ");" 1. 单条件查询图书信息: ");" 2. 模糊条件查询图书信息: ");" 3. 多表连接查询图书信息: ");" 4. 嵌套查询图书信息: ");" 5. 谓词演算查询");int c12=();switch(c12){case 1:" 1.单条件查询: ");" 1.按图书名编码号查询图书信息: ");int ddd=0;while(ddd!=1){"请输入图书编码号:");String A=();String sql1= "SELECT * FROM systembook WHERE bookID ='"+A+"' ";rs= (sql1);int x=0;while()){String a2 =(1);String b2 =(2);String c2 =(3);String d2 =(4);String e2 =(5);","+b2+" ,"+c2+","+d2+","+e2);x++;}if(x==0){"查无此书,请重新输入");else{"是否继续按姓名查询yes/no no返回主菜单");String k=();if("yes")){};if("no")){ddd=1;};};}break;case 2:" 2.模糊查询图书信息: ");int dc=0;while(dc!=1){"请用户输入图书名字中的模糊关键字");String E=();String sq123= "SELECT * FROM systembook WHERE bookName LIKE'"+E+"%'";rs= (sq123);int z=0;while()){String a2 =(1);String b2 =(2);String c2 =(3);String d2 =(4);String e2 =(5);","+b2+" ,"+c2+","+d2+","+e2);z++;}if(z==0){"查无此书,请重新输入");}else{"是否继续输入图书名字中的模糊关键字yes/no no 返回主菜单");String k=();if("yes")){};if("no")){dc=1;表连接查询查询图书信息: ");int dq=0;while(dq!=1){"查询逾期罚款或是赔偿表中的读者的相关信息");"请输入逾期罚款或是赔偿的读者编码号");String F=();String sq1234= "SELECT * FROM fine,borrowbook,systemreader WHERE = AND = AND ='"+F+"' ";rs= (sq1234);int n=0;while()){String a2 =(1);String b2 =(2);String c2 =(3);String d2 =(4);String e2 =(5);","+b2+" ,"+c2+","+d2+","+e2);n++;}if(n==0){"查无此人,请重新输入");}else{"是否继续输入图书名字中的模糊关键字yes/no no返回主菜单");if("yes")){};if("no")){ddd=1;};}}break;case 4:" 4.嵌套查询图书信息: ");int dq1=0;while(dq1!=1){"查询某读者所在年级女读者的相关信息");"请输入某读者的读者编号");String G=();String sq12345= "SELECT * FROM systemreader WHERE reaGrade=(SELECT reaGrade FROM systemreader WHERE reaID='"+G+"') AND reasex='女'";rs= (sq12345);int m=0;while()){String a2 =(1);String b2 =(2);String c2 =(3);String d2 =(4);String e2 =(5);","+b2+" ,"+c2+","+d2+","+e2);m++;}if(m==0){"查无此书,请重新输入");}else{"是否继续输入读者编号yes/no no返回主菜单");if("yes")){};if("no")){d=1;};}}break;case 5:" 5. 谓词演算查询:");int dq1123=0;while(dq1123!=1){"查询借阅了某本书的读者的相关信息");"请输入该书的名字");String H=();String sq123456= "SELECT * FROM systemreader WHERE reaID IN (SELECT reaID FROM borrowbook WHERE bookName='"+H+"')";rs= (sq123456);int l=0;while()){String a2 =(1);String b2 =(2);String c2 =(3);String d2 =(4);String e2 =(5);","+b2+" ,"+c2+","+d2+","+e2);l++;}if(l==0){"查无此人,请重新输入");}else{"是否继续输入图书名字yes/no no返回主菜单");String k=();if("yes")){} ;if("no")){d=1;};}}break;}查询图书信息: ");String Sql = "SELECT * FROM systembook ";rs= (Sql);while()){插入图书信息: ");"请按顺序插入图书条码号,图书索书号,图书名字,图书作者,图书出版社");String str=();String []splitst=(",");String a11=splitst[0];String a12=splitst[1];String a13=splitst[2];String a14=splitst[3];String a15=splitst[4];String insertSql="INSERT INTO systembook(bookID,bookNo,bookName,bookWriter,bookPub)VALUES('"+a11+"','"+a12+"','"+a13+"','"+a14+"','"+a15+"')";int i=(insertSql); 删除图书信息: ");"请输入要删除的图书编号:");String Str=();String []Splitst=(",");String b3=Splitst[0];String sql1="SELECT * FROM systembook where bookID='"+b3+"'";rs= (sql1);int kkk=0;while()){String a22 =(1);String b22 =(2);String c22 =(3);String d22 =(4);String e22 =(5);String f22 =(6);","+b22+" ,"+c22+","+d22+","+e22+","+f22);kkk++;}if(kkk==0){"没有这本书,请重新输入");}else{{String deleSql= "DELETE FROM systembook WHERE bookID='"+b3+"'";int p=(deleSql); 修改图书信息: ");"请输入修改的图书ID ");String S=();String sql1="SELECT * FROM systembook where bookID='"+S+"'";rs= (sql1);int lll=0;while()){String a222 =(1);String b222 =(2);String c222 =(3);String d222 =(4);String e222 =(5);String f222 =(6);","+b222+" ,"+c222+","+d222+","+e222+","+f222);lll++;}if(lll==0){"没有这本书,请重新输入");}else{"要将书名改为");String bbb=();String updateSql1="UPDATE systembook SET bookName='"+bbb+"' WHERE bookID='"+S+"'";int hh=(updateSql1); 查询读者信息: ");" 2. 插入读者信息: ");" 3. 删除读者信息: ");" 4. 修改读者信息: " );int b1=();switch(b1){case 1:" 1. 查询读者信息: ");String ssql = "SELECT * FROM systemreader ";rs= (ssql);while()){插入读者信息: ");"请按顺序插入借书卡证号读者名字读者学号读者性别读者LBID 读者类型读者学院读者年级读者专业办证日期");String str=();String []splitst=(",");String b11=splitst[0];String b12=splitst[1];String b13=splitst[2];String b14=splitst[3];String b15=splitst[4];String b16=splitst[5];String b17=splitst[6];String b18=splitst[7];String b19=splitst[8];String b20=splitst[9];String insertSql="INSERT INTO systemreader(reaID,reaName,reaNo,reaSex,reaLBID,reaType,reaDep,reaGrade,reaPre,reaDate) VALUES('"+b11+"','"+b12+"','"+b13+"','"+b14+"','"+b15+"','"+b16+"','"+b17+"','"+b18+"','"+b19+"' ,'"+b20+"')";int n=(insertSql); 删除读者信息: ");"请输入要删除的读者证号:");String Str=();String []Splitst=(",");String r=Splitst[0];String sql1="SELECT * FROM systemreader where reaID='"+r+"'";rs= (sql1);int kkk=0;while()){String a22 =(1);String b22 =(2);String c22 =(3);String d22 =(4);String e22 =(5);String f22 =(6);String g22 =(7);String h22 =(8);String i22 =(9);","+b22+" ,"+c22+","+d22+","+e22+","+f22+","+g22+","+h22+","+i22);kkk++;}if(kkk==0){"没有这个读者,请重新输入");}else{修改读者信息: ");"请输入修改以后的读者的ID ");String S=();查询管理员信息: ");" 2. 插入管理员信息: ");" 3. 删除管理员信息: ");" 4. 修改管理员信息: ");" 5. 返回上一级");int c11=();switch(c11){case 1:" 1. 查询管理员信息: ");String Ssql = "SELECT * FROM manager ";rs= (Ssql);while()){插入管理员信息: ");"请按顺序插入管理员的编号,管理员的姓名,管理员的性别,所管书库,电话,地址");String str=();String []splitst=(",");String a11=splitst[0];String a12=splitst[1];String a13=splitst[2];String a14=splitst[3];String a15=splitst[4];String a16=splitst[5];String insertSql="INSERT INTO manager(mID,mName,mSex,mAuth,mTeleph,mAddre)VALUES('"+a11+"','"+a12+"','"+a13+"','"+a14+"','"+a15+"','"+a16+"')";int i=(insertSql); 删除管理员信息: ");"请输入要删除的管理员编号:");String Str=();String []Splitst=(",");String b3=Splitst[0];String sql1="SELECT * FROM manager where mID='"+b3+"'";rs= (sql1);int kkk=0;while()){String a22 =(1);String b22 =(2);String c22 =(3);String d22 =(4);String e22 =(5);String f22 =(6);","+b22+" ,"+c22+","+d22+","+e22+","+f22);kkk++;}if(kkk==0){"没有这个管理员,请重新输入");}else{修改管理员信息: ");"请输入要修改的管理员编号:");String S=();String []Ssplitst=(",");String c1=Ssplitst[0];String sql1="SELECT * FROM manager where mID='"+S+"'";rs= (sql1);int lll=0;while()){String a222 =(1);String b222 =(2);String c222 =(3);String d222 =(4);String e222 =(5);String f222 =(6);","+b222+" ,"+c222+","+d222+","+e222+","+f222);lll++;}if(lll==0){"没有这个管理员,请重新输入");}else{查询图书借阅信息信息: ");" 2. 插入图书借阅信息: ");" 3. 删除图书借阅信息: ");" 4. 修改图书借阅信息: ");" 5. 返回上一级");int d=();switch(d){case 1:" 1. 查询图书借阅信息: ");String Sql4 = "SELECT * FROM borrowbook ";rs= (Sql4);while()){String bookID =(1);String reaID =(2);String outDate =(3);String yhDate =(4);","+reaID+","+outDate+","+yhDate);}break;case 2:int zz=0;while(zz!=1){" 2. 插入图书借阅信息: ");"请按顺序插入图书的的编号,读者编号,图书借出日期,图书归还日期");String str=();String []splitst=(",");String a11=splitst[0];String a12=splitst[1];String a13=splitst[2];String a14=splitst[3];删除图书借阅信息: ");"请输入要删除的图书条码号:");String Str=();String []Splitst=(",");String b3=Splitst[0];String sql1="SELECT * FROM borrowbook where bookID='"+b3+"'";rs= (sql1);int kkk=0;while()){String a22 =(1);String b22 =(2);String c22 =(3);String d22 =(4);修改借阅读书信息: ");"请输入要修改的图书的ID ");String S=();String []Ssplitst=(",");String c1=Ssplitst[0];String sql1="SELECT * FROM borrowbook where bookID='"+S+"'";rs= (sql1);int lll=0;while()){String a222 =(1);String b222 =(2);String c222 =(3);String d222 =(4);查询还书信息: ");" 2. 插入还书信息: ");" 3. 删除还书信息: ");" 4. 修改还书信息: ");" 5. 返回上一级");int e=();switch(e){case 1:" 1. 查询还书信息: ");sql = "SELECT * FROM return ";rs= (sql);while()){String reaID =(1);String bookID =(2);String bookName =(3);String inDate =(4);","+bookID+","+bookName+","+ inDate);}break;case 2:" 2. 插入还书信息: ");"请按顺序插入读者卡号,图书编号,图书名称,还书日期");String str=();String []splitst=(",");String e1=splitst[0];String e2=splitst[1];String e3=splitst[2];String e4=splitst[3];String insertSql="INSERT INTO returnbook(reaID,bookID,bookName,inDate) VALUES('"+e1+"','"+e2+"','"+e3+"','"+e4+"')";int h=(insertSql); 删除还书书信息: ");"请输入要删除的读者证号:");String Str=();String []Splitst=(",");String f3=Splitst[0];String deleSql= "DELETE FROM return WHERE reaID='"+f3+"'";int w=(deleSql); 查询罚款信息: ");" 2. 插入罚款信息: ");" 3. 删除罚款信息: ");" 4. 修改罚款信息: ");int g=();switch(g){case 1:" 1. 查询罚款信息: ");String Sssql = "SELECT * FROM fine ";rs= (Sssql);while()){插入罚款信息: ");"请按顺序插入读者卡号,图书编号,借书日期,超出日期,应缴罚款");String str=();String []splitst=(",");String g1=splitst[0];String g2=splitst[1];String g3=splitst[2];String g4=splitst[3];String g5=splitst[4];删除罚款信息: ");"请输入要删除的读者证号:");String Str=();String []Splitst=(",");String r=Splitst[0];String deleSql= "DELETE FROM fine WHERE reaID='"+r+"'";int x=(deleSql); 查询借阅历史信息: ");" 2. 插入借阅历史信息: ");" 3. 删除借阅历史信息: ");" 4. 修改借阅历史信息: ");" 5. 返回上一级");int h=();switch(h){" 1. 查询历史借阅信息: ");String Sql7 = "SELECT * FROM borrowhistory ";rs= (Sql7);while()){String bookID =(1);String reaID =(2);String bookName=(3);String bookWriter=(4);String outDate =(5);String yhDate =(6);","+reaID+","+bookName+","+bookWriter+","+outDate+","+yhDate);}break;case 2:" 2. 插入图书历史借阅信息: ");"请按顺序插入图书的的编号,读者编号,,图书借出日期,图书归还日期");String str=();String []splitst=(",");String a11=splitst[0];String a12=splitst[1];String a13=splitst[2];String a14=splitst[3];删除图书历史借阅信息: ");"请输入要删除的图书条码号:");String Str=();String []Splitst=(",");String d3=Splitst[0];String deleSql= "DELETE bookID FROM borrowhistory WHERE bookID='"+d3+"'";int k=(deleSql); 修改图书借阅历史信息: ");"请输入要修改的图书的借出日期");String S=();String []Ssplitst=(",");String c1=Ssplitst[0];String updateSql="UPDATE borrow SET outDate='"+c1+"' WHERE bookName='数据库'";int t=(updateSql); //返回记录影响的条数if(t!=0){"修改成功!");}break;}}}}}else{"非法用户!");}}catch(SQLException e) {();}//();();();}}}}。
(完整word版)图书管理系统源代码
图书管理系统源代码(一)程序代码1。
主窗口界面import java.awt。
*;import java.awt。
event.*;import javax。
swing.*;import javax.swing.border.TitledBorder;import java.awt。
Font;import javax.swing。
JMenu;public class MainWindow extends JFrame implements ActionListener { private static final long serialVersionUID = 1L;static String loginName;static String loginNo;JLabel mlabel;JPanel jp=new JPanel();//建立菜单栏JMenu a=new JMenu();JMenu b=new JMenu();JMenu c=new JMenu();//建立系统管理菜单组JMenuItem aa=new JMenuItem();JMenuItem ab=new JMenuItem();JMenuItem ac=new JMenuItem();//建立读者管理菜单组JMenuItem bb=new JMenuItem();//建立书籍管理菜单组JMenuItem ca=new JMenuItem();JMenuItem cb=new JMenuItem();JMenuItem cc=new JMenuItem();JMenuItem cd=new JMenuItem();public MainWindow(){super(”图书管理系统");addWindowListener(new WindowAdapter(){System.exit(0);}});Container d=getContentPane();this。
基于java的图书管理系统源代码
声明:本系统是基于C/S的图书管理系统,主要使用的是Oracle数据库,下面附所有实现代码package library;public class book_add extends JFrame implements ActionListener{DataBaseManager db=new DataBaseManager();ResultSet rs;JPanel panel1,panel2;JLabel book_id_label,book_name_label,author_label,press_label,press_date_label,price_label,book_num_label,borrowed_num_label, address;JTextField book_id_TextField,book_name_TextField,author_TextField,press_TextField,press_date_TextField,price_TextField,book_num_TextField,borrowed_count;JComboBox addresst;Container c;JButton clear,add,exit;public book_add(){super("添加图书信息");c=getContentPane();c.setLayout(new BorderLayout());book_id_label=new JLabel("编号",JLabel.CENTER);book_name_label=new JLabel("名称",JLabel.CENTER);author_label=new JLabel("作者",JLabel.CENTER);press_label=new JLabel("出版社",JLabel.CENTER);press_date_label=new JLabel("出版日期",JLabel.CENTER);price_label=new JLabel("价格",JLabel.CENTER);book_num_label=new JLabel("库存数",JLabel.CENTER);borrowed_num_label=new JLabel("已借阅数",JLabel.CENTER);address=new JLabel("藏书地址",JLabel.CENTER);book_id_TextField=new JTextField(15);book_name_TextField=new JTextField(15);author_TextField=new JTextField(15);press_TextField=new JTextField(15);press_date_TextField=new JTextField(15);price_TextField=new JTextField(15);book_num_TextField=new JTextField(15);borrowed_count=new JTextField(15);borrowed_count.setText("0");addresst=new JComboBox();addresst.addItem("扬子津图书馆");addresst.addItem("荷花池图书馆");addresst.addItem("瘦西湖图书馆");addresst.addItem("淮海路图书馆");panel1=new JPanel();panel1.setLayout(new GridLayout(9,2));panel1.add(book_id_label);panel1.add(book_id_TextField);panel1.add(book_name_label);panel1.add(book_name_TextField);panel1.add(press_label);panel1.add(press_TextField);panel1.add(author_label);panel1.add(author_TextField);panel1.add(press_date_label);panel1.add(press_date_TextField);panel1.add(price_label);panel1.add(price_TextField);panel1.add(book_num_label);panel1.add(book_num_TextField);panel1.add(borrowed_num_label);panel1.add(borrowed_count);panel1.add(address);panel1.add(addresst);panel2=new JPanel();panel2.setLayout(new GridLayout(1,3));clear=new JButton("清空");clear.addActionListener(this);add=new JButton("添加");add.addActionListener(this);exit=new JButton("退出");exit.addActionListener(this);panel2.add(clear);panel2.add(add);panel2.add(exit);c.add(panel1,BorderLayout.CENTER);c.add(panel2,BorderLayout.SOUTH);setVisible(true);}public void actionPerformed(ActionEvent e) {if(e.getSource()==exit){this.dispose();}else if(e.getSource()==clear){book_id_TextField.setText("");book_name_TextField.setText("");author_TextField.setText("");press_TextField.setText("");press_date_TextField.setText("");price_TextField.setText("");book_num_TextField.setText("");}else if(e.getSource()==add){if(book_id_TextField.getText().trim().equals("")){JOptionPane.showMessageDialog(null, "书号不能为空");}else if(book_name_TextField.getText().trim().equals("")){JOptionPane.showMessageDialog(null, "书名不能为空");}else if(author_TextField.getText().trim().equals("")){JOptionPane.showMessageDialog(null, "作者不能为空");}else if(press_TextField.getText().trim().equals("")){JOptionPane.showMessageDialog(null, "出版社不能为空");}else if(press_date_TextField.getText().trim().equals("")) {JOptionPane.showMessageDialog(null, "出版日期不能为空");}else if(price_TextField.getText().trim().equals("")){JOptionPane.showMessageDialog(null, "价格不能为空");}else if(book_num_TextField.getText().trim().equals("")){JOptionPane.showMessageDialog(null, "库存不能为空");}else if(borrowed_count.getText().trim().equals("")){JOptionPane.showMessageDialog(null, "借阅数不能为空");}else {try{String strSQL="insert into book(book_id,book_name,press,author,press_date,price,book_count,borrowed_count, store_address) values('"+book_id_TextField.getText().trim()+"','"+book_name_TextField.getText().trim()+"','"+press_TextField.getText().trim()+"','"+author_TextField.getText().trim()+"','"+press_date_TextField.getText().trim()+"','"+price_TextField.getText().trim()+"','"+book_num_TextField.getText().trim()+"','"+borrowed_count.getText().trim()+"','"+addresst.getSelectedItem()+"')";if(db.updateSql(strSQL)){this.dispose();JOptionPane.showMessageDialog(null,"添加图书成功");}else{JOptionPane.showMessageDialog(null,"添加图书失败");this.dispose();}db.closeConnection();}catch(Exception ex){}}}}}package library;import javax.swing.*;import java.awt.*;public class book_delete extends JFrame implements ActionListener{ DataBaseManager db=new DataBaseManager();ResultSet rs;Container c;JLabel TipLabel=new JLabel("请选择要删除的书名",JLabel.CENTER);JComboBox bb=new JComboBox();JButton yes,exit;JPanel panel1=new JPanel();public book_delete(){super("删除图书信息");c=getContentPane();c.setLayout(new BorderLayout());try{String strSQL="select book_name from book where book_count>borrowed_count";rs=db.getResult(strSQL);while(rs.next()){bb.addItem(rs.getString(1));}}catch(SQLException sqle){}catch(Exception ex){}c.add(TipLabel,BorderLayout.NORTH);c.add(bb,BorderLayout.CENTER);yes=new JButton("确定");exit=new JButton("退出");yes.addActionListener(this);exit.addActionListener(this);panel1.add(yes);panel1.add(exit);c.add(panel1,BorderLayout.SOUTH);setVisible(true);}public void actionPerformed(ActionEvent e){if(e.getSource()==exit){this.dispose();}else if(e.getSource()==yes){try{String strSQL="select borrowed_count from book where book_name='"+bb.getSelectedItem()+"'";rs=db.getResult(strSQL);if(!rs.first()){JOptionPane.showMessageDialog(null,"书库里没有你要删除的书");}else{String strSql="delete from book where book_name='"+bb.getSelectedItem()+"'and borrowed_count=0";rs.first();int count=rs.getInt(1);if(!(count==0)){JOptionPane.showMessageDialog(null,"此书还有学生没有还,不可删除");}else if(db.updateSql(strSql)){JOptionPane.showMessageDialog(null,"删除成功");db.closeConnection();this.dispose();}else{JOptionPane.showMessageDialog(null,"删除失败");db.closeConnection();this.dispose();}}}catch(SQLException sqle){}catch(Exception ex){}}}}package library;public class book_modify extends JFrame implements ActionListener{ DataBaseManager db=new DataBaseManager();ResultSet rs;JPanel panel1,panel2,panel3;JLabel TipLabel=new JLabel("输入书名点确定,将调出此书的相关信息");JLabel book_name_label,author_label,press_label,press_date_label,price_label;JTextField book_name_TextField,author_TextField,press_TextField,press_date_TextField,price_TextField; Container c;JButton clear,yes,update,exit;public book_modify(){super("修改图书信息");c=getContentPane();c.setLayout(new BorderLayout());panel3=new JPanel();panel3.add(TipLabel);c.add(panel3,BorderLayout.NORTH);book_name_label=new JLabel("名称",JLabel.CENTER);author_label=new JLabel("作者",JLabel.CENTER);press_label=new JLabel("出版社",JLabel.CENTER);press_date_label=new JLabel("出版日期",JLabel.CENTER);price_label=new JLabel("价格",JLabel.CENTER);book_name_TextField=new JTextField(15);author_TextField=new JTextField(15);press_TextField=new JTextField(15);press_date_TextField=new JTextField(15);price_TextField=new JTextField(15);panel1=new JPanel();panel1.setLayout(new GridLayout(6,2));panel1.add(book_name_label);panel1.add(book_name_TextField);panel1.add(author_label);panel1.add(author_TextField);panel1.add(press_label);panel1.add(press_TextField);panel1.add(press_date_label);panel1.add(press_date_TextField);panel1.add(price_label);panel1.add(price_TextField);panel2=new JPanel();panel2.setLayout(new GridLayout(1,4));clear=new JButton("清空");yes=new JButton("确定");update=new JButton("更新");exit=new JButton("退出");panel2.add(clear);panel2.add(yes);panel2.add(update);panel2.add(exit);clear.addActionListener(this);yes.addActionListener(this);update.addActionListener(this);exit.addActionListener(this);update.setEnabled(false);c.add(panel1,BorderLayout.CENTER);c.add(panel2,BorderLayout.SOUTH);setVisible(true);}public void actionPerformed(ActionEvent e){if(e.getSource()==exit){this.dispose();;}else if(e.getSource()==clear){book_name_TextField.setText("");author_TextField.setText("");press_TextField.setText("");press_date_TextField.setText("");price_TextField.setText("");}else if(e.getSource()==yes){try{String strSQL="select * from book where book_name='"+book_name_TextField.getText().trim()+"'";rs=db.getResult(strSQL);while(rs.next()){book_name_TextField.setText(rs.getString("book_name"));author_TextField.setText(rs.getString("author"));press_TextField.setText(rs.getString("press"));press_date_TextField.setText(rs.getString("press_date"));price_TextField.setText(rs.getString("price"));}update.setEnabled(true);}catch(NullPointerException upe){}catch(Exception es){}}else if(e.getSource()==update){try{String strSQL="update book set book_name='"+book_name_TextField.getText().trim()+"',press='"+press_TextField.getText().trim()+"',author='"+author_TextField.getText().trim()+"',press_date='"+press_date_TextField.getText().trim()+"',price='"+price_TextField.getText().trim()+"' where book_name='"+book_name_TextField.getText().trim()+"'";if(db.updateSql(strSQL)){this.dispose();JOptionPane.showMessageDialog(null,"更新图书成功");}else {JOptionPane.showMessageDialog(null,"更新图书失败");}db.closeConnection();}catch(Exception sqle){}}}}package library;public class bookborrow extends JFrame implements ActionListener{ DataBaseManager db=new DataBaseManager();ResultSet rs;Container c;JPanel panel1,panel2;JLabel borrowname,bookname,borrowdate,returndate,is_return_label;JTextField borrowdateField,returndateField,is_return;JButton clear,yes,cancel;JComboBox borrownameBox=new JComboBox();JComboBox booknameBox=new JComboBox();public bookborrow(){super("书籍出借");c=getContentPane();c.setLayout(new BorderLayout());Calendar cal = Calendar.getInstance();int year,month,day;// year=cal.get(Calendar.YEAR);// month=cal.get(Calendar.MONTH)+3;//从0开始的// day=cal.get(Calendar.DAY_OF_MONTH);// String cdate = sdf.format(cal.getTime());// String da=Integer.toString(year)+"-0"+Integer.toString(month)+"-"+Integer.toString(day );borrowname=new JLabel("借阅者姓名",JLabel.CENTER);bookname=new JLabel("书名",JLabel.CENTER);borrowdate=new JLabel("借书日期",JLabel.CENTER);// returndate=new JLabel("应还日期",JLabel.CENTER);is_return_label=new JLabel("是否归还",JLabel.CENTER);borrowdateField=new JTextField(15);// borrowdateField.setText(cdate);// returndateField=new JTextField(15);// returndateField.setText(da);is_return=new JTextField(15);is_return.setText("否");try{String strSql="select student_name from reader ";rs=db.getResult(strSql);while(rs.next()){borrownameBox.addItem(rs.getString(1));}}catch(SQLException sqle){}catch(Exception ex){}try{String strSQL="select book_name from book where book_count>borrowed_count";rs=db.getResult(strSQL);while(rs.next()){booknameBox.addItem(rs.getString(1));}}catch(SQLException sqle){}catch(Exception ex){}panel1=new JPanel();panel1.setLayout(new GridLayout(5,2));panel1.add(borrowname);panel1.add(borrownameBox);panel1.add(bookname);panel1.add(booknameBox);panel1.add(borrowdate);panel1.add(borrowdateField);// panel1.add(returndate);// panel1.add(returndateField);panel1.add(is_return_label);panel1.add(is_return);c.add(panel1,BorderLayout.CENTER);panel2=new JPanel();panel2.setLayout(new GridLayout(1,3));clear=new JButton("清空");yes=new JButton("确定");cancel=new JButton("取消");clear.addActionListener(this);yes.addActionListener(this);cancel.addActionListener(this);panel2.add(clear);panel2.add(yes);panel2.add(cancel);c.add(panel2,BorderLayout.SOUTH);setVisible(true);setSize(300,300);}public void actionPerformed(ActionEvent e){if(e.getSource()==cancel){this.dispose();}else if(e.getSource()==clear){borrowdateField.setText("");// returndateField.setText("");is_return.setText("");}else if(e.getSource()==yes){if(borrownameBox.getSelectedItem().equals("")){JOptionPane.showMessageDialog(null, "对不起,没有读者借阅");}else if(booknameBox.getSelectedItem().equals("")){JOptionPane.showMessageDialog(null, "对不起,现在书库没有书");}else {try{//系统计算归还日期//获取输入的借阅日期,自动加两个月String startDate=borrowdateField.getText().trim();SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");Date dateStart=format.parse(startDate);Calendar cd=Calendar.getInstance();cd.setTime(dateStart);cd.add(Calendar.MONTH, 2);String returnDate=format.format(cd.getTime());String strSQL="insert into borrow(student_name,book_name,borrow_date,return_date,is_returned) values('"+borrownameBox.getSelectedItem()+"','"+booknameBox.getSelectedItem()+"','"+borrowdateField.getText().trim()+"','"+returnDate+"','"+is_return.getText().trim()+"')";if(db.updateSql(strSQL)){JOptionPane.showMessageDialog(null, "借阅完成");strSQL = "update reader set borrow_count=borrow_count+1 where student_name='"+borrownameBox.getSelectedItem()+"'";db.updateSql(strSQL);strSQL="update book set borrowed_count=borrowed_count+1 where book_name='"+booknameBox.getSelectedItem()+"'";db.updateSql(strSQL);db.closeConnection();this.dispose();}else{JOptionPane.showMessageDialog(null, "借阅失败");db.closeConnection();this.dispose();}}catch(Exception se){}}}}}package library;import javax.swing.*;import java.awt.*;public class bookborrowlist extends JFrame implements ActionListener{ DataBaseManager db=new DataBaseManager();ResultSet rs;Container c;JPanel panel1,panel2;JLabel bookname,studentname;JTextField booknamet,studentnamet;JButton search,exit;JTable table=null;DefaultTableModel defaultModel=null;public bookborrowlist(){super("借阅列表");c=getContentPane();c.setLayout(new BorderLayout());bookname=new JLabel("书名",JLabel.CENTER);studentname=new JLabel("人名",JLabel.CENTER);booknamet=new JTextField(15);studentnamet=new JTextField(15);search=new JButton("查询");exit=new JButton("退出");search.addActionListener(this);exit.addActionListener(this);Box box1=Box.createHorizontalBox();box1.add(studentname);box1.add(studentnamet);box1.add(search);Box box2=Box.createHorizontalBox();box2.add(bookname);box2.add(booknamet);box2.add(exit);Box boxH=Box.createVerticalBox();boxH.add(box1);boxH.add(box2);boxH.add(Box.createVerticalGlue());panel1=new JPanel();panel1.add(boxH);panel2=new JPanel();String []name={"读者","书名","借阅时间","应还时间","是否归还"};String [][]data=new String[0][0];defaultModel=new DefaultTableModel(data,name);table=new JTable(defaultModel);table.setPreferredScrollableViewportSize(new Dimension(400,80));JScrollPane s=new JScrollPane(table);panel2.add(s);c.add(panel1,BorderLayout.NORTH);c.add(panel2,BorderLayout.SOUTH);}public void actionPerformed(ActionEvent e){if(e.getSource()==exit){db.closeConnection();this.dispose();}else if(e.getSource()==search){String strSQL="select student_name,book_name,borrow_date,return_date,is_returned from borrow";String strSql=null;if(studentnamet.getText().trim().equals("")&&booknamet.getText().trim().equ als("")){strSql=strSQL;}else if(studentnamet.getText().trim().equals("")){strSql="selectstudent_name,book_name,borrow_date,return_date,is_returned from borrow where book_name='"+booknamet.getText().trim()+"'";}else if(booknamet.getText().trim().equals("")){strSql="selectstudent_name,book_name,borrow_date,return_date,is_returned from borrow where student_name='"+studentnamet.getText().trim()+"'";}else{strSql="selectstudent_name,book_name,borrow_date,return_date,is_returned from borrow where student_name='"+studentnamet.getText().trim()+"'and book_name='"+booknamet.getText().trim()+"'";JOptionPane.showMessageDialog(null, "你借的书还还有7天超期");}try{int rowCount=defaultModel.getRowCount()-1;int j=rowCount;for(int i=0;i<=rowCount;i++){defaultModel.removeRow(j);defaultModel.setRowCount(j);j=j-1;}rs=db.getResult(strSql);while(rs.next()){Vector insertRow=new Vector();insertRow.addElement(rs.getString(1));insertRow.addElement(rs.getString(2));insertRow.addElement(rs.getString(3));insertRow.addElement(rs.getString(4));insertRow.addElement(rs.getString(5));defaultModel.addRow(insertRow);}table.revalidate();}catch(SQLException sqle){}catch(Exception ex){}}}}package library;import javax.swing.*;import java.awt.*;public class bookborrowModify extends JFrame implements ActionListener{ DataBaseManager db=new DataBaseManager();ResultSet rs;JPanel panel1,panel2,panel3;Container c;JLabel tiplabel=new JLabel("输入借阅者姓名和书名单击确定,将调出此书的相关信息");JLabel borrowlabel,namelabel,borrowdate;JTextField borrowField,nameField,dateField;JButton clear,yes,update,cancel;public bookborrowModify(){super("修改图书出借信息");c=getContentPane();c.setLayout(new BorderLayout());panel3=new JPanel();panel3.add(tiplabel);c.add(panel3,BorderLayout.NORTH);borrowlabel=new JLabel("借阅者姓名",JLabel.CENTER);namelabel=new JLabel("书名",JLabel.CENTER);borrowdate=new JLabel("借书日期",JLabel.CENTER);borrowField=new JTextField(15);nameField=new JTextField(15);dateField=new JTextField(15);panel1=new JPanel();panel1.setLayout(new GridLayout(3,2));panel1.add(borrowlabel);panel1.add(borrowField);panel1.add(namelabel);panel1.add(nameField);panel1.add(borrowdate);panel1.add(dateField);c.add(panel1,BorderLayout.CENTER);panel2=new JPanel();panel2.setLayout(new GridLayout(1,4));clear=new JButton("清空");yes=new JButton("确定");update=new JButton("更新");cancel=new JButton("取消");clear.addActionListener(this);yes.addActionListener(this);update.addActionListener(this);cancel.addActionListener(this);panel2.add(clear);panel2.add(yes);panel2.add(update);panel2.add(cancel);c.add(panel2,BorderLayout.SOUTH);setVisible(true);setSize(400,200);}public void actionPerformed(ActionEvent e) {if(e.getSource()==clear){borrowField.setText("");nameField.setText("");dateField.setText("");}else if(e.getSource()==cancel){this.dispose();}else if(e.getSource()==yes){try{String strSQL="select student_name,book_name,borrow_date from borrow where student_name='"+borrowField.getText().trim()+"'and book_name='"+nameField.getText().trim()+"'";rs=db.getResult(strSQL);if(!rs.first()){JOptionPane.showMessageDialog(null,"此学生没有借过书或者没有此书");}else{borrowField.setText(rs.getString(1));nameField.setText(rs.getString(2));dateField.setText(rs.getString(3));update.setEnabled(true);}}catch(Exception ex){}}else if(e.getSource()==update){String strSQL="update borrow set borrow_date='"+dateField.getText().trim()+"' where student_name='"+borrowField.getText().trim()+"'and book_name='"+nameField.getText().trim()+"'";if(db.updateSql(strSQL)){JOptionPane.showMessageDialog(null,"更新成功");db.closeConnection();this.dispose();}else{JOptionPane.showMessageDialog(null,"更新失败");db.closeConnection();this.dispose();}}}}package library;import javax.swing.*;import java.awt.*;public class booklist extends JFrame implements ActionListener{ DataBaseManager db=new DataBaseManager();ResultSet rs;Container c;JPanel panel1,panel2,panel3;JLabel bookname,authorname,press;JTextField booknamet,authornamet,presst;JButton search,exit;JTable table=null;DefaultTableModel defaultModel=null;public booklist(){super("书籍信息查询");c=getContentPane();c.setLayout(new BorderLayout());bookname=new JLabel("书名",JLabel.CENTER);authorname=new JLabel("作者",JLabel.CENTER);press=new JLabel("出版社",JLabel.CENTER);booknamet=new JTextField(15);authornamet=new JTextField(15);presst=new JTextField(15);search=new JButton("查询");exit=new JButton("退出");search.addActionListener(this);exit.addActionListener(this);panel1=new JPanel();panel1.add(bookname);panel1.add(booknamet);panel1.add(authorname);panel1.add(authornamet);panel2=new JPanel();panel2.add(press);panel2.add(presst);panel2.add(search);panel2.add(exit);String []name={"书号","书名","出版社","作者","出版日期","价格","图书数目","已借数目","剩余数目","藏书地址"};String [][]data=new String[0][0];defaultModel=new DefaultTableModel(data,name);table=new JTable(defaultModel);table.setPreferredScrollableViewportSize(new Dimension(400,80));JScrollPane s=new JScrollPane(table);panel3=new JPanel();panel3.add(s);c.add(panel1,BorderLayout.NORTH);c.add(panel2,BorderLayout.CENTER);c.add(panel3,BorderLayout.SOUTH);}public void actionPerformed(ActionEvent e){if(e.getSource()==exit){db.closeConnection();this.dispose();}else if(e.getSource()==search){String strSQL="select book_id,book_name,press,author,press_date,price,book_count,borrowed_count,book_ count-borrowed_count,store_address from book";String strSql=null;if(booknamet.getText().trim().equals("")&&authornamet.getText().trim().equa ls("")&&presst.getText().trim().equals("")){strSql=strSQL;}elseif(booknamet.getText().trim().equals("")&&authornamet.getText().trim().equals(" ")){strSql="selectbook_id,book_name,press,author,press_date,price,book_count,borrowed_count,book_ count-borrowed_count,store_address from book where press='"+presst.getText().trim()+"'";}elseif(authornamet.getText().trim().equals("")&&presst.getText().trim().equals("")) {strSql="selectbook_id,book_name,press,author,press_date,price,book_count,borrowed_count,book_ count-borrowed_count,store_address from book where book_name='"+booknamet.getText().trim()+"'";}elseif(booknamet.getText().trim().equals("")&&presst.getText().trim().equals("")) {strSql="selectbook_id,book_name,press,author,press_date,price,book_count,borrowed_count,book_ count-borrowed_count,store_address from book where author='"+authornamet.getText().trim()+"'";}else{strSql="selectbook_id,book_name,press,author,press_date,price,book_count,borrowed_count,book_ count-borrowed_count,store_address from book where book_name='"+booknamet.getText().trim()+"'and author='"+authornamet.getText().trim()+"'and press='"+presst.getText().trim()+"'";}try{int rowCount=defaultModel.getRowCount()-1;int j=rowCount;for(int i=0;i<=rowCount;i++){defaultModel.removeRow(j);defaultModel.setRowCount(j);j=j-1;}rs=db.getResult(strSql);while(rs.next()){Vector insertRow=new Vector();insertRow.addElement(rs.getString(1));insertRow.addElement(rs.getString(2));insertRow.addElement(rs.getString(3));insertRow.addElement(rs.getString(4));insertRow.addElement(rs.getString(5));insertRow.addElement(rs.getString(6));insertRow.addElement(rs.getString(7));insertRow.addElement(rs.getString(8));insertRow.addElement(rs.getString(9));insertRow.addElement(rs.getString(10));defaultModel.addRow(insertRow);}table.revalidate();}catch(SQLException sqle){}catch(Exception ex){}}}}package library;import javax.swing.*;import java.awt.*;public class bookreturn extends JFrame implements ActionListener{ DataBaseManager db=new DataBaseManager();ResultSet rs;JPanel panel1,panel2;Container c;JLabel namelabel,booklabel,returndatelabel;JTextField returnField;JButton clear,yes,cancel;JComboBox bookname=new JComboBox();JComboBox readername=new JComboBox();public bookreturn(){super("图书还入");c=getContentPane();c.setLayout(new BorderLayout());Calendar cal = Calendar.getInstance();String cdate = sdf.format(cal.getTime());namelabel=new JLabel("还书者姓名",JLabel.CENTER);booklabel =new JLabel("书名",JLabel.CENTER);returndatelabel=new JLabel("日期",JLabel.CENTER);returnField=new JTextField(15);returnField.setText(cdate);try{String s="";String strSQL="select student_name from reader where borrow_count!=0";rs=db.getResult(strSQL);while(rs.next()){readername.addItem(rs.getString(1));}}catch(SQLException sqle){}catch(Exception ex){}try{String s="";String strSQL="select book_name from borrow where is_returned='否'";rs=db.getResult(strSQL);while(rs.next()){bookname.addItem(rs.getString(1));}}catch(SQLException sqle){}catch(Exception ex){}panel1=new JPanel();panel1.setLayout(new GridLayout(3,2));。
java图书管理系统代码版
目录第1章本设计所要达到的目的和要求1.1 设计目的1.2 设计要求第2章设计内容第3 章开发和运行环境介绍第4章需求分析1、本设计所要达到的目的和要求1.1 设计目的管理信息系统(MIS)的应用已深入到社会的各行各业,它是信息、软件与科学管理相结合的产物。
MIS的开发过程不仅是一个编写应用程序的过程,而且是一个以软件工程的思想为指导,从可行性研究开始,经过系统分析、系统设计、系统实施到等主要阶段的规范开发过程。
本题目实现的是JAVA系统,我们选择的是图书馆管理系统,不同角色的用户登录,用户信息的管理包括密码管理,及用户借还书,用户对图书信息及本人借还情况的查询,超级管理员对图书信息的增删查改,用户信息的增删查改及借还情况总的查询。
1.2 设计要求1、主题明确,软体开发要有创新性,能体现SQL的存储过程、触发器、游标技术等;2、用高级语言结合SQL Server数据库进行开发;3、写出数据库关系模式及相应的数据库表关系图;4、绘制成绩MIS相应的系统流程图、E-R图等;5、完成成绩MIS登陆界面、主界面、图书信息录入、图书信息查询和其各项设计与操作。
2、设计内容我们设计的图书馆管理系统主要用于对图书馆日常工作的管理,主要任务是用计算机对读者、图书等各种信息进行日常管理,如查询、修改、增加、删除、图书借阅和归还的管理等。
本系统实现了图书馆的信息化管理,完成了图书馆管理系统的基本功能。
该系统主要包括读者用户登录系统、管理员用户登入系统、图书管理系统、图书借阅、图书和用户信息查询子系统四个部分,各部分主要功能如下:读者用户登录子系统:用于数据库的连接,主界面的设计和读者身份用户的登录管理。
管理员用户登入系统:用于管理员用户的管理,如图书添加、图书信息修改。
图书管理系统:用于图书信息的管理,如新书入库、图书信息修改、图书信息删除。
图书借阅系统:用于用户借阅和归还图书。
图书和用户信息查询:图书和用户信息的查询。
java编写的图书管理系统源代码
/用户登陆数据库代码: importjava.sql.*;classDatabasefConn ectioncon;ResultSetrs;Statementstmt;publicDatabase(){try{Class.forName(,,sun.jdbc.odbc.JdbcOdbcDriver u);〃加载JDBC-ODBC桥驱动程序Stringurl=,,jdbcdbc:HDB M;con 二DriverMa nager.getC onn ection(url);〃连接数据库HDB//stmt提供一个创建SQL查询、执行查询、得到返回结果的空间stmt= //con.createStatementfResultSet.TYPE^SCROLL^SENSITIVE,//ResultSet.CONCUR_READ_ONLY);}catch(Excepti on ex){System.out.println(ex);}}广根据用户名,获取密码*/publicStringgetPswd(Stringname){try{//rs为执行SQL语句所查询的结果赋给结果集对象rsrsustmt.executeQuGryC'SELECTpswdFROMUsGrWHERENamG』+name+);rs」ast();〃把rs的指针移到最后一行if(rs.getRow()==0){retur nn ull;}else{StringpswdDB=rs.getString(,,Pswd H);〃获取rs结果集中的pswd列的数据returnpswdDB;}}catch(Exceptio ne){System.out.printl n(e);returnnull;厂增加一行用户需、密码数据舟/publicboolea ninsertDatafStringname^tringpswdJftry{Strin gs=getPswd(name);if(s==null){intrtn=stmt.executellpdate(,,INSERTINTOUserVALUES(,,,+name +”「+pswd+”y);if(rtn!=O)returntrue;}else{retur nfalse;}retur nfalse;}catch(Exceptio net){System.out.printl n(et);returnfalse;〃进库数据库代码:importjava.sql.C onn ectio n;importjava.sql.DriverMa nager;importjava.sql.ResultSet;importjava.sql.Statement;classBookDatabase{Conn ectioncon;ResultSetrs;Statementstmt;publicBookDatabase(){try{Class.forName(,l sun.jdbc.odbcJdbcOdbcDriver u);〃加载JDBC-ODBC桥驱动程序Stringurl=,,jdbcdbc:Book,1;con 二DriverMa nager.getCon nection (url);〃连接数据库HDB//stmt提供一个创建SQL查询、执行查询、得到返回结果的空间stmt=co n・creatGStatemGnt(ResultSet・TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);}catch(Exceptio nex){ System.out.printl n(ex);厂增加一行用户需、密码数据*7publicboolea ninsertData(Stringid, String nam 已Stringwhere,Stringprice z Stringdate){try{intrtn=stmt.executellpdate(,,INSERTINTOBookVALUES(,,,+id+name+,,l/,,,+where+,,l/l,l+price+,,,;,,+dateif(rtn!=O){returntrue;}else{returnfalse;}}catch(Excep tion et){System.out.printl n(et);returnfalse;}}/**publicbooleandeleteData(Stringid){try{intrt n二♦stmt.executeUpdatef^ELETEFROMBookWHEREid^Ol^^nrtn^O)!*returntrue;}else{returnfalse;}}catch(Exceptione){ *System.out.println(e);returnfalse;}}publicboole anSelect(String *id){try{intrtn=stmt.executeUpdate(,,SELECT*FROMBooklnWHERE ♦id=IH+id+);♦*if(rt n!=O){retur ntrue;}else{retur nfelse;}}catch(Exception*e){System.out.println(e);returnfalse;}}*/}〃出库数据库代码:importjava.sql.C onn ectio n;importjava.sql.DriverMa nager;importjava.sql.ResultSet;importjava.sql.Statement;classBookDatabasel{Conn ectioncon;ResultSetrs;Statementstmt;publicBookDatabasel(){try{Class.forNameC'sun.jdbc.odbcJdbcOdbcDriver'1);〃加载JDBC-ODBC桥驱动程序Stringurl=,,jdbcdbc:Book,1;con 二DriverMa nager.getCon nection (url);〃连接数据库HDB//stmt提供一个创建SQL查询、执行查询、得到返回结果的空间stmt=co n・creatGStatemGnt(ResultSet・TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);}catch(Excepti on ex){System.out.pri ntln(ex);琢增加一行用户名、密码数拯publicbooleaninsertData(Stringid,Stringname z String *where z String ♦*price/Stringdate){try{intrtn=stmt.executeUpdate(,,INSERTINTO*BooklnVALUES(,H+id+♦s「+name+“「+whae*「+price+y+datery);♦*if(rt n!=O){retur ntrue;}else{returnfalse;}}catch(Exception*et){System.out.println(et);retur nfalse;}}*/publicbooleandeleteData(Stringid){try{intrt n=stmt.executellpdate(,l DELETEFROMBookWHEREid=,,,+id+,,,H);if(rtn!=O){returntrue;}else{returnfalse;catch(Excepti on e){ System.out.pri ntln(e); returnfalse;♦public bo olea nSelect(Stringid){try{intrt n 二♦stmt.executeUpdate(,,SELECT*FROMBooklnWHEREid=,,,+id+,,,l,);if(rtn!=*0){retur ntrue;}else{retur nfalse;}}catch(Exceptione){♦System.out.pri nt In (e);returnfalse;}}*/}〃查询数据库代码;importjava.awt.*;importjava.awt.event.*;importjava.sql.*;importjavax.swing.*;classBookDatabase2exte ndsJFrame{Stringnumber, nam 已address, prices,day;Conn ectioncon;Statementstmt=null;ResultSetresult=null;Strin gsql=null;publicBookDatabase2(){try{Class.forName(,l sun.jdbc.odbcJdbcOdbcDriver u);〃加载JDBC-ODBC桥驱动程序Stringurl=,,jdbc:odbc:Book H;con 二DriverMa nager.getCon nection (url);〃连接数据库HDB//stmt提供一个创建SQL查询、执行查询、得到返回结果的空间stmt=co n・creatGStatemGnt(ResultSet・TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);}catch(Exceptio nex){ System.out.printl n(ex);publicvoidselect(Stringid){try{sql=,,SELECT*FROMBookwhereid=,,,+id+,,,l,;result=stmt.executeQuery(sql);while(result.next()){number=result.getString(l);name=result.getString(2);address=result.getStri ng(3);prices=result.getString(4);day=result.getStri ng(4);}JOptionPane.showMessageDialogfBookDatabaseZ.this/1成功査询图书!\n,,+,1图书ID:,,+number+l,\n l,+H图书名称:,,+name+,,\n,,+u出版社”+address+”\n”+”价格:,,+prices+,,\n H+,,tB 版日期:,,+day+,,\n,7,提示,,/JOptionPane.ERROR_MESSAGE);}catch(Excepti on e){System.out.printl n(e);(注:文档可能无法思考全面,请浏览后下载,供参考。
基于java的图书管理系统源代码
声明:本系统是基于C/S的图书管理系统,主要使用的是Oracle数据库,下面附所有实现代码packagelibrary;publicclassbook_addextendsJFrameimplementsActionListener{DataBaseManagerdb=newDataBaseManager();ResultSetrs;JPanelpanel1,panel2;JLabelbook_id_label,book_name_label,author_label,press_label,press_date_label,price_label,book_num_label,borrowed_num_label,address;JTextFieldbook_id_TextField,book_name_TextField,author_TextField,press_TextField,press_date_TextField,price_TextField,book_num_TextField,borrowed_count;JComboBoxaddresst;Containerc;JButtonclear,add,exit;publicbook_add(){super("添加图书信息");c=getContentPane();c.setLayout(newBorderLayout());book_id_label=newJLabel("编号",JLabel.CENTER);book_name_label=newJLabel("名称",JLabel.CENTER);author_label=newJLabel("作者",JLabel.CENTER);press_label=newJLabel("出版社",JLabel.CENTER);press_date_label=newJLabel("出版日期",JLabel.CENTER);price_label=newJLabel("价格",JLabel.CENTER);book_num_label=newJLabel("库存数",JLabel.CENTER);borrowed_num_label=newJLabel("已借阅数",JLabel.CENTER);address=newJLabel("藏书地址",JLabel.CENTER);book_id_TextField=newJTextField(15);book_name_TextField=newJTextField(15);author_TextField=newJTextField(15);press_TextField=newJTextField(15);press_date_TextField=newJTextField(15);price_TextField=newJTextField(15);book_num_TextField=newJTextField(15);borrowed_count=newJTextField(15);borrowed_count.setText("0");addresst=newJComboBox();addresst.addItem("扬子津图书馆");addresst.addItem("荷花池图书馆");addresst.addItem("瘦西湖图书馆");addresst.addItem("淮海路图书馆");panel1=newJPanel();panel1.setLayout(newGridLayout(9,2));panel1.add(book_id_label);panel1.add(book_id_TextField);panel1.add(book_name_label);panel1.add(book_name_TextField);panel1.add(press_label);panel1.add(press_TextField);panel1.add(author_label);panel1.add(author_TextField);panel1.add(press_date_label);panel1.add(press_date_TextField);panel1.add(price_label);panel1.add(price_TextField);panel1.add(book_num_label);panel1.add(book_num_TextField);panel1.add(borrowed_num_label);panel1.add(borrowed_count);panel1.add(address);panel1.add(addresst);panel2=newJPanel();panel2.setLayout(newGridLayout(1,3));clear=newJButton("清空");clear.addActionListener(this);add=newJButton("添加");add.addActionListener(this);exit=newJButton("退出");exit.addActionListener(this);panel2.add(clear);panel2.add(add);panel2.add(exit);c.add(panel1,BorderLayout.CENTER);c.add(panel2,BorderLayout.SOUTH);setVisible(true);}publicvoidactionPerformed(ActionEvente) {if(e.getSource()==exit){this.dispose();}elseif(e.getSource()==clear){book_id_TextField.setText("");book_name_TextField.setText("");author_TextField.setText("");press_TextField.setText("");press_date_TextField.setText("");price_TextField.setText("");book_num_TextField.setText("");}elseif(e.getSource()==add){if(book_id_TextField.getText().trim().equals("")){JOptionPane.showMessageDialog(null,"书号不能为空");}elseif(book_name_TextField.getText().trim().equals("")){JOptionPane.showMessageDialog(null,"书名不能为空");}elseif(author_TextField.getText().trim().equals("")){JOptionPane.showMessageDialog(null,"作者不能为空");}elseif(press_TextField.getText().trim().equals("")){JOptionPane.showMessageDialog(null,"出版社不能为空");}elseif(press_date_TextField.getText().trim().equals("")){JOptionPane.showMessageDialog(null,"出版日期不能为空");}elseif(price_TextField.getText().trim().equals("")){JOptionPane.showMessageDialog(null,"价格不能为空");}elseif(book_num_TextField.getText().trim().equals("")){JOptionPane.showMessageDialog(null,"库存不能为空");}elseif(borrowed_count.getText().trim().equals("")){JOptionPane.showMessageDialog(null,"借阅数不能为空");}else{try{StringstrSQL="insertintobook(book_id,book_name,press,author,press_date,price,book_count,borrow ed_count,store_address) values('"+book_id_TextField.getText().trim()+"','"+book_name_TextField.getText().trim()+"','"+press_TextField.getText().trim()+"','"+author_TextField.getText().trim()+"','"+press_date_TextField.getText().trim()+"','"+price_TextField.getText().trim()+"','"+book_num_TextField.getText().trim()+"','"+borrowed_count.getText().trim()+"','"+addresst.getSelectedItem()+"')";if(db.updateSql(strSQL)){this.dispose();JOptionPane.showMessageDialog(null,"添加图书成功");}else{JOptionPane.showMessageDialog(null,"添加图书失败");this.dispose();}db.closeConnection();}catch(Exceptionex){}}}}}packagelibrary;importjavax.swing.*;importjava.awt.*;publicclassbook_deleteextendsJFrameimplementsActionListener{DataBaseManagerdb=newDataBaseManager();ResultSetrs;Containerc;JLabelTipLabel=newJLabel("请选择要删除的书名",JLabel.CENTER); JComboBoxbb=newJComboBox();JButtonyes,exit;JPanelpanel1=newJPanel();publicbook_delete(){super("删除图书信息");c=getContentPane();c.setLayout(newBorderLayout());try{StringstrSQL="selectbook_namefrombookwherebook_count>borrowed_count";rs=db.getResult(strSQL);while(rs.next()){bb.addItem(rs.getString(1));}}catch(SQLExceptionsqle){}catch(Exceptionex){}c.add(TipLabel,BorderLayout.NORTH);c.add(bb,BorderLayout.CENTER);yes=newJButton("确定");exit=newJButton("退出");yes.addActionListener(this);exit.addActionListener(this);panel1.add(yes);panel1.add(exit);c.add(panel1,BorderLayout.SOUTH);setVisible(true);}publicvoidactionPerformed(ActionEvente){if(e.getSource()==exit){this.dispose();}elseif(e.getSource()==yes){try{StringstrSQL="selectborrowed_countfrombookwherebook_name='"+bb.getSelectedItem()+"'";rs=db.getResult(strSQL);if(!rs.first()){JOptionPane.showMessageDialog(null,"书库里没有你要删除的书");}else{StringstrSql="deletefrombookwherebook_name='"+bb.getSelectedItem()+"'andborrowed_count=0";rs.first();intcount=rs.getInt(1);if(!(count==0)){JOptionPane.showMessageDialog(null,"此书还有学生没有还,不可删除");}elseif(db.updateSql(strSql)){JOptionPane.showMessageDialog(null,"删除成功");db.closeConnection();this.dispose();}else{JOptionPane.showMessageDialog(null,"删除失败");db.closeConnection();this.dispose();}}}catch(SQLExceptionsqle){}catch(Exceptionex){}}}}packagelibrary;publicclassbook_modifyextendsJFrameimplementsActionListener{DataBaseManagerdb=newDataBaseManager();ResultSetrs;JPanelpanel1,panel2,panel3;JLabelTipLabel=newJLabel("输入书名点确定,将调出此书的相关信息");JLabelbook_name_label,author_label,press_label,press_date_label,price_label;JTextFieldbook_name_TextField,author_TextField,press_TextField,press_date_TextField,price_TextField;Containerc;JButtonclear,yes,update,exit;publicbook_modify(){super("修改图书信息");c=getContentPane();c.setLayout(newBorderLayout());panel3=newJPanel();panel3.add(TipLabel);c.add(panel3,BorderLayout.NORTH);book_name_label=newJLabel("名称",JLabel.CENTER);author_label=newJLabel("作者",JLabel.CENTER);press_label=newJLabel("出版社",JLabel.CENTER);press_date_label=newJLabel("出版日期",JLabel.CENTER);price_label=newJLabel("价格",JLabel.CENTER);book_name_TextField=newJTextField(15);author_TextField=newJTextField(15);press_TextField=newJTextField(15);press_date_TextField=newJTextField(15);price_TextField=newJTextField(15);panel1=newJPanel();panel1.setLayout(newGridLayout(6,2));panel1.add(book_name_label);panel1.add(book_name_TextField);panel1.add(author_label);panel1.add(author_TextField);panel1.add(press_label);panel1.add(press_TextField);panel1.add(press_date_label);panel1.add(press_date_TextField);panel1.add(price_label);panel1.add(price_TextField);panel2=newJPanel();panel2.setLayout(newGridLayout(1,4));clear=newJButton("清空");yes=newJButton("确定");update=newJButton("更新");exit=newJButton("退出");panel2.add(clear);panel2.add(yes);panel2.add(update);panel2.add(exit);clear.addActionListener(this);yes.addActionListener(this);update.addActionListener(this);exit.addActionListener(this);update.setEnabled(false);c.add(panel1,BorderLayout.CENTER);c.add(panel2,BorderLayout.SOUTH);setVisible(true);}publicvoidactionPerformed(ActionEvente){if(e.getSource()==exit){this.dispose();;}elseif(e.getSource()==clear){book_name_TextField.setText("");author_TextField.setText("");press_TextField.setText("");press_date_TextField.setText("");price_TextField.setText("");}elseif(e.getSource()==yes){try{StringstrSQL="select*frombookwherebook_name='"+book_name_TextField.getText().trim()+"'";rs=db.getResult(strSQL);while(rs.next()){book_name_TextField.setText(rs.getString("book_name"));author_TextField.setText(rs.getString("author"));press_TextField.setText(rs.getString("press"));press_date_TextField.setText(rs.getString("press_date"));price_TextField.setText(rs.getString("price"));}update.setEnabled(true);}catch(NullPointerExceptionupe){}catch(Exceptiones){}}elseif(e.getSource()==update){try{StringstrSQL="updatebooksetbook_name='"+book_name_TextField.getText().trim()+"',press='"+press_TextField.getText().trim()+"',author='"+author_TextField.getText().trim()+"',press_date='"+press_date_TextField.getText().trim()+"',price='"+price_TextField.getText().trim()+"'wherebook_name='"+book_name_TextField.getText().trim()+"'" ;if(db.updateSql(strSQL)){this.dispose();JOptionPane.showMessageDialog(null,"更新图书成功");}else{JOptionPane.showMessageDialog(null,"更新图书失败");}db.closeConnection();}catch(Exceptionsqle){}}}}packagelibrary; publicclassbookborrowextendsJFrameimplementsActionListener{DataBaseManagerdb=newDataBaseManager();ResultSetrs;Containerc;JPanelpanel1,panel2;JLabelborrowname,bookname,borrowdate,returndate,is_return_label;JTextFieldborrowdateField,returndateField,is_return;JButtonclear,yes,cancel;JComboBoxborrownameBox=newJComboBox();JComboBoxbooknameBox=newJComboBox();publicbookborrow(){super("书籍出借");c=getContentPane();c.setLayout(newBorderLayout());Calendarcal=Calendar.getInstance();intyear,month,day;// year=cal.get(Calendar.YEAR);// month=cal.get(Calendar.MONTH)+3;//从0开始的// day=cal.get(Calendar.DAY_OF_MONTH);//Stringcdate=sdf.format(cal.getTime());//Stringda=Integer.toString(year)+"-0"+Integer.toString(month)+"-"+Integer.toString(day);borrowname=newJLabel("借阅者姓名",JLabel.CENTER);bookname=newJLabel("书名",JLabel.CENTER);borrowdate=newJLabel("借书日期",JLabel.CENTER);// returndate=newJLabel("应还日期",JLabel.CENTER);is_return_label=newJLabel("是否归还",JLabel.CENTER);borrowdateField=newJTextField(15);// borrowdateField.setText(cdate);// returndateField=newJTextField(15);// returndateField.setText(da);is_return=newJTextField(15);is_return.setText("否");try{StringstrSql="selectstudent_namefromreader";rs=db.getResult(strSql);while(rs.next()){borrownameBox.addItem(rs.getString(1));}}catch(SQLExceptionsqle){}catch(Exceptionex){}try{StringstrSQL="selectbook_namefrombookwherebook_count>borrowed_count";rs=db.getResult(strSQL);while(rs.next()){booknameBox.addItem(rs.getString(1));}}catch(SQLExceptionsqle){}catch(Exceptionex){}panel1=newJPanel();panel1.setLayout(newGridLayout(5,2));panel1.add(borrowname);panel1.add(borrownameBox);panel1.add(bookname);panel1.add(booknameBox);panel1.add(borrowdate);panel1.add(borrowdateField);// panel1.add(returndate);// panel1.add(returndateField);panel1.add(is_return_label);panel1.add(is_return);c.add(panel1,BorderLayout.CENTER);panel2=newJPanel();panel2.setLayout(newGridLayout(1,3));clear=newJButton("清空");yes=newJButton("确定");cancel=newJButton("取消");clear.addActionListener(this);yes.addActionListener(this);cancel.addActionListener(this);panel2.add(clear);panel2.add(yes);panel2.add(cancel);c.add(panel2,BorderLayout.SOUTH);setVisible(true);setSize(300,300);}publicvoidactionPerformed(ActionEvente){if(e.getSource()==cancel){this.dispose();}elseif(e.getSource()==clear){borrowdateField.setText("");// returndateField.setText("");is_return.setText("");}elseif(e.getSource()==yes){if(borrownameBox.getSelectedItem().equals("")){JOptionPane.showMessageDialog(null,"对不起,没有读者借阅");}elseif(booknameBox.getSelectedItem().equals("")){JOptionPane.showMessageDialog(null,"对不起,现在书库没有书");}else{try{//系统计算归还日期//获取输入的借阅日期,自动加两个月StringstartDate=borrowdateField.getText().trim();SimpleDateFormatformat=newSimpleDateFormat("yyyy-MM-dd");DatedateStart=format.parse(startDate);Calendarcd=Calendar.getInstance();cd.setTime(dateStart);cd.add(Calendar.MONTH,2);StringreturnDate=format.format(cd.getTime());StringstrSQL="insertintoborrow(student_name,book_name,borrow_date,return_date,is_returned)valu es('"+borrownameBox.getSelectedItem()+"','"+booknameBox.getSelectedItem()+"','"+borrowdateField.getText().trim()+"','"+returnDate+"','"+is_return.getText().trim()+"')";if(db.updateSql(strSQL)){JOptionPane.showMessageDialog(null,"借阅完成");strSQL="updatereadersetborrow_count=borrow_count+1wherestudent_name='"+borrownameBox.ge tSelectedItem()+"'";db.updateSql(strSQL);strSQL="updatebooksetborrowed_count=borrowed_count+1wherebook_name='"+booknameBox.get SelectedItem()+"'";db.updateSql(strSQL);db.closeConnection();this.dispose();}else{JOptionPane.showMessageDialog(null,"借阅失败");db.closeConnection();this.dispose();}}catch(Exceptionse){}}}}}packagelibrary;importjavax.swing.*;importjava.awt.*; publicclassbookborrowlistextendsJFrameimplementsActionListener{DataBaseManagerdb=newDataBaseManager();ResultSetrs;Containerc;JPanelpanel1,panel2;JLabelbookname,studentname;JTextFieldbooknamet,studentnamet;JButtonsearch,exit;JTabletable=null;DefaultTableModeldefaultModel=null;publicbookborrowlist(){super("借阅列表");c=getContentPane();c.setLayout(newBorderLayout());bookname=newJLabel("书名",JLabel.CENTER);studentname=newJLabel("人名",JLabel.CENTER);booknamet=newJTextField(15);studentnamet=newJTextField(15);search=newJButton("查询");exit=newJButton("退出");search.addActionListener(this);exit.addActionListener(this);Boxbox1=Box.createHorizontalBox();box1.add(studentname);box1.add(studentnamet);box1.add(search);Boxbox2=Box.createHorizontalBox();box2.add(bookname);box2.add(booknamet);box2.add(exit);BoxboxH=Box.createVerticalBox();boxH.add(box1);boxH.add(box2);boxH.add(Box.createVerticalGlue());panel1=newJPanel();panel1.add(boxH);panel2=newJPanel();String[]name={"读者","书名","借阅时间","应还时间","是否归还"};String[][]data=newString[0][0];defaultModel=newDefaultTableModel(data,name);table=newJTable(defaultModel);table.setPreferredScrollableViewportSize(newDimension(400,80));JScrollPanes=newJScrollPane(table);panel2.add(s);c.add(panel1,BorderLayout.NORTH);c.add(panel2,BorderLayout.SOUTH);}publicvoidactionPerformed(ActionEvente){if(e.getSource()==exit){db.closeConnection();this.dispose();}elseif(e.getSource()==search){StringstrSQL="selectstudent_name,book_name,borrow_date,return_date,is_returnedfromborrow";StringstrSql=null;if(studentnamet.getText().trim().equals("")&&booknamet.getText().trim().equals("")){strSql=strSQL;}elseif(studentnamet.getText().trim().equals("")){strSql="selectstudent_name,book_name,borrow_date,return_date,is_returnedfromborrowwherebook_ name='"+booknamet.getText().trim()+"'";}elseif(booknamet.getText().trim().equals("")){strSql="selectstudent_name,book_name,borrow_date,return_date,is_returnedfromborrowwherestude nt_name='"+studentnamet.getText().trim()+"'";}else{strSql="selectstudent_name,book_name,borrow_date,return_date,is_returnedfromborrowwherestude nt_name='"+studentnamet.getText().trim()+"'andbook_name='"+booknamet.getText().trim()+"'";JOptionPane.showMessageDialog(null,"你借的书还还有7天超期");}try{introwCount=defaultModel.getRowCount()-1;intj=rowCount;for(inti=0;i<=rowCount;i++){defaultModel.removeRow(j);defaultModel.setRowCount(j);j=j-1;}rs=db.getResult(strSql);while(rs.next()){VectorinsertRow=newVector();insertRow.addElement(rs.getString(1));insertRow.addElement(rs.getString(2));insertRow.addElement(rs.getString(3));insertRow.addElement(rs.getString(4));insertRow.addElement(rs.getString(5));defaultModel.addRow(insertRow);}table.revalidate();}catch(SQLExceptionsqle){}catch(Exceptionex){}}}}packagelibrary;importjavax.swing.*;importjava.awt.*; publicclassbookborrowModifyextendsJFrameimplementsActionListener{DataBaseManagerdb=newDataBaseManager();ResultSetrs;JPanelpanel1,panel2,panel3;Containerc;JLabeltiplabel=newJLabel("输入借阅者姓名和书名单击确定,将调出此书的相关信息");JLabelborrowlabel,namelabel,borrowdate;JTextFieldborrowField,nameField,dateField;JButtonclear,yes,update,cancel;publicbookborrowModify(){super("修改图书出借信息");c=getContentPane();c.setLayout(newBorderLayout());panel3=newJPanel();panel3.add(tiplabel);c.add(panel3,BorderLayout.NORTH);borrowlabel=newJLabel("借阅者姓名",JLabel.CENTER);namelabel=newJLabel("书名",JLabel.CENTER);borrowdate=newJLabel("借书日期",JLabel.CENTER);borrowField=newJTextField(15);nameField=newJTextField(15);dateField=newJTextField(15);panel1=newJPanel();panel1.setLayout(newGridLayout(3,2));panel1.add(borrowlabel);panel1.add(borrowField);panel1.add(namelabel);panel1.add(nameField);panel1.add(borrowdate);panel1.add(dateField);c.add(panel1,BorderLayout.CENTER);panel2=newJPanel();panel2.setLayout(newGridLayout(1,4));clear=newJButton("清空");yes=newJButton("确定");update=newJButton("更新");cancel=newJButton("取消");clear.addActionListener(this);yes.addActionListener(this);update.addActionListener(this);cancel.addActionListener(this);panel2.add(clear);panel2.add(yes);panel2.add(update);panel2.add(cancel);c.add(panel2,BorderLayout.SOUTH);setVisible(true);setSize(400,200);}publicvoidactionPerformed(ActionEvente){if(e.getSource()==clear){borrowField.setText("");nameField.setText("");dateField.setText("");}elseif(e.getSource()==cancel){this.dispose();}elseif(e.getSource()==yes){try{StringstrSQL="selectstudent_name,book_name,borrow_datefromborrowwherestudent_name='"+borrowField.getText().trim()+"'andbook_name='"+nameField.getText().trim()+"'";rs=db.getResult(strSQL);if(!rs.first()){JOptionPane.showMessageDialog(null,"此学生没有借过书或者没有此书");}else{borrowField.setText(rs.getString(1));nameField.setText(rs.getString(2));dateField.setText(rs.getString(3));update.setEnabled(true);}}catch(Exceptionex){}}elseif(e.getSource()==update){StringstrSQL="updateborrowsetborrow_date='"+dateField.getText().trim()+"'wherestudent_name='"+borrowField.getText().trim()+"'andbook_name='"+nameField.getText().trim()+"'";if(db.updateSql(strSQL)){JOptionPane.showMessageDialog(null,"更新成功");db.closeConnection();this.dispose();}else{JOptionPane.showMessageDialog(null,"更新失败");db.closeConnection();this.dispose();}}}}packagelibrary;importjavax.swing.*;importjava.awt.*;publicclassbooklistextendsJFrameimplementsActionListener{DataBaseManagerdb=newDataBaseManager();ResultSetrs;Containerc;JPanelpanel1,panel2,panel3;JLabelbookname,authorname,press;JTextFieldbooknamet,authornamet,presst;JButtonsearch,exit;JTabletable=null;DefaultTableModeldefaultModel=null;publicbooklist(){super("书籍信息查询");c=getContentPane();c.setLayout(newBorderLayout());bookname=newJLabel("书名",JLabel.CENTER);authorname=newJLabel("作者",JLabel.CENTER);press=newJLabel("出版社",JLabel.CENTER);booknamet=newJTextField(15);authornamet=newJTextField(15);presst=newJTextField(15);search=newJButton("查询");exit=newJButton("退出");search.addActionListener(this);exit.addActionListener(this);panel1=newJPanel();panel1.add(bookname);panel1.add(booknamet);panel1.add(authorname);panel1.add(authornamet);panel2=newJPanel();panel2.add(press);panel2.add(presst);panel2.add(search);panel2.add(exit);String[]name={"书号","书名","出版社","作者","出版日期","价格","图书数目","已借数目","剩余数目","藏书地址"};String[][]data=newString[0][0];defaultModel=newDefaultTableModel(data,name);table=newJTable(defaultModel);table.setPreferredScrollableViewportSize(newDimension(400,80));JScrollPanes=newJScrollPane(table);panel3=newJPanel();panel3.add(s);c.add(panel1,BorderLayout.NORTH);c.add(panel2,BorderLayout.CENTER);c.add(panel3,BorderLayout.SOUTH);}publicvoidactionPerformed(ActionEvente){if(e.getSource()==exit){db.closeConnection();this.dispose();}elseif(e.getSource()==search){StringstrSQL="selectbook_id,book_name,press,author,press_date,price,book_count,borrowed_count, book_count-borrowed_count,store_addressfrombook";StringstrSql=null;if(booknamet.getText().trim().equals("")&&authornamet.getText().trim().equals("")&&presst.getTex t().trim().equals("")){strSql=strSQL;}elseif(booknamet.getText().trim().equals("")&&authornamet.getText().trim().equals("")){strSql="selectbook_id,book_name,press,author,press_date,price,book_count,borrowed_count,book_c ount-borrowed_count,store_addressfrombookwherepress='"+presst.getText().trim()+"'";}elseif(authornamet.getText().trim().equals("")&&presst.getText().trim().equals("")){strSql="selectbook_id,book_name,press,author,press_date,price,book_count,borrowed_count,book_c ount-borrowed_count,store_addressfrombookwherebook_name='"+booknamet.getText().trim()+"'";}elseif(booknamet.getText().trim().equals("")&&presst.getText().trim().equals("")){strSql="selectbook_id,book_name,press,author,press_date,price,book_count,borrowed_count,book_c ount-borrowed_count,store_addressfrombookwhereauthor='"+authornamet.getText().trim()+"'";}else{strSql="selectbook_id,book_name,press,author,press_date,price,book_count,borrowed_count,book_c ount-borrowed_count,store_addressfrombookwherebook_name='"+booknamet.getText().trim()+"'andauthor='"+authornamet.getText().trim()+"'andpress='"+presst.getText().trim()+"'";}try{introwCount=defaultModel.getRowCount()-1;intj=rowCount;for(inti=0;i<=rowCount;i++){defaultModel.removeRow(j);defaultModel.setRowCount(j);j=j-1;}rs=db.getResult(strSql);while(rs.next()){VectorinsertRow=newVector();insertRow.addElement(rs.getString(1));insertRow.addElement(rs.getString(2));insertRow.addElement(rs.getString(3));insertRow.addElement(rs.getString(4));insertRow.addElement(rs.getString(5));insertRow.addElement(rs.getString(6));insertRow.addElement(rs.getString(7));insertRow.addElement(rs.getString(8));insertRow.addElement(rs.getString(9));insertRow.addElement(rs.getString(10));defaultModel.addRow(insertRow);}table.revalidate();}catch(SQLExceptionsqle){}catch(Exceptionex){}}}}packagelibrary;importjavax.swing.*;importjava.awt.*; publicclassbookreturnextendsJFrameimplementsActionListener{DataBaseManagerdb=newDataBaseManager();ResultSetrs;JPanelpanel1,panel2;Containerc;JLabelnamelabel,booklabel,returndatelabel;JTextFieldreturnField;JButtonclear,yes,cancel;JComboBoxbookname=newJComboBox();JComboBoxreadername=newJComboBox();publicbookreturn(){super("图书还入");c=getContentPane();c.setLayout(newBorderLayout());Calendarcal=Calendar.getInstance();Stringcdate=sdf.format(cal.getTime());namelabel=newJLabel("还书者姓名",JLabel.CENTER);booklabel=newJLabel("书名",JLabel.CENTER);returndatelabel=newJLabel("日期",JLabel.CENTER);returnField=newJTextField(15);returnField.setText(cdate);try{Strings="";StringstrSQL="selectstudent_namefromreaderwhereborrow_count!=0";rs=db.getResult(strSQL);while(rs.next()){readername.addItem(rs.getString(1));}}catch(SQLExceptionsqle){}catch(Exceptionex){。
用Java写一个图书管理系统的代码
用Java写一个图书管理系统的代码```import java.util.*;public class BookManager {// Create a list for book storageprivate List<Book> books;public BookManager() {books = new ArrayList<Book>();}// Add a book to the listpublic void addBook(Book book) {books.add(book);}// Remove a book from the listpublic void removeBook(Book book) {books.remove(book);}// Get all books in the listpublic List<Book> getAllBooks() {return books;}// Search a book by book namepublic List<Book> searchByName(String name) {List<Book> resultBooks = new ArrayList<Book>();for (Book book : books) {if (book.getName().equals(name)) {resultBooks.add(book);}}return resultBooks;}// Search a book by author namepublic List<Book> searchByAuthor(String author) { List<Book> resultBooks = new ArrayList<Book>(); for (Book book : books) {if (book.getAuthor().equals(author)) {resultBooks.add(book);}}return resultBooks;}}class Book {private String name;private String author;public Book(String name, String author) { = name;this.author = author;}public String getName() {return name;}public void setName(String name) { = name;}public String getAuthor() {return author;}public void setAuthor(String author) { this.author = author;}}```。
基于java的图书管理系统源代码
声明:本系统是基于C/S的图书管理系统,主要使用的是Oracle数据库,下面附所有实现代码package library;import java.awt.BorderLayout;import java.awt.Container;import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.sql.ResultSet;import javax.swing.JButton;import javax.swing.JComboBox;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JTextField;public class book_add extends JFrame implements ActionListener{ DataBaseManager db=new DataBaseManager();ResultSet rs;JPanel panel1,panel2;JLabel book_id_label,book_name_label,author_label,press_label,press_date_label,price_label,book_num_label,borrowed_num_label,address;JTextField book_id_TextField,book_name_TextField,author_TextField,press_TextField,press_date_TextField,price_TextField,book_num_TextField, borrowed_count;JComboBox addresst;Container c;JButton clear,add,exit;public book_add(){super("添加图书信息");c=getContentPane();c.setLayout(new BorderLayout());book_id_label=new JLabel("编号",JLabel.CENTER);book_name_label=new JLabel("名称",JLabel.CENTER);author_label=new JLabel("作者",JLabel.CENTER);press_label=new JLabel("出版社",JLabel.CENTER);press_date_label=new JLabel("出版日期",JLabel.CENTER); price_label=new JLabel("价格",JLabel.CENTER);book_num_label=new JLabel("库存数",JLabel.CENTER); borrowed_num_label=new JLabel("已借阅数",JLabel.CENTER); address=new JLabel("藏书地址",JLabel.CENTER);book_id_TextField=new JTextField(15);book_name_TextField=new JTextField(15);author_TextField=new JTextField(15);press_TextField=new JTextField(15);press_date_TextField=new JTextField(15);price_TextField=new JTextField(15);book_num_TextField=new JTextField(15);borrowed_count=new JTextField(15);borrowed_count.setText("0");addresst=new JComboBox();addresst.addItem("扬子津图书馆");addresst.addItem("荷花池图书馆");addresst.addItem("瘦西湖图书馆");addresst.addItem("淮海路图书馆");panel1=new JPanel();panel1.setLayout(new GridLayout(9,2));panel1.add(book_id_label);panel1.add(book_id_TextField);panel1.add(book_name_label);panel1.add(book_name_TextField);panel1.add(press_label);panel1.add(press_TextField);panel1.add(author_label);panel1.add(author_TextField);panel1.add(press_date_label);panel1.add(press_date_TextField);panel1.add(price_label);panel1.add(price_TextField);panel1.add(book_num_label);panel1.add(book_num_TextField);panel1.add(borrowed_num_label);panel1.add(borrowed_count);panel1.add(address);panel1.add(addresst);panel2=new JPanel();panel2.setLayout(new GridLayout(1,3));clear=new JButton("清空");clear.addActionListener(this);add=new JButton("添加");add.addActionListener(this);exit=new JButton("退出");exit.addActionListener(this);panel2.add(clear);panel2.add(add);panel2.add(exit);c.add(panel1,BorderLayout.CENTER);c.add(panel2,BorderLayout.SOUTH);setVisible(true);}public void actionPerformed(ActionEvent e){if(e.getSource()==exit){this.dispose();}else if(e.getSource()==clear){book_id_TextField.setText("");book_name_TextField.setText("");author_TextField.setText("");press_TextField.setText("");press_date_TextField.setText("");price_TextField.setText("");book_num_TextField.setText("");}else if(e.getSource()==add){if(book_id_TextField.getText().trim().equals("")){JOptionPane.showMessageDialog(null, "书号不能为空");}else if(book_name_TextField.getText().trim().equals("")){JOptionPane.showMessageDialog(null, "书名不能为空");}else if(author_TextField.getText().trim().equals("")){JOptionPane.showMessageDialog(null, "作者不能为空");}else if(press_TextField.getText().trim().equals("")){JOptionPane.showMessageDialog(null, "出版社不能为空");}else if(press_date_TextField.getText().trim().equals("")){JOptionPane.showMessageDialog(null, "出版日期不能为空");}else if(price_TextField.getText().trim().equals("")){JOptionPane.showMessageDialog(null, "价格不能为空");}else if(book_num_TextField.getText().trim().equals("")){JOptionPane.showMessageDialog(null, "库存不能为空");}else if(borrowed_count.getText().trim().equals("")){JOptionPane.showMessageDialog(null, "借阅数不能为空");}else {try{String strSQL="insert into book(book_id,book_name,press,author,press_date,price,book_count,borrowed_count ,store_address) values('"+book_id_TextField.getText().trim()+"','"+book_name_TextField.getText().trim()+"','"+press_TextField.getText().trim()+"','"+author_TextField.getText().trim()+"','"+press_date_TextField.getText().trim()+"','"+price_TextField.getText().trim()+"','"+book_num_TextField.getText().trim()+"','"+borrowed_count.getText().trim()+"','"+addresst.getSelectedItem()+"')";if(db.updateSql(strSQL)){this.dispose();JOptionPane.showMessageDialog(null,"添加图书成功");}else{JOptionPane.showMessageDialog(null,"添加图书失败");this.dispose();}db.closeConnection();}catch(Exception ex){System.out.println(ex.toString());}}}}}package library;import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.sql.ResultSet;import java.sql.SQLException;public class book_delete extends JFrame implements ActionListener{ DataBaseManager db=new DataBaseManager();ResultSet rs;Container c;JLabel TipLabel=new JLabel("请选择要删除的书名",JLabel.CENTER);JComboBox bb=new JComboBox();JButton yes,exit;JPanel panel1=new JPanel();public book_delete(){super("删除图书信息");c=getContentPane();c.setLayout(new BorderLayout());try{String strSQL="select book_name from book where book_count>borrowed_count";rs=db.getResult(strSQL);while(rs.next()){bb.addItem(rs.getString(1));}}catch(SQLException sqle){System.out.println(sqle.toString());}catch(Exception ex){System.out.println(ex.toString());}c.add(TipLabel,BorderLayout.NORTH);c.add(bb,BorderLayout.CENTER);yes=new JButton("确定");exit=new JButton("退出");yes.addActionListener(this);exit.addActionListener(this);panel1.add(yes);panel1.add(exit);c.add(panel1,BorderLayout.SOUTH);setVisible(true);}public void actionPerformed(ActionEvent e){if(e.getSource()==exit){this.dispose();}else if(e.getSource()==yes){try{String strSQL="select borrowed_count from book where book_name='"+bb.getSelectedItem()+"'";rs=db.getResult(strSQL);if(!rs.first()){JOptionPane.showMessageDialog(null,"书库里没有你要删除的书");}else{String strSql="delete from book where book_name='"+bb.getSelectedItem()+"'and borrowed_count=0";rs.first();int count=rs.getInt(1);if(!(count==0)){JOptionPane.showMessageDialog(null,"此书还有学生没有还,不可删除");}else if(db.updateSql(strSql)){JOptionPane.showMessageDialog(null,"删除成功");db.closeConnection();this.dispose();}else{JOptionPane.showMessageDialog(null,"删除失败");db.closeConnection();this.dispose();}}}catch(SQLException sqle){System.out.println(sqle.toString());}catch(Exception ex){System.out.println(ex.toString());}}}}package library;import java.awt.BorderLayout;import java.awt.Container;import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.sql.ResultSet;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JTextField;public class book_modify extends JFrame implements ActionListener{ DataBaseManager db=new DataBaseManager();ResultSet rs;JPanel panel1,panel2,panel3;JLabel TipLabel=new JLabel("输入书名点确定,将调出此书的相关信息");JLabel book_name_label,author_label,press_label,press_date_label,price_label;JTextField book_name_TextField,author_TextField,press_TextField,press_date_TextField,price_TextField;Container c;JButton clear,yes,update,exit;public book_modify(){super("修改图书信息");c=getContentPane();c.setLayout(new BorderLayout());panel3=new JPanel();panel3.add(TipLabel);c.add(panel3,BorderLayout.NORTH);book_name_label=new JLabel("名称",JLabel.CENTER);author_label=new JLabel("作者",JLabel.CENTER);press_label=new JLabel("出版社",JLabel.CENTER);press_date_label=new JLabel("出版日期",JLabel.CENTER);price_label=new JLabel("价格",JLabel.CENTER);book_name_TextField=new JTextField(15);author_TextField=new JTextField(15);press_TextField=new JTextField(15);press_date_TextField=new JTextField(15);price_TextField=new JTextField(15);panel1=new JPanel();panel1.setLayout(new GridLayout(6,2));panel1.add(book_name_label);panel1.add(book_name_TextField);panel1.add(author_label);panel1.add(author_TextField);panel1.add(press_label);panel1.add(press_TextField);panel1.add(press_date_label);panel1.add(press_date_TextField);panel1.add(price_label);panel1.add(price_TextField);panel2=new JPanel();panel2.setLayout(new GridLayout(1,4));clear=new JButton("清空");yes=new JButton("确定");update=new JButton("更新");exit=new JButton("退出");panel2.add(clear);panel2.add(yes);panel2.add(update);panel2.add(exit);clear.addActionListener(this);yes.addActionListener(this);update.addActionListener(this);exit.addActionListener(this);update.setEnabled(false);c.add(panel1,BorderLayout.CENTER);c.add(panel2,BorderLayout.SOUTH);setVisible(true);}public void actionPerformed(ActionEvent e){if(e.getSource()==exit){this.dispose();;}else if(e.getSource()==clear){book_name_TextField.setText("");author_TextField.setText("");press_TextField.setText("");press_date_TextField.setText("");price_TextField.setText("");}else if(e.getSource()==yes){try{String strSQL="select * from book where book_name='"+book_name_TextField.getText().trim()+"'";rs=db.getResult(strSQL);while(rs.next()){book_name_TextField.setText(rs.getString("book_name"));author_TextField.setText(rs.getString("author"));press_TextField.setText(rs.getString("press"));press_date_TextField.setText(rs.getString("press_date"));price_TextField.setText(rs.getString("price"));}update.setEnabled(true);}catch(NullPointerException upe){System.out.println(upe.toString());}catch(Exception es){System.out.println(es.toString());}}else if(e.getSource()==update){try{String strSQL="update book set book_name='"+book_name_TextField.getText().trim()+"',press='"+press_TextField.getText().trim()+"',author='"+author_TextField.getText().trim()+"',press_date='"+press_date_TextField.getText().trim()+"',price='"+price_TextField.getText().trim()+"' where book_name='"+book_name_TextField.getText().trim()+"'";if(db.updateSql(strSQL)){this.dispose();JOptionPane.showMessageDialog(null,"更新图书成功");}else {JOptionPane.showMessageDialog(null,"更新图书失败");}db.closeConnection();}catch(Exception sqle){System.out.println(sqle.toString());}}}}package library;import java.awt.BorderLayout;import java.awt.Container;import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.sql.ResultSet;import java.sql.SQLException;import java.text.DateFormat;import java.text.SimpleDateFormat;import java.util.Calendar;import java.util.Date;import javax.swing.JButton;import javax.swing.JComboBox;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JTextField;public class bookborrow extends JFrame implements ActionListener{ DataBaseManager db=new DataBaseManager();ResultSet rs;Container c;JPanel panel1,panel2;JLabel borrowname,bookname,borrowdate,returndate,is_return_label;JTextField borrowdateField,returndateField,is_return;JButton clear,yes,cancel;JComboBox borrownameBox=new JComboBox();JComboBox booknameBox=new JComboBox();public bookborrow(){super("书籍出借");c=getContentPane();c.setLayout(new BorderLayout());Calendar cal = Calendar.getInstance();int year,month,day;// year=cal.get(Calendar.YEAR);// month=cal.get(Calendar.MONTH)+3;//从0开始的// day=cal.get(Calendar.DAY_OF_MONTH);// java.text.SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); // String cdate = sdf.format(cal.getTime());// Stringda=Integer.toString(year)+"-0"+Integer.toString(month)+"-"+Integer.toString(day);borrowname=new JLabel("借阅者姓名",JLabel.CENTER);bookname=new JLabel("书名",JLabel.CENTER);borrowdate=new JLabel("借书日期",JLabel.CENTER);// returndate=new JLabel("应还日期",JLabel.CENTER);is_return_label=new JLabel("是否归还",JLabel.CENTER);borrowdateField=new JTextField(15);// borrowdateField.setText(cdate);// returndateField=new JTextField(15);// returndateField.setText(da);is_return=new JTextField(15);is_return.setText("否");try{String strSql="select student_name from reader ";rs=db.getResult(strSql);while(rs.next()){borrownameBox.addItem(rs.getString(1));}}catch(SQLException sqle){System.out.println(sqle.toString());}catch(Exception ex){System.out.println(ex.toString());}String strSQL="select book_name from book where book_count>borrowed_count";rs=db.getResult(strSQL);while(rs.next()){booknameBox.addItem(rs.getString(1));}}catch(SQLException sqle){System.out.println(sqle.toString());}catch(Exception ex){System.out.println(ex.toString());}panel1=new JPanel();panel1.setLayout(new GridLayout(5,2));panel1.add(borrowname);panel1.add(borrownameBox);panel1.add(bookname);panel1.add(booknameBox);panel1.add(borrowdate);panel1.add(borrowdateField);// panel1.add(returndate);// panel1.add(returndateField);panel1.add(is_return_label);panel1.add(is_return);c.add(panel1,BorderLayout.CENTER);panel2=new JPanel();panel2.setLayout(new GridLayout(1,3));clear=new JButton("清空");yes=new JButton("确定");cancel=new JButton("取消");clear.addActionListener(this);yes.addActionListener(this);cancel.addActionListener(this);panel2.add(clear);panel2.add(yes);panel2.add(cancel);c.add(panel2,BorderLayout.SOUTH);setVisible(true);setSize(300,300);}public void actionPerformed(ActionEvent e){if(e.getSource()==cancel)this.dispose();}else if(e.getSource()==clear){borrowdateField.setText("");// returndateField.setText("");is_return.setText("");}else if(e.getSource()==yes){if(borrownameBox.getSelectedItem().equals("")){JOptionPane.showMessageDialog(null, "对不起,没有读者借阅");}else if(booknameBox.getSelectedItem().equals("")){JOptionPane.showMessageDialog(null, "对不起,现在书库没有书");}else {try{//系统计算归还日期//获取输入的借阅日期,自动加两个月String startDate=borrowdateField.getText().trim();SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");Date dateStart=format.parse(startDate);Calendar cd=Calendar.getInstance();cd.setTime(dateStart);cd.add(Calendar.MONTH, 2);String returnDate=format.format(cd.getTime());String strSQL="insert into borrow(student_name,book_name,borrow_date,return_date,is_returned) values('"+borrownameBox.getSelectedItem()+"','"+booknameBox.getSelectedItem()+"','"+borrowdateField.getText().trim()+"','"+returnDate+"','"+is_return.getText().trim()+"')";if(db.updateSql(strSQL)){JOptionPane.showMessageDialog(null, "借阅完成");strSQL = "update reader set borrow_count=borrow_count+1 where student_name='"+borrownameBox.getSelectedItem()+"'";db.updateSql(strSQL);strSQL="update book set borrowed_count=borrowed_count+1 where book_name='"+booknameBox.getSelectedItem()+"'";db.updateSql(strSQL);db.closeConnection();this.dispose();}else{JOptionPane.showMessageDialog(null, "借阅失败");db.closeConnection();this.dispose();}}catch(Exception se){System.out.println(se.toString());}}}}}package library;import javax.swing.*;import javax.swing.table.DefaultTableModel;import java.awt.*;import java.awt.event.*;import java.sql.ResultSet;import java.sql.SQLException;import java.util.Vector;public class bookborrowlist extends JFrame implements ActionListener{ DataBaseManager db=new DataBaseManager();ResultSet rs;Container c;JPanel panel1,panel2;JLabel bookname,studentname;JTextField booknamet,studentnamet;JButton search,exit;JTable table=null;DefaultTableModel defaultModel=null;public bookborrowlist(){super("借阅列表");c=getContentPane();c.setLayout(new BorderLayout());bookname=new JLabel("书名",JLabel.CENTER);studentname=new JLabel("人名",JLabel.CENTER);booknamet=new JTextField(15);studentnamet=new JTextField(15);search=new JButton("查询");exit=new JButton("退出");search.addActionListener(this);exit.addActionListener(this);Box box1=Box.createHorizontalBox();box1.add(studentname);box1.add(studentnamet);box1.add(search);Box box2=Box.createHorizontalBox();box2.add(bookname);box2.add(booknamet);box2.add(exit);Box boxH=Box.createVerticalBox();boxH.add(box1);boxH.add(box2);boxH.add(Box.createVerticalGlue());panel1=new JPanel();panel1.add(boxH);panel2=new JPanel();String []name={"读者","书名","借阅时间","应还时间","是否归还"};String [][]data=new String[0][0];defaultModel=new DefaultTableModel(data,name);table=new JTable(defaultModel);table.setPreferredScrollableViewportSize(new Dimension(400,80));JScrollPane s=new JScrollPane(table);panel2.add(s);c.add(panel1,BorderLayout.NORTH);c.add(panel2,BorderLayout.SOUTH);}public void actionPerformed(ActionEvent e){if(e.getSource()==exit){db.closeConnection();this.dispose();}else if(e.getSource()==search){String strSQL="select student_name,book_name,borrow_date,return_date,is_returned from borrow";String strSql=null;if(studentnamet.getText().trim().equals("")&&booknamet.getText().trim().eq uals("")){strSql=strSQL;}else if(studentnamet.getText().trim().equals("")){strSql="selectstudent_name,book_name,borrow_date,return_date,is_returned from borrow where book_name='"+booknamet.getText().trim()+"'";}else if(booknamet.getText().trim().equals("")){strSql="selectstudent_name,book_name,borrow_date,return_date,is_returned from borrow where student_name='"+studentnamet.getText().trim()+"'";}else{strSql="selectstudent_name,book_name,borrow_date,return_date,is_returned from borrow where student_name='"+studentnamet.getText().trim()+"'and book_name='"+booknamet.getText().trim()+"'";JOptionPane.showMessageDialog(null, "你借的书还还有7天超期");}try{int rowCount=defaultModel.getRowCount()-1;int j=rowCount;for(int i=0;i<=rowCount;i++){defaultModel.removeRow(j);defaultModel.setRowCount(j);j=j-1;}rs=db.getResult(strSql);while(rs.next()){Vector insertRow=new Vector();insertRow.addElement(rs.getString(1));insertRow.addElement(rs.getString(2));insertRow.addElement(rs.getString(3));insertRow.addElement(rs.getString(4));insertRow.addElement(rs.getString(5));defaultModel.addRow(insertRow);}table.revalidate();}catch(SQLException sqle){System.out.println(sqle.toString());}catch(Exception ex){System.out.println(ex.toString());}}}}package library;import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.sql.ResultSet;public class bookborrowModify extends JFrame implements ActionListener{ DataBaseManager db=new DataBaseManager();ResultSet rs;JPanel panel1,panel2,panel3;Container c;JLabel tiplabel=new JLabel("输入借阅者姓名和书名单击确定,将调出此书的相关信息");JLabel borrowlabel,namelabel,borrowdate;JTextField borrowField,nameField,dateField;JButton clear,yes,update,cancel;public bookborrowModify(){super("修改图书出借信息");c=getContentPane();c.setLayout(new BorderLayout());panel3=new JPanel();panel3.add(tiplabel);c.add(panel3,BorderLayout.NORTH);borrowlabel=new JLabel("借阅者姓名",JLabel.CENTER);namelabel=new JLabel("书名",JLabel.CENTER);borrowdate=new JLabel("借书日期",JLabel.CENTER);borrowField=new JTextField(15);nameField=new JTextField(15);dateField=new JTextField(15);panel1=new JPanel();panel1.setLayout(new GridLayout(3,2));panel1.add(borrowlabel);panel1.add(borrowField);panel1.add(namelabel);panel1.add(nameField);panel1.add(borrowdate);panel1.add(dateField);c.add(panel1,BorderLayout.CENTER);panel2=new JPanel();panel2.setLayout(new GridLayout(1,4));clear=new JButton("清空");yes=new JButton("确定");update=new JButton("更新");cancel=new JButton("取消");clear.addActionListener(this);yes.addActionListener(this);update.addActionListener(this);cancel.addActionListener(this);panel2.add(clear);panel2.add(yes);panel2.add(update);panel2.add(cancel);c.add(panel2,BorderLayout.SOUTH);setVisible(true);setSize(400,200);}public void actionPerformed(ActionEvent e){if(e.getSource()==clear){borrowField.setText("");nameField.setText("");dateField.setText("");}else if(e.getSource()==cancel){this.dispose();}else if(e.getSource()==yes){try{String strSQL="select student_name,book_name,borrow_date from borrow where student_name='"+borrowField.getText().trim()+"'and book_name='"+nameField.getText().trim()+"'";rs=db.getResult(strSQL);if(!rs.first()){JOptionPane.showMessageDialog(null,"此学生没有借过书或者没有此书");}else{borrowField.setText(rs.getString(1));nameField.setText(rs.getString(2));dateField.setText(rs.getString(3));update.setEnabled(true);}}catch(Exception ex){System.out.println(ex.toString());}}else if(e.getSource()==update){String strSQL="update borrow set borrow_date='"+dateField.getText().trim()+"' where student_name='"+borrowField.getText().trim()+"'and book_name='"+nameField.getText().trim()+"'";if(db.updateSql(strSQL)){JOptionPane.showMessageDialog(null,"更新成功");db.closeConnection();this.dispose();}else{JOptionPane.showMessageDialog(null,"更新失败");db.closeConnection();this.dispose();}}}}package library;import javax.swing.*;import javax.swing.table.DefaultTableModel;import java.awt.*;import java.awt.event.*;import java.sql.ResultSet;import java.sql.SQLException;import java.util.Vector;public class booklist extends JFrame implements ActionListener{ DataBaseManager db=new DataBaseManager();ResultSet rs;Container c;JPanel panel1,panel2,panel3;JLabel bookname,authorname,press;JTextField booknamet,authornamet,presst;JButton search,exit;JTable table=null;DefaultTableModel defaultModel=null;public booklist(){super("书籍信息查询");c=getContentPane();c.setLayout(new BorderLayout());bookname=new JLabel("书名",JLabel.CENTER);authorname=new JLabel("作者",JLabel.CENTER);press=new JLabel("出版社",JLabel.CENTER);booknamet=new JTextField(15);authornamet=new JTextField(15);presst=new JTextField(15);search=new JButton("查询");exit=new JButton("退出");search.addActionListener(this);exit.addActionListener(this);panel1=new JPanel();panel1.add(bookname);panel1.add(booknamet);panel1.add(authorname);panel1.add(authornamet);panel2=new JPanel();panel2.add(press);panel2.add(presst);panel2.add(search);panel2.add(exit);String []name={"书号","书名","出版社","作者","出版日期","价格","图书数目","已借数目","剩余数目","藏书地址"};String [][]data=new String[0][0];defaultModel=new DefaultTableModel(data,name);table=new JTable(defaultModel);table.setPreferredScrollableViewportSize(new Dimension(400,80));JScrollPane s=new JScrollPane(table);panel3=new JPanel();panel3.add(s);c.add(panel1,BorderLayout.NORTH);c.add(panel2,BorderLayout.CENTER);c.add(panel3,BorderLayout.SOUTH);}public void actionPerformed(ActionEvent e){if(e.getSource()==exit){db.closeConnection();this.dispose();}else if(e.getSource()==search){String strSQL="select book_id,book_name,press,author,press_date,price,book_count,borrowed_count,book _count-borrowed_count,store_address from book";String strSql=null;if(booknamet.getText().trim().equals("")&&authornamet.getText().trim().equ als("")&&presst.getText().trim().equals("")){strSql=strSQL;}elseif(booknamet.getText().trim().equals("")&&authornamet.getText().trim().equals( "")){strSql="selectbook_id,book_name,press,author,press_date,price,book_count,borrowed_count,book _count-borrowed_count,store_address from book where press='"+presst.getText().trim()+"'";}elseif(authornamet.getText().trim().equals("")&&presst.getText().trim().equals("") ){strSql="selectbook_id,book_name,press,author,press_date,price,book_count,borrowed_count,book _count-borrowed_count,store_address from book where book_name='"+booknamet.getText().trim()+"'";}elseif(booknamet.getText().trim().equals("")&&presst.getText().trim().equals(""))。
Java图书管理系统-附源码
图书信息删除:
图书信息显示:
图书借阅:
图书归还:
分析总结:
本程序在数据库设计方面可以改为多张表存储的方式,用三张表来记录图书信息,借阅关系和学生信息,这样可以减少数据冗余,还可以增加一些其他功能,比如图书挂失等功能。由于刚刚接触到Java界面设计,所以本程序在界面设计方面还有有待改进的地方。
JMenuItem itemDelete = new JMenuItem();
JMenuItem itemSelect = new JMenuItem();
JMenuItem itБайду номын сангаасmBook = new JMenuItem();
JMenuItem itemReturn = new JMenuItem();
图书ID,图书名称,图书所有者,图书的状态,图书使用者(允许为空)均为varchar(50)类型,在Java中可以方便的查询。图书存储信息的具体内容如下图所示:
功能模块:
程序设计:
主框架设计:
主框架上方包含三个按钮,分别是“系统管理”、“图书信息管理”和“图书流通管理”,定义JMenuBar类的对象、JMenu类的对象和JMenuItem类的对象,分别表示菜单栏、菜单组和菜单选项,然后调用初始化函数,将不同类的对象通过setText()函数设定不同的文本,然后将其添加到窗口容器中。对每个按钮分别添加不同的消息监听,响应相应的消息,调用不同的类完成不同的功能。消息监听功能详见源代码bookMain类。
删除图书信息模块:
调用bookDel类的构造函数产生一个该类的对象,在初始化函数中显示信息输入对话框,提示用户输入要删除图书的ID。完成输入后,点击确定按钮,消息监听模块将调用bookBean的构造函数产生一个该类的对象,通过该对象调用bookBean的bookDel函数,执行删除的SQL语句,通过delete语句完成图书信息的删除功能。
图书管理系统源码(java实现)
【图书管理系统】【MainPro包】1.系统登录页面public class Login extends Frame {private static final long serialVersionUID = -1758475247807861408L;TextField text_user;TextField text_pass;public Login() {1 this.setTitle("登录");this.setLayout(null);//默认流式布局this.setSize(260, 170);/* 定义标签与文本框*/Label lbUser = new Label("用户名:");text_user = new TextField();Label lbPass = new Label("密码:");text_pass = new TextField();Button btn_ok = new Button("确定");Button btn_cancel = new Button("取消");lbUser.setBounds(40, 53, 60, 20);//x,y,width,heightlbPass.setBounds(40, 83, 60, 20);text_user.setBounds(100, 50, 120, 20);text_pass.setBounds(100, 80, 120, 20);btn_ok.setBounds(45, 120, 80, 25); // 确定按钮btn_cancel.setBounds(135, 120, 80, 25); // 取消按钮/* 添加标签与文本框*/add(lbUser);add(lbPass);add(text_user);add(text_pass);add(btn_ok);add(btn_cancel);setLocationRelativeTo(null); // 使窗体在屏幕上居中放置this.setVisible(true); // 使窗体可见btn_ok.addActionListener((new ActionListener() {public void actionPerformed(ActionEvent e) {btn_okActionPerformed(e);//自定义确定按钮触发的实施过程}}));btn_cancel.addActionListener((new ActionListener() {public void actionPerformed(ActionEvent e) {DbOp.Close(); // 关闭数据库System.exit(0);}}));this.addWindowListener(new WindowAdapter() {/* 关闭窗口*/// 重写windowClosing()方法public void windowClosing(WindowEvent e) {DbOp.Close(); // 关闭数据库System.exit(0);} }); }public void btn_okActionPerformed(ActionEvent e) {String user = text_user.getText();String pass = text_pass.getText();String is_admin;// 如果用户名或密码任一为空,则终止后续操作if (user.equals("")||pass.equals("")) {JOptionPane.showMessageDialog(null, "用户名或密码不能为空!");return;}try {// 核对用户名和密码String sql = "select * from user where username=" + "'" + user + "' and password=" + "'" + pass + "'";ResultSet rs = DbOp.executeQuery(sql);// 如果此用户存在,则记录其状态(否:不是管理员,是:是管理员)if (rs.next()) {is_admin = rs.getString("is_admin");} else {JOptionPane.showMessageDialog(null, "用户名或密码不正确!");return;}GlobalVar.login_user = user; // 记录登录的用户名ShowMain show = new ShowMain(); // 调用主程序// 只有管理员才能使用"基础管理"和"借阅管理"菜单show.setRights(is_admin);// 释放窗体及其全部组件的屏幕资源,即使释放登录窗体dispose(); // 释放当前窗体} catch (SQLException e1) {JOptionPane.showMessageDialog(null, "用户数据库有误!");}}}2.系统首页页面public class ShowMain extends Frame {private static final long serialVersionUID = 5003296786441785470L;MenuBar menuBar;Menu jcwh, jcwh_book, jcwh_reader;//基础维护:图书维护、读者维护Menu jywh, cxgl, xtgl;//借阅维护、查询管理、系统管理MenuItemjcwh_book_add,jcwh_book_update,jcwh_book_delete,jcwh_reader_add,jcwh_reader_update,jcwh_reader_delete;MenuItem jywh_borrow, jywh_back;MenuItem cxgl_book, cxgl_reader;MenuItem xtgl_update_pass, xtgl_exit;public void setRights(String rights) {// 如果不是管理员,则禁止用户维护图书信息和读者信息以及禁止进行借阅管理,即只能查询if (rights.equals("否")) {jywh.setEnabled(false);jcwh.setEnabled(false);}}public ShowMain() {setTitle("图书管理系统");setLayout(new BorderLayout());setSize(640, 480);menuBar = new MenuBar();jcwh = new Menu("基础维护");// 基础维护菜单jcwh_book = new Menu("图书维护");// 图书维护菜单jcwh_book_add = new MenuItem("添加");// 添加图书菜单jcwh_book_update = new MenuItem("修改");// 修改图书菜单jcwh_book_delete = new MenuItem("删除");// 删除图书菜单jcwh_reader = new Menu("读者维护");// 读者维护菜单jcwh_reader_add = new MenuItem("添加读者");// 添加读者菜单jcwh_reader_update = new MenuItem("修改读者");jcwh_reader_delete = new MenuItem("删除读者");jywh = new Menu("借阅管理");jywh_borrow = new MenuItem("借书管理");jywh_back = new MenuItem("还书管理");cxgl = new Menu("查询管理");cxgl_book = new MenuItem("图书查询");cxgl_reader = new MenuItem("读者查询");xtgl = new Menu("系统管理");xtgl_update_pass = new MenuItem("修改密码");xtgl_exit = new MenuItem("退出系统");// 添加图书菜单jcwh_book.add(jcwh_book_add);jcwh_book.add(jcwh_book_update);jcwh_book.add(jcwh_book_delete);jcwh.add(jcwh_book);jcwh_reader.add(jcwh_reader_add);jcwh_reader.add(jcwh_reader_update);jcwh_reader.add(jcwh_reader_delete);jcwh.add(jcwh_reader);jywh.add(jywh_borrow);jywh.add(jywh_back);cxgl.add(cxgl_book);cxgl.add(cxgl_reader);xtgl.add(xtgl_update_pass);xtgl.add(xtgl_exit);menuBar.add(jcwh);menuBar.add(jywh);menuBar.add(cxgl);menuBar.add(xtgl);setMenuBar(menuBar);setLocationRelativeTo(null); // 使窗体在屏幕上居中放置setVisible(true); // 使窗体可见jcwh_book_add.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {new BookManeger("save");} });jcwh_book_update.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {new BookManeger("update");} });jcwh_book_delete.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {new BookManeger("delete");} });jcwh_reader_add.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {new ReaderManeger("save");} });jcwh_reader_update.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {new ReaderManeger("update");} });jcwh_reader_delete.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {new ReaderManeger("delete");} });jywh_borrow.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {new Borrow();} });jywh_back.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {new Back();} });cxgl_book.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {new BookQuery();} });cxgl_reader.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {new ReaderQuery();} });xtgl_update_pass.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {new UpdatePassword();} });xtgl_exit.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {DbOp.Close(); // 关闭数据库System.exit(0);}});this.addWindowListener(new WindowAdapter() {/* 关闭窗口*/// 重写windowClosing()方法public void windowClosing(WindowEvent e) {DbOp.Close(); // 关闭数据库System.exit(0);}});}}3.图书管理public class BookManeger extends JFrame {private static final long serialVersionUID = 377287301994613384L;private Label lbbookid_c = new Label("图书编号");private TextField tf_bookid_c = new TextField();private Label lbbookid = new Label("图书编号");private TextField tf_bookid = new TextField();private Label lbbookname = new Label("图书名称");private TextField tf_bookname = new TextField();private Label lbbooktype = new Label("图书类别");private Choice tf_booktype = new Choice();private Label lbauthor = new Label("作者");private TextField tf_author = new TextField();private Label lbtranslator = new Label("译者");private TextField tf_translator = new TextField();private Label lbpublisher = new Label("出版社");private TextField tf_publisher = new TextField();private Label lbpublish_time = new Label("出版时间");private TextField tf_publish_time = new TextField();private Label lbprice = new Label("定价");private TextField tf_price = new TextField();private Label lbstock = new Label("库存数量");private TextField tf_stock = new TextField();private Button queryBtn = new Button("查询");private Button saveBtn = new Button("保存");private Button closeBtn = new Button("关闭");private String optionStr;BookManeger(String str) {optionStr = str;ggFrame(optionStr);saveBtn.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {HashMap<String, Object> map = new HashMap<String, Object>();map.put("bookid", tf_bookid);map.put("bookname", tf_bookname);map.put("booktype", tf_booktype);map.put("author", tf_author);map.put("translator", tf_translator);map.put("publisher", tf_publisher);map.put("publish_time", tf_publish_time);map.put("price", tf_price);map.put("stock", tf_stock);int i ;if(optionStr.equals("delete")){i = Jcwh.btn_delActionPerformed(e, map);}else{i = Jcwh.btn_saveActionPerformed(e, map,optionStr);}if (i == 1) {String showInfo = "";if(optionStr.equals("save")){showInfo = "图书添加成功!";}else if(optionStr.equals("update")){showInfo = "图书修改成功!";}else if(optionStr.equals("delete")){showInfo = "图书删除成功!";}JOptionPane.showMessageDialog(null, showInfo);// 清空全部文本框clearAllTextfield();}}});closeBtn.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {dispose(); // 释放当前窗体}});/* 关闭窗口*/this.addWindowListener(new WindowAdapter() {public void windowClosing(WindowEvent e) { // 关闭当前窗口dispose(); // 释放当前窗体}});}private void ggFrame(String str) {setLayout(null);setSize(500, 320);lbbookid.setBounds(50, 40, 50, 20); // 图书编号tf_bookid.setBounds(110, 40, 100, 20);lbbookname.setBounds(240, 40, 50, 20); // 图书名称tf_bookname.setBounds(300, 40, 100, 20);lbbooktype.setBounds(50, 80, 50, 20); // 图书类别tf_booktype.setBounds(110, 80, 100, 20);tf_booktype.add("科技");tf_booktype.add("文学");tf_booktype.add("社科");tf_booktype.add("其他");lbauthor.setBounds(240, 80, 50, 20); // 作者tf_author.setBounds(300, 80, 100, 20);lbtranslator.setBounds(50, 120, 50, 20); // 设置译者tf_translator.setBounds(110, 120, 100, 20);lbpublisher.setBounds(240, 120, 50, 20); // 出版社tf_publisher.setBounds(300, 120, 100, 20);lbpublish_time.setBounds(50, 160, 50, 20); // 出版时间tf_publish_time.setBounds(110, 160, 100, 20);lbprice.setBounds(240, 160, 50, 20); // 定价tf_price.setBounds(300, 160, 100, 20);lbstock.setBounds(50, 200, 50, 20); // 库存数量tf_stock.setBounds(110, 200, 100, 20);saveBtn.setBounds(150, 240, 80, 25); // 保存按钮closeBtn.setBounds(280, 240, 80, 25);// 关闭按钮if(str.equals("save")){setTitle("添加图书");}else if(str.equals("update")){setTitle("修改图书");lbbookid_c.setBounds(100, 10, 50, 20); // 图书编号tf_bookid_c.setBounds(160, 10, 100, 20);tf_bookid.setEditable(false);//修改的图书信息中id不可以修改queryBtn.setBounds(280, 10, 80, 20); // 查询按钮add(lbbookid_c);add(tf_bookid_c);add(queryBtn);queryBtn.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {HashMap<String, Object> map = new HashMap<String, Object>();map.put("bookid", tf_bookid_c);Book book = (Book)Jcwh.btn_queryActionPerformed(e,map).get("book");if(book!=null){tf_bookid.setText(book.getId());tf_bookname.setText(book.getBookname());// 将Choice的选定项设置为其名称等于指定字符串的项tf_booktype.select(book.getBooktype());tf_author.setText(book.getAuthor());tf_translator.setText(book.getTranslator());tf_publisher.setText(book.getPublisher());tf_publish_time.setText(book.getPublish_time().toString());tf_price.setText(String.valueOf(book.getPrice()));tf_stock.setText(String.valueOf(book.getStock()));}}});saveBtn.setLabel("修改");//将按钮显示文字修改成“修改”}else if(str.equals("delete")){setTitle("删除图书");lbbookid_c.setBounds(100, 10, 50, 20); // 图书编号tf_bookid_c.setBounds(160, 10, 100, 20);tf_bookid.setEditable(false);//修改的图书信息中id不可以修改queryBtn.setBounds(280, 10, 80, 20); // 查询按钮add(lbbookid_c);add(tf_bookid_c);add(queryBtn);queryBtn.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {HashMap<String, Object> map = new HashMap<String, Object>();map.put("bookid", tf_bookid_c);Book book = (Book)Jcwh.btn_queryActionPerformed(e,map).get("book");if(book!=null){tf_bookid.setText(book.getId());tf_bookname.setText(book.getBookname());// 将Choice的选定项设置为其名称等于指定字符串的项tf_booktype.select(book.getBooktype());tf_author.setText(book.getAuthor());tf_translator.setText(book.getTranslator());tf_publisher.setText(book.getPublisher());tf_publish_time.setText(book.getPublish_time().toString());tf_price.setText(String.valueOf(book.getPrice()));tf_stock.setText(String.valueOf(book.getStock()));}}});saveBtn.setLabel("删除");//将按钮显示文字修改成“删除”}add(lbbookid);add(tf_bookid);add(lbbookname);add(tf_bookname);add(lbbooktype);add(tf_booktype);add(lbauthor);add(tf_author);add(lbtranslator);add(tf_translator);add(lbpublisher);add(tf_publisher);add(lbpublish_time);add(tf_publish_time);add(lbprice);add(tf_price);add(lbstock);add(tf_stock);add(saveBtn);add(closeBtn);setLocationRelativeTo(null); // 使窗体在屏幕上居中放置setVisible(true); // 使窗体可见}private void clearAllTextfield() {tf_bookid.setText("");tf_bookname.setText("");tf_author.setText("");tf_translator.setText("");tf_publisher.setText("");tf_publish_time.setText("");tf_price.setText("");tf_stock.setText("");}}4.读者管理public class ReaderManeger extends JFrame {private static final long serialVersionUID = -2399939451497711745L;Label lbreaderid_c = new Label("读者编号");TextField tf_readerid_c = new TextField();Label lbreaderid = new Label("读者编号");TextField tf_readerid = new TextField();Label lbreadername = new Label("读者姓名");TextField tf_readername = new TextField();Label lbreadertype = new Label("读者类别");Choice tf_readertype = new Choice();Label lbsex = new Label("性别");Choice tf_sex = new Choice();Label lbmax_num = new Label("可借数量");TextField tf_max_num = new TextField();Label lbdays_num = new Label("可借天数");TextField tf_days_num = new TextField();Button queryBtn = new Button("查询");Button saveBtn = new Button("保存");Button closeBtn = new Button("关闭");private String optionStr;//保存、修改、删除ReaderManeger(String str){optionStr = str;ggFrame(optionStr);saveBtn.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {HashMap<String, Object> map = new HashMap<String, Object>();map.put("readerid", tf_readerid);map.put("readername", tf_readername);map.put("readertype", tf_readertype);map.put("sex", tf_sex);map.put("days_num", tf_days_num);map.put("max_num", tf_max_num);int i ;if(optionStr.equals("delete")){i = Jcwh.btn_delReaderActionPerformed(e, map);}else{i = Jcwh.btn_saveReaderActionPerformed(e,map,optionStr);}if (i == 1) {String showInfo = "";if(optionStr.equals("save")){showInfo = "读者添加成功!";}else if(optionStr.equals("update")){showInfo = "读者修改成功!";}else if(optionStr.equals("delete")){showInfo = "读者删除成功!";}JOptionPane.showMessageDialog(null, showInfo);// 清空全部文本框clearAllTextfield();}}});closeBtn.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {dispose(); // 释放当前窗体}});this.addWindowListener(new WindowAdapter() {public void windowClosing(WindowEvent e) { // 关闭当前窗口dispose(); // 释放当前窗体}});}private void ggFrame(String str) {setLayout(null);setTitle("添加读者信息");setSize(500, 230);lbreaderid.setBounds(50, 50, 50, 20);tf_readerid.setBounds(110, 50, 100, 20);lbreadername.setBounds(240, 50, 50, 20);tf_readername.setBounds(300, 50, 100, 20);lbreadertype.setBounds(50, 80, 50, 20);tf_readertype.setBounds(110, 80, 100, 20);tf_readertype.add("教师");tf_readertype.add("学生");tf_readertype.add("职工");lbsex.setBounds(240, 80, 50, 20);tf_sex.setBounds(300, 80, 100, 20);tf_sex.add("男");tf_sex.add("女");lbmax_num.setBounds(50, 110, 50, 20);tf_max_num.setBounds(110, 110, 100, 20);lbdays_num.setBounds(240, 110, 50, 20);tf_days_num.setBounds(300, 110, 100, 20);saveBtn.setBounds(150, 150, 80, 25);closeBtn.setBounds(280, 150, 80, 25);if(str.equals("save")){setTitle("添加读者");}else if(str.equals("update")){setTitle("修改读者");lbreaderid_c.setBounds(100, 10, 50, 20);tf_readerid_c.setBounds(160, 10, 100, 20);tf_readerid.setEditable(false);queryBtn.setBounds(280, 10, 80, 20);add(lbreaderid_c);add(tf_readerid_c);add(queryBtn);queryBtn.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {HashMap<String, Object> map = new HashMap<String, Object>();map.put("readerid", tf_readerid_c);Reader reader = (Reader)Jcwh.btn_queryReaderActionPerformed(e,map).get("reader");if(reader!=null){tf_readerid.setText(reader.getId());tf_readername.setText(reader.getReadername());tf_readertype.select(reader.getReadertype());tf_sex.select(reader.getSex());tf_days_num.setText(String.valueOf(reader.getDays_num()));tf_max_num.setText(String.valueOf(reader.getMax_num()));}}});saveBtn.setLabel("修改");//将按钮显示文字修改成“修改”}else if(str.equals("delete")){setTitle("删除图书");lbreaderid_c.setBounds(100, 10, 50, 20);tf_readerid_c.setBounds(160, 10, 100, 20);tf_readerid.setEditable(false);queryBtn.setBounds(280, 10, 80, 20);add(lbreaderid_c);add(tf_readerid_c);add(queryBtn);queryBtn.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {HashMap<String, Object> map = new HashMap<String, Object>();map.put("readerid", tf_readerid_c);Reader reader = (Reader)Jcwh.btn_queryReaderActionPerformed(e,map).get("reader");if(reader!=null){tf_readerid.setText(reader.getId());tf_readername.setText(reader.getReadername());tf_readertype.select(reader.getReadertype());tf_sex.select(reader.getSex());tf_days_num.setText(String.valueOf(reader.getDays_num()));tf_max_num.setText(String.valueOf(reader.getMax_num()));}}});saveBtn.setLabel("删除");//将按钮显示文字修改成“删除”}add(lbreaderid);add(lbreadername);add(lbreadertype);add(lbsex);add(lbmax_num);add(lbdays_num);add(tf_readerid);add(tf_readername);add(tf_max_num);add(tf_days_num);add(tf_readertype);add(tf_sex);add(saveBtn);add(closeBtn);setLocationRelativeTo(null);setVisible(true);}private void clearAllTextfield() {tf_readerid.setText("");tf_readername.setText("");tf_max_num.setText("");tf_days_num.setText("");}public static void main(String[] args) {ReaderManeger r = new ReaderManeger("update");}}5.借书public class Borrow extends Frame {private static final long serialVersionUID = -1036076990599464079L;String SepLine = "-------------------------------------------------";Label lbbookid = new Label("图书编号");Label lbreaderid = new Label("读者编号");TextField tf_bookid = new TextField();TextField tf_readerid = new TextField();Button queryBtn = new Button("查询");Label lbbookinfo = new Label(SepLine + "图书信息" + SepLine); Label lbbookname = new Label("图书名称:");Label tf_bookname = new Label("xx");Label lbauthor = new Label("作者:");Label tf_author = new Label("xx");Label lbpublisher = new Label("出版社:");Label tf_publisher = new Label("xx");Label lbpublish_time = new Label("出版时间:");Label tf_publish_time = new Label("xx");Label lbprice = new Label("定价:");Label tf_price = new Label("xx");Label lbstock = new Label("库存数量:");Label tf_stock = new Label("xx");Label lbreaderinfo = new Label(SepLine + "读者信息" + SepLine); Label lbreadername = new Label("读者姓名:");Label tf_readername = new Label("xx");Label lbreadertype = new Label("读者类型:");Label tf_readertype = new Label("xx");Label lbmax_num = new Label("最大可借数:");Label tf_max_num = new Label("xx");Label lbdays_num = new Label("最大可借天数:");Label tf_days_num = new Label("xx");Label lbborrowinfo = new Label(SepLine + "借阅信息" + SepLine); Label lbborrowednum = new Label("该读者已借图书数量:"); Label tf_borrowednum = new Label("xx");Label lbif_borrow = new Label("该读者是否可借所选图书:"); Label tf_if_borrow = new Label("xx");Label lbborrow_date = new Label("借阅日期:");Label tf_borrow_date = new Label("xx");Button borrowBtn = new Button("借出");Button closeBtn = new Button("关闭");public Borrow() {setLayout(null);setTitle("借阅图书");setSize(500, 420);this.setForeground(Color.BLACK); // 设置前景色为黑色lbbookid.setBounds(30, 40, 50, 25); // 图书编号tf_bookid.setBounds(90, 40, 90, 20);lbreaderid.setBounds(200, 40, 50, 25); // 读者编号tf_readerid.setBounds(260, 40, 90, 20);queryBtn.setBounds(370, 40, 80, 25); // 查询按钮lbbookinfo.setBounds(30, 70, 440, 25); // 图书信息提示条lbbookname.setBounds(30, 100, 60, 25); // 图书名称tf_bookname.setBounds(90, 100, 200, 25);lbauthor.setBounds(310, 100, 60, 25); // 作者tf_author.setBounds(370, 100, 90, 25);lbpublisher.setBounds(30, 125, 60, 25); // 出版社tf_publisher.setBounds(90, 125, 200, 25);lbpublish_time.setBounds(310, 125, 60, 25); // 出版时间tf_publish_time.setBounds(370, 125, 90, 25);lbprice.setBounds(30, 150, 60, 25); // 定价tf_price.setBounds(90, 150, 200, 25);lbstock.setBounds(310, 150, 60, 25); // 库存数量tf_stock.setBounds(370, 150, 90, 25);lbreaderinfo.setBounds(30, 180, 440, 25); // 读者信息提示条lbreadername.setBounds(30, 205, 60, 25); // 读者姓名tf_readername.setBounds(90, 205, 90, 25);lbreadertype.setBounds(310, 205, 60, 25); // 读者类型tf_readertype.setBounds(370, 205, 90, 25);lbmax_num.setBounds(30, 230, 75, 25); // 最大可借数tf_max_num.setBounds(105, 230, 90, 25);lbdays_num.setBounds(310, 230, 85, 25); // 最大可借天数tf_days_num.setBounds(395, 230, 70, 25);lbborrowinfo.setBounds(30, 260, 440, 25); // 借阅信息提示条lbborrowednum.setBounds(30, 285, 120, 25);// 已借图书数量tf_borrowednum.setBounds(150, 285, 50, 25);lbif_borrow.setBounds(30, 310, 145, 25); // 是否可借tf_if_borrow.setBounds(175, 310, 50, 25);lbborrow_date.setBounds(30, 335, 60, 25);// 借书日期tf_borrow_date.setBounds(90, 335, 100, 25);borrowBtn.setBounds(160, 365, 80, 25);// 借出按钮borrowBtn.setEnabled(false); // 开始时禁用借出按钮closeBtn.setBounds(260, 365, 80, 25);// 关闭按钮queryBtn.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) { btn_querywActionPerformed(e); } }); borrowBtn.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) { btn_borrowActionPerformed(e); } });closeBtn.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) { setForeground(Color.BLACK); dispose(); } }); this.addWindowListener(new WindowAdapter() {public void windowClosing(WindowEvent e) {setForeground(Color.BLACK); // 设置前景色为黑色dispose(); // 关闭窗体}});add(lbbookid);add(lbreaderid);add(queryBtn);add(lbbookinfo);add(lbbookname);add(lbauthor);add(lbpublisher);add(lbpublish_time);add(lbprice);add(lbstock);add(lbreaderinfo);add(lbreadername);add(lbreadertype);add(lbmax_num);add(lbdays_num);add(lbborrowinfo);add(lbborrowednum);add(lbif_borrow);add(lbborrow_date);add(borrowBtn);add(closeBtn);setLocationRelativeTo(null); // 使窗体在屏幕上居中放置setVisible(true); // 使窗体可见setForeground(Color.RED); // 设置前景色为红色add(tf_bookid);add(tf_readerid);add(tf_bookname);add(tf_author);add(tf_publisher);add(tf_publish_time);add(tf_price);add(tf_stock);add(tf_readername);add(tf_readertype);add(tf_max_num);add(tf_days_num);add(tf_borrowednum);add(tf_if_borrow);add(tf_borrow_date);}// 图书和读者查询private void btn_querywActionPerformed(ActionEvent e) {String bookid = tf_bookid.getText();String readerid = tf_readerid.getText();// 如果图书编号或读者编号两者均为空,或者有一个为空,则返回if (bookid.equals("") || readerid.equals("")) {JOptionPane.showMessageDialog(null, "图书编号和读者编号均不能为空!");init(); // 重新初始化各参数并禁止借出按钮return;}// 按编号查询图书,结果存入book对象中Book book = BookSelect.SelectBookById(bookid);if (book != null) { // 如果查询到结果,将其显示在各文本框中tf_bookname.setText(book.getBookname());tf_author.setText(book.getAuthor());tf_publisher.setText(book.getPublisher());tf_publish_time.setText(book.getPublish_time().toString());tf_price.setText(String.valueOf((book.getPrice())));tf_stock.setText(String.valueOf(book.getStock()));} else {JOptionPane.showMessageDialog(null, "图书编号有误,查无此书!");init(); // 重新初始化各参数并禁止借出按钮return;}if (book.getStock() == 0) {JOptionPane.showMessageDialog(null, "图书已无库存,无法借阅!");init(); // 重新初始化各参数并禁止借出按钮return;}// 按编号查询读者,结果存入reader对象中Reader reader = ReaderSelect.selectReaderById(readerid);// 如果查询到结果,将其显示在各文本框中if (reader != null) {tf_readername.setText(reader.getReadername());tf_readertype.setText(reader.getReadertype());tf_max_num.setText(String.valueOf(reader.getMax_num()));tf_days_num.setText(String.valueOf(reader.getDays_num()));} else {JOptionPane.showMessageDialog(null, "读者编号有误,查无此人!");init(); // 重新初始化各参数并禁止借出按钮return;}// 查询指定读者是否已借过指定图书且未归还if (IfBorrowBack.findbook(bookid, readerid)) {JOptionPane.showMessageDialog(null, "该读者已借阅所选图书,且未归还!");init(); // 重新初始化各参数并禁止借出按钮return;}// 统计读者所借图书数量int borrowednum = statborrowednum(readerid);tf_borrowednum.setText(String.valueOf(borrowednum));// 如果读者已借图书尚未超出其允许最大借书量,则允许其继续借阅所选图书if (borrowednum < reader.getMax_num()) {tf_if_borrow.setText("是");// 创建一个简单日期格式对象,注意:MM一定要用大写SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");// 创建日期变量,其内容为当前日期Date currentdate = new Date();// 将日期按指定格式输出String borrowdate = sdf.format(currentdate);tf_borrow_date.setText(borrowdate);borrowBtn.setEnabled(true); // 使借出按钮有效} else {JOptionPane.showMessageDialog(null, "该读者借书过多,无法继续借阅!");init(); // 重新初始化各参数并禁止借出按钮return;}}// 填写借出图书记录private void btn_borrowActionPerformed(ActionEvent e) {String sql;String bookid = tf_bookid.getText();String readerid = tf_readerid.getText();String borrowdate = tf_borrow_date.getText();// 为borrow表增加借书记录sql = "insert into borrow (book_id,reader_id,"+ "borrow_date,if_back) values('" + bookid + "','" + readerid + "','" + borrowdate + "','否')";。
java图书管理系统代码版
目录第1章本设计所要达到的目的和要求 1.1 设计目的1.2 设计要求第2章设计内容第3 章开发和运行环境介绍第4章需求分析1、本设计所要达到的目的和要求1.1 设计目的管理信息系统(MIS)的应用已深入到社会的各行各业,它是信息、软件与科学管理相结合的产物。
MIS的开发过程不仅是一个编写应用程序的过程,而且是一个以软件工程的思想为指导,从可行性研究开始,经过系统分析、系统设计、系统实施到等主要阶段的规范开发过程。
本题目实现的是JAVA系统,我们选择的是图书馆管理系统,不同角色的用户登录,用户信息的管理包括密码管理,及用户借还书,用户对图书信息及本人借还情况的查询,超级管理员对图书信息的增删查改,用户信息的增删查改及借还情况总的查询。
1.2 设计要求1、主题明确,软体开发要有创新性,能体现SQL的存储过程、触发器、游标技术等;2、用高级语言结合SQL Server数据库进行开发;3、写出数据库关系模式及相应的数据库表关系图;4、绘制成绩MIS相应的系统流程图、E-R图等;5、完成成绩MIS登陆界面、主界面、图书信息录入、图书信息查询和其各项设计与操作。
2、设计内容我们设计的图书馆管理系统主要用于对图书馆日常工作的管理,主要任务是用计算机对读者、图书等各种信息进行日常管理,如查询、修改、增加、删除、图书借阅和归还的管理等。
本系统实现了图书馆的信息化管理,完成了图书馆管理系统的基本功能。
该系统主要包括读者用户登录系统、管理员用户登入系统、图书管理系统、图书借阅、图书和用户信息查询子系统四个部分,各部分主要功能如下:读者用户登录子系统:用于数据库的连接,主界面的设计和读者身份用户的登录管理。
管理员用户登入系统:用于管理员用户的管理,如图书添加、图书信息修改。
图书管理系统:用于图书信息的管理,如新书入库、图书信息修改、图书信息删除。
图书借阅系统:用于用户借阅和归还图书。
图书和用户信息查询:图书和用户信息的查询。
图书借阅管理系统java代码
以我给的标题写原创文档,最低1200字,要求以Markdown文本格式输出,不要带图片和AI、人工智能、Markdown、GPT等关键词,标题为:图书借阅管理系统java代码# 图书借阅管理系统Java代码## 一、介绍图书借阅管理系统是一个帮助图书馆管理图书借阅情况的系统。
本系统基于Java开发,采用面向对象的编程方式,实现了对图书信息、借阅记录等数据的管理与处理。
用户可以通过该系统查询图书信息、借阅图书、归还图书,并实现了管理员对系统的管理功能。
## 二、功能模块### 1. 图书管理模块- 实现对图书信息的添加、删除、修改和查询功能。
- 对图书的分类管理,方便用户按照分类查找图书信息。
### 2. 用户管理模块- 用户注册与登录功能,保证用户数据的安全。
- 用户查询借阅情况、借阅历史等个人信息。
### 3. 借阅管理模块- 实现图书的借阅功能,包括借书日期、归还日期等信息的记录。
- 用户借阅超时提醒,确保图书及时归还。
### 4. 管理员模块- 管理员登录后可以对图书信息、用户信息进行管理。
- 实现图书归还、逾期处理等功能。
## 三、系统架构本系统采用MVC(Model-View-Controller)架构,实现了模型层、视图层、控制层之间的分离,提高了系统的灵活性和可维护性。
具体架构如下:1. Model层:负责处理数据的逻辑操作,包括对图书信息、用户信息、借阅记录等数据的管理。
2. View层:负责系统的界面展示,包括用户界面和管理员界面。
3. Controller层:负责处理用户请求,调用Model层的方法,并将结果返回给View层进行展示。
## 四、代码示例以下是借阅图书的Java代码示例:```javapublic class BorrowBook {private Book book;private User user;private Date borrowDate;private Date returnDate;// Constructorpublic BorrowBook(Book book, User user, Date borrowDate, Date returnDate) {this.book = book;er = user;this.borrowDate = borrowDate;this.returnDate = returnDate;}// Getters and setters}```以上代码实现了一个借阅图书的类`BorrowBook`,包含了借阅的图书信息、用户信息,借阅时间和归还时间。
用java做的一个图书管理系统的源代码
用java做的一个图书管理系统的源代码import java.sql.*;import java.util.*;public class T{public static void main(String[] args) throws Exception{Connection conn=null;Statement stmt=null;ResultSet rs=null;while(true){Scanner scanner=new Scanner(System.in);System.out.println("请输入用户名:");String username2=scanner.next();System.out.println("请输入密码:");String password2=scanner.next();if(!(username2.equals("")||password2.equals(""))){try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");conn=DriverManager.getConnection("jdbc:odbc:book","","");String sql="select * from ww where username='"+username2+"'";stmt=conn.createStatement();rs=stmt.executeQuery(sql);if(rs.next()){if(rs.getString("password").equals(password2)){System.out.println("*********欢迎来山东科技大学图书馆管理系统********");while(true){System.out.println(" 1.图书信息");System.out.println(" 2.读者信息");System.out.println(" 3.管理员信息");System.out.println(" 4.借阅信息");System.out.println(" 5.还书信息");System.out.println(" 6.逾期罚款或损坏赔偿信息");//System.out.println(" 7.退出");System.out.println(" 请输入选择功能的序号:");int a=scanner.nextInt();switch(a){case 1:System.out.println(" 图书信息: ");System.out.println(" 1. 查询图书信息: ");System.out.println(" 2. 插入图书信息: ");System.out.println(" 3. 删除图书信息: ");System.out.println(" 4. 修改图书信息: ");int a1=scanner.nextInt();switch(a1){case 1:System.out.println(" 欢迎进入图书信息查询系统: ");System.out.println(" 1. 无条件查询图书信息: ");System.out.println(" 2. 条件查询图书信息: ");int d=scanner.nextInt();switch(d){case 1:int llll=0;//int mm=0;while(llll!=1){System.out.println(" 1. 无条件查询图书信息: ");String Sql0 = "SELECT * FROM systembook ";rs= stmt.executeQuery(Sql0);while(rs.next()){String bookID =rs.getString(1);String bookNo =rs.getString(2);String bookName =rs.getString(3);String bookWriter =rs.getString(4);String bookPub =rs.getString(5);System.out.println(bookID+","+bookNo+","+bookName+","+ bookWriter+","+bookPub);}System.out.println("是否继续插入?yes/no no返回主菜单");String k=scanner.next();if(k.startsWith("yes")){System.out.println();};if(k.startsWith("no")){llll=1;System.out.println();};}break;//break;case 2:System.out.println(" 2. 条件查询图书信息: ");System.out.println(" 1. 单条件查询图书信息: ");System.out.println(" 2. 模糊条件查询图书信息: ");System.out.println(" 3. 多表连接查询图书信息: ");System.out.println(" 4. 嵌套查询图书信息: ");System.out.println(" 5. 谓词演算查询");int c12=scanner.nextInt();switch(c12){case 1:System.out.println(" 1.单条件查询: ");System.out.println(" 1.按图书名编码号查询图书信息: ");int ddd=0;while(ddd!=1){System.out.println("请输入图书编码号:");String A=scanner.next();String sql1= "SELECT * FROM systembook WHERE bookID ='"+A+"' ";rs= stmt.executeQuery(sql1);int x=0;while(rs.next()){String a2 =rs.getString(1);String b2 =rs.getString(2);String c2 =rs.getString(3);String d2 =rs.getString(4);String e2 =rs.getString(5);System.out.println(a2+","+b2+" ,"+c2+","+d2+","+e2);x++;}if(x==0){System.out.println("查无此书,请重新输入");}else{System.out.println("是否继续按姓名查询?yes/no no返回主菜单");String k=scanner.next();if(k.startsWith("yes")){System.out.println();};if(k.startsWith("no")){ddd=1;System.out.println();};};}break;case 2:System.out.println(" 2.模糊查询图书信息: ");int dc=0;while(dc!=1){System.out.println("请用户输入图书名字中的模糊关键字");String E=scanner.next();String sq123= "SELECT * FROM systembook WHERE bookName LIKE'"+E+"%'";rs= stmt.executeQuery(sq123);int z=0;while(rs.next()){String a2 =rs.getString(1);String b2 =rs.getString(2);String c2 =rs.getString(3);String d2 =rs.getString(4);String e2 =rs.getString(5);System.out.println(a2+","+b2+" ,"+c2+","+d2+","+e2);z++;}if(z==0){System.out.println("查无此书,请重新输入");}else{System.out.println("是否继续输入图书名字中的模糊关键字?yes/no no返回主菜单");String k=scanner.next();if(k.startsWith("yes")){System.out.println();};if(k.startsWith("no")){dc=1;System.out.println();// break;};}}break;case 3:System.out.println(" 3.多表连接查询查询图书信息: ");int dq=0;while(dq!=1){System.out.println("查询逾期罚款或是赔偿表中的读者的相关信息");System.out.println("请输入逾期罚款或是赔偿的读者编码号");String F=scanner.next();String sq1234= "SELECT * FROM fine,borrowbook,systemreader WHERE fine.bookID=borrowbook.bookID AND borrowbook.reaID=systemreader.reaID AND fine.bookID='"+F+"' ";rs= stmt.executeQuery(sq1234);int n=0;while(rs.next()){String a2 =rs.getString(1);String b2 =rs.getString(2);String c2 =rs.getString(3);String d2 =rs.getString(4);String e2 =rs.getString(5);System.out.println(a2+","+b2+" ,"+c2+","+d2+","+e2);n++;}if(n==0){System.out.println("查无此人,请重新输入");}else{System.out.println("是否继续输入图书名字中的模糊关键字?yes/no no返回主菜单");String k=scanner.next();if(k.startsWith("yes")){System.out.println();};if(k.startsWith("no")){ddd=1;System.out.println();};}}break;case 4:System.out.println(" 4.嵌套查询图书信息: ");int dq1=0;System.out.println("查询某读者所在年级女读者的相关信息");System.out.println("请输入某读者的读者编号");String G=scanner.next();String sq12345= "SELECT * FROM systemreader WHERE reaGrade=(SELECT reaGrade FROM systemreader WHERE reaID='"+G+"') AND reasex='女'";rs= stmt.executeQuery(sq12345);int m=0;while(rs.next()){String a2 =rs.getString(1);String b2 =rs.getString(2);String c2 =rs.getString(3);String d2 =rs.getString(4);String e2 =rs.getString(5);System.out.println(a2+","+b2+" ,"+c2+","+d2+","+e2);m++;}if(m==0){System.out.println("查无此书,请重新输入");}else{System.out.println("是否继续输入读者编号?yes/no no 返回主菜单");String k=scanner.next();if(k.startsWith("yes")){System.out.println();};if(k.startsWith("no")){d=1;System.out.println();};}}break;System.out.println(" 5. 谓词演算查询:");int dq1123=0;while(dq1123!=1){System.out.println("查询借阅了某本书的读者的相关信息");System.out.println("请输入该书的名字");String H=scanner.next();String sq123456= "SELECT * FROM systemreader WHERE reaID IN (SELECT reaID FROM borrowbook WHERE bookName='"+H+"')";rs= stmt.executeQuery(sq123456);int l=0;while(rs.next()){String a2 =rs.getString(1);String b2 =rs.getString(2);String c2 =rs.getString(3);String d2 =rs.getString(4);String e2 =rs.getString(5);System.out.println(a2+","+b2+" ,"+c2+","+d2+","+e2);l++;}if(l==0){System.out.println("查无此人,请重新输入");}else{System.out.println("是否继续输入图书名字?yes/no no返回主菜单");String k=scanner.next();if(k.startsWith("yes")){System.out.println();};if(k.startsWith("no")){d=1;System.out.println();};}}break;}//c12break;}break;/*case 1:System.out.println(" 1. 查询图书信息: ");String Sql = "SELECT * FROM systembook ";rs= stmt.executeQuery(Sql);while(rs.next()){//String str =scanner.next();String bookID =rs.getString(1);String bookNo =rs.getString(2);String bookName =rs.getString(3);String bookWriter =rs.getString(4);String bookPub =rs.getString(5);System.out.println(bookID+","+bookNo+","+bookName+","+ bookWriter+","+bookPub);}break;*/case 2:int zz=0;while(zz!=1){System.out.println(" 2. 插入图书信息: ");System.out.println("请按顺序插入图书条码号,图书索书号,图书名字,图书作者,图书出版社");String str=scanner.next();String []splitst=str.split(",");String a11=splitst[0];String a12=splitst[1];String a13=splitst[2];String a14=splitst[3];String a15=splitst[4];String insertSql="INSERT INTO systembook(bookID,bookNo,bookName,bookWriter,bookPub)VALUES('"+a11+"','"+a12+"','"+a13+"','"+a14+"','"+a15+"')";int i=stmt.executeUpdate(insertSql); //返回记录影响的条数if(i!=0){System.out.println("插入成功!"); }System.out.println("是否继续插入?yes/no no返回主菜单");String k=scanner.next();if(k.startsWith("yes")){System.out.println();};if(k.startsWith("no")){zz=1;System.out.println();};}break;case 3:int ll=0;//int mm=0;while(ll!=1){System.out.println(" 3. 删除图书信息: ");System.out.println("请输入要删除的图书编号:");String Str=scanner.next();String []Splitst=Str.split(",");String b3=Splitst[0];String sql1="SELECT * FROM systembook where bookID='"+b3+"'";rs= stmt.executeQuery(sql1);int kkk=0;while(rs.next()){String a22 =rs.getString(1);String b22 =rs.getString(2);String c22 =rs.getString(3);String d22 =rs.getString(4);String e22 =rs.getString(5);String f22 =rs.getString(6);System.out.println(a22+","+b22+" ,"+c22+","+d22+","+e22+","+f22);kkk++;}if(kkk==0){System.out.println( "没有这本书,请重新输入");}else{{String deleSql= "DELETE FROM systembook WHERE bookID='"+b3+"'";int p=stmt.executeUpdate(deleSql); //返回记录影响的条数if(p!=0){System.out.println("删除成功!");}System.out.println("是否继续删除?yes/no no返回主菜单");String l=scanner.next();if(l.startsWith("yes")){System.out.println();};if(l.startsWith("no")){ll=1;System.out.println();};};}}break;case 4:int mm=0;while(mm!=1){System.out.println(" 4. 修改图书信息: ");System.out.println("请输入修改的图书ID ");String S=scanner.next();String sql1="SELECT * FROM systembook where bookID='"+S+"'";rs= stmt.executeQuery(sql1);int lll=0;while(rs.next()){String a222 =rs.getString(1);String b222 =rs.getString(2);String c222 =rs.getString(3);String d222 =rs.getString(4);String e222 =rs.getString(5);String f222 =rs.getString(6);System.out.println(a222+","+b222+" ,"+c222+","+d222+","+e222+","+f222);lll++;}if(lll==0){System.out.println( "没有这本书,请重新输入");}else{System.out.println("要将书名改为");String bbb=scanner.next();String updateSql1="UPDATE systembook SET bookName='"+bbb+"' WHERE bookID='"+S+"'";int hh=stmt.executeUpdate(updateSql1); //返回记录影响的条数if(hh!=0){System.out.println("修改成功!");}System.out.println("是否继续修改yes/no no返回主菜单");String o=scanner.next();if(o.startsWith("yes")){System.out.println();};if(o.startsWith("no")){mm=1;System.out.println();};}}break;}break;/* String updateSql="UPDATE systembook SET bookCopy='"+c1+"' WHERE bookName='数据库管理'";int t=stmt.executeUpdate(updateSql); //返回记录影响的条数if(t!=0){System.out.println("修改成功!");}break;}break;*/case 2:System.out.println(" 读者信息: ");System.out.println(" 1. 查询读者信息: ");System.out.println(" 2. 插入读者信息: ");System.out.println(" 3. 删除读者信息: ");System.out.println(" 4. 修改读者信息: " );int b1=scanner.nextInt();switch(b1){case 1:System.out.println(" 1. 查询读者信息: ");String ssql = "SELECT * FROM systemreader ";rs= stmt.executeQuery(ssql);while(rs.next()){//String str =scanner.next();String reaID=rs.getString(1);String reaName =rs.getString(2);String reaLBID =rs.getString(3);String reaNo =rs.getString(4);String reaSex =rs.getString(5);String reaType =rs.getString(6);String reaDep =rs.getString(7);String reaGrade =rs.getString(8);String reaPre =rs.getString(9);String reaDate =rs.getString(10);System.out.println(reaID+","+reaName+","+reaNo+","+reaSex+","+reaLBID+","+reaType+","+reaD ep+","+reaGrade+","+reaPre+","+reaDate);}break;case 2:int zz=0;while(zz!=1){System.out.println(" 2. 插入读者信息: ");System.out.println("请按顺序插入借书卡证号读者名字读者学号读者性别读者LBID 读者类型读者学院读者年级读者专业办证日期");String str=scanner.next();String []splitst=str.split(",");String b11=splitst[0];String b12=splitst[1];String b13=splitst[2];String b14=splitst[3];String b15=splitst[4];String b16=splitst[5];String b17=splitst[6];String b18=splitst[7];String b19=splitst[8];String b20=splitst[9];String insertSql="INSERT INTO systemreader(reaID,reaName,reaNo,reaSex,reaLBID,reaType,reaDep,reaGrade,reaPre,reaDate) VALUES('"+b11+"','"+b12+"','"+b13+"','"+b14+"','"+b15+"','"+b16+"','"+b17+"','"+b18+"','"+b19+"' ,'"+b20+"')";int n=stmt.executeUpdate(insertSql); //返回记录影响的条数if(n!=0){System.out.println("插入成功!"); }System.out.println("是否继续插入?yes/no no返回主菜单");String k=scanner.next();if(k.startsWith("yes")){System.out.println();};if(k.startsWith("no")){zz=1;System.out.println();};}break;case 3:int ll=0;while(ll!=1){System.out.println(" 3. 删除读者信息: ");System.out.println("请输入要删除的读者证号:");String Str=scanner.next();String []Splitst=Str.split(",");String r=Splitst[0];String sql1="SELECT * FROM systemreader where reaID='"+r+"'";rs= stmt.executeQuery(sql1);int kkk=0;while(rs.next()){String a22 =rs.getString(1);String b22 =rs.getString(2);String c22 =rs.getString(3);String d22 =rs.getString(4);String e22 =rs.getString(5);String f22 =rs.getString(6);String g22 =rs.getString(7);String h22 =rs.getString(8);String i22 =rs.getString(9);System.out.println(a22+","+b22+" ,"+c22+","+d22+","+e22+","+f22+","+g22+","+h22+","+i22);kkk++;}if(kkk==0){System.out.println( "没有这个读者,请重新输入");}else{//System.out.println( "您是否真的要删除? yes/no");//String k=scanner.next();//if(k.startsWith("y")){String deleSql= "DELETE FROM systemreader WHERE reaID='"+r+"'";int p=stmt.executeUpdate(deleSql); //返回记录影响的条数if(p!=0){System.out.println("删除成功!");}System.out.println("是否继续删除?yes/no no返回主菜单");String l=scanner.next();if(l.startsWith("yes")){System.out.println();};if(l.startsWith("no")){ll=1;System.out.println();};};}}/* String deleSql= "DELETE FROM systemreader WHERE reaID='"+r+"'";int m=stmt.executeUpdate(deleSql); //返回记录影响的条数if(m!=0){System.out.println("删除成功!");}*/break;case 4:int mm=0;while(mm!=1){System.out.println(" 4. 修改读者信息: ");System.out.println("请输入修改以后的读者的ID ");String S=scanner.next();// String []Ssplitst=S.split(",");//String tt=Ssplitst[0];String sql1="SELECT * FROM systemreader where reaID='"+S+"'";rs= stmt.executeQuery(sql1);int lll=0;while(rs.next()){String a222 =rs.getString(1);String b222 =rs.getString(2);String c222 =rs.getString(3);String d222 =rs.getString(4);String e222 =rs.getString(5);String f222 =rs.getString(6);String g222 =rs.getString(7);String h222 =rs.getString(8);String i222 =rs.getString(9);String j222 =rs.getString(10);System.out.println(a222+","+b222+" ,"+c222+","+d222+","+e222+","+f222+","+g222+","+h222+", "+i222+","+j222);lll++;}if(lll==0){System.out.println( "没有这个人,请重新输入");}else{System.out.println("要将名字改为");String bb=scanner.next();String updateSql="UPDATE systemreader SET reaName='"+bb+"' WHERE reaID='"+S+"'";int hh=stmt.executeUpdate(updateSql); //返回记录影响的条数if(hh!=0){System.out.println("修改成功!");}System.out.println("是否继续修改yes/no no返回主菜单");String o=scanner.next();if(o.startsWith("yes")){System.out.println();};if(o.startsWith("no")){mm=1;System.out.println();};}}break;/* String updateSql="UPDATE systemreader SET reaSex='"+tt+"' WHERE reaID='20030101'";int l=stmt.executeUpdate(updateSql); //返回记录影响的条数if(l!=0){System.out.println("修改成功!");}break;*/}break;case 3:System.out.println(" 管理员信息: ");System.out.println(" 1. 查询管理员信息: ");System.out.println(" 2. 插入管理员信息: ");System.out.println(" 3. 删除管理员信息: ");System.out.println(" 4. 修改管理员信息: ");System.out.println(" 5. 返回上一级");int c11=scanner.nextInt();switch(c11){case 1:System.out.println(" 1. 查询管理员信息: ");String Ssql = "SELECT * FROM manager ";rs= stmt.executeQuery(Ssql);while(rs.next()){// String str =scanner.next();String mID =rs.getString(1);String mName=rs.getString(2);String mSex =rs.getString(3);System.out.println(mID+","+mName+","+mSex);}break;case 2:int zz=0;while(zz!=1){System.out.println(" 2. 插入管理员信息: ");System.out.println("请按顺序插入管理员的编号,管理员的姓名,管理员的性别,所管书库,电话,地址");String str=scanner.next();String []splitst=str.split(",");String a11=splitst[0];String a12=splitst[1];String a13=splitst[2];String a14=splitst[3];String a15=splitst[4];String a16=splitst[5];String insertSql="INSERT INTO manager(mID,mName,mSex,mAuth,mTeleph,mAddre)VALUES('"+a11+"','"+a12+"','"+a13+"','"+a14+"','"+a15+"','"+a16+"')";int i=stmt.executeUpdate(insertSql); //返回记录影响的条数if(i!=0){System.out.println("插入成功!");}System.out.println("是否继续插入?yes/no no返回主菜单");String k=scanner.next();if(k.startsWith("yes")){System.out.println();};if(k.startsWith("no")){zz=1;System.out.println();};}break;case 3:int ll=0;while(ll!=1){System.out.println(" 3. 删除管理员信息: ");System.out.println("请输入要删除的管理员编号:");String Str=scanner.next();String []Splitst=Str.split(",");String b3=Splitst[0];String sql1="SELECT * FROM manager where mID='"+b3+"'";rs= stmt.executeQuery(sql1);int kkk=0;while(rs.next()){String a22 =rs.getString(1);String b22 =rs.getString(2);String c22 =rs.getString(3);String d22 =rs.getString(4);String e22 =rs.getString(5);String f22 =rs.getString(6);System.out.println(a22+","+b22+" ,"+c22+","+d22+","+e22+","+f22);kkk++;}if(kkk==0){System.out.println( "没有这个管理员,请重新输入");}else{//System.out.println( "您是否真的要删除? yes/no");//String k=scanner.next();//if(k.startsWith("y")){String deleSql= "DELETE FROM manager WHERE mID='"+b3+"'";int p=stmt.executeUpdate(deleSql); //返回记录影响的条数if(p!=0){System.out.println("删除成功!");}System.out.println("是否继续删除?yes/no no返回主菜单");String l=scanner.next();if(l.startsWith("yes")){System.out.println();};if(l.startsWith("no")){ll=1;System.out.println();};};}}/* String deleSql= "DELETE mID FROM manager WHERE mID='"+b3+"'";int k=stmt.executeUpdate(deleSql); //返回记录影响的条数if(k!=0){System.out.println("删除成功!");}*/break;case 4:int mm=0;while(mm!=1){System.out.println(" 4. 修改管理员信息: ");System.out.println("请输入要修改的管理员编号:");String S=scanner.next();String []Ssplitst=S.split(",");String c1=Ssplitst[0];String sql1="SELECT * FROM manager where mID='"+S+"'";rs= stmt.executeQuery(sql1);int lll=0;while(rs.next()){String a222 =rs.getString(1);String b222 =rs.getString(2);String c222 =rs.getString(3);String d222 =rs.getString(4);String e222 =rs.getString(5);String f222 =rs.getString(6);System.out.println(a222+","+b222+" ,"+c222+","+d222+","+e222+","+f222);lll++;}if(lll==0){System.out.println( "没有这个管理员,请重新输入");}else{// System.out.println( "要修改的信息");//String aa=scanner.next();System.out.println("要将它改为");String bb=scanner.next();String updateSql="UPDATE manager SET mName='"+bb+"' WHERE mID='"+S+"'";int hh=stmt.executeUpdate(updateSql); //返回记录影响的条数if(hh!=0){System.out.println("修改成功!");}System.out.println("是否继续修改yes/no no返回主菜单");String o=scanner.next();if(o.startsWith("yes")){System.out.println();};if(o.startsWith("no")){mm=1;System.out.println();};}}break;}break;/*String updateSql="UPDATE manager SET mSex='"+c1+"' WHERE mID=1";int t=stmt.executeUpdate(updateSql); //返回记录影响的条数if(t!=0){System.out.println("修改成功!");}}break;*/case 4:System.out.println(" 图书借阅信息: ");System.out.println(" 1. 查询图书借阅信息信息: ");System.out.println(" 2. 插入图书借阅信息: ");System.out.println(" 3. 删除图书借阅信息: ");System.out.println(" 4. 修改图书借阅信息: ");System.out.println(" 5. 返回上一级");int d=scanner.nextInt();switch(d){case 1:System.out.println(" 1. 查询图书借阅信息: ");String Sql4 = "SELECT * FROM borrowbook ";rs= stmt.executeQuery(Sql4);while(rs.next()){String bookID =rs.getString(1);String reaID =rs.getString(2);String outDate =rs.getString(3);String yhDate =rs.getString(4);System.out.println(bookID+","+reaID+","+outDate+","+yhDate);}break;case 2:int zz=0;while(zz!=1){System.out.println(" 2. 插入图书借阅信息: ");System.out.println("请按顺序插入图书的的编号,读者编号,图书借出日期,图书归还日期");String str=scanner.next();String []splitst=str.split(",");String a11=splitst[0];String a12=splitst[1];String a13=splitst[2];String a14=splitst[3];//String a15=splitst[4];//String a16=splitst[5];String insertSql="INSERT INTO borrowbook(bookID,reaID,outDate,yhDate) VALUES('"+a11+"','"+a12+"','"+a13+"','"+a14+"')";int ii=stmt.executeUpdate(insertSql); //返回记录影响的条数if(ii!=0){System.out.println("插入成功!");}System.out.println("是否继续插入?yes/no no返回主菜单");String k=scanner.next();if(k.startsWith("yes")){System.out.println();};if(k.startsWith("no")){zz=1;System.out.println();};}break;case 3:int ll=0;while(ll!=1){System.out.println(" 3. 删除图书借阅信息: ");System.out.println("请输入要删除的图书条码号:");String Str=scanner.next();String []Splitst=Str.split(",");String b3=Splitst[0];String sql1="SELECT * FROM borrowbook where bookID='"+b3+"'";rs= stmt.executeQuery(sql1);int kkk=0;while(rs.next()){String a22 =rs.getString(1);String b22 =rs.getString(2);String c22 =rs.getString(3);String d22 =rs.getString(4);// String e22 =rs.getString(5);//String f22 =rs.getString(6);System.out.println(a22+","+b22+" ,"+c22+","+d22);kkk++;}if(kkk==0){System.out.println( "没有这本书,请重新输入");}else{//System.out.println( "您是否真的要删除? yes/no");//String k=scanner.next();//if(k.startsWith("y")){String deleSql= "DELETE FROM borrowbook WHERE bookID='"+b3+"'";int p=stmt.executeUpdate(deleSql); //返回记录影响的条数if(p!=0){System.out.println("删除成功!");}System.out.println("是否继续删除?yes/no no返回主菜单");String l=scanner.next();if(l.startsWith("yes")){System.out.println();};if(l.startsWith("no")){ll=1;System.out.println();};}}}/* String deleSql= "DELETE bookID FROM borrowbook WHERE bookID='"+b3+"'";int k=stmt.executeUpdate(deleSql); //返回记录影响的条数if(k!=0){System.out.println("删除成功!");}*/break;case 4:int mm=0;while(mm!=1)System.out.println(" 4. 修改借阅读书信息: ");System.out.println("请输入要修改的图书的ID ");String S=scanner.next();String []Ssplitst=S.split(",");String c1=Ssplitst[0];String sql1="SELECT * FROM borrowbook where bookID='"+S+"'";rs= stmt.executeQuery(sql1);int lll=0;while(rs.next()){String a222 =rs.getString(1);String b222 =rs.getString(2);String c222 =rs.getString(3);String d222 =rs.getString(4);//String e222 =rs.getString(5);//String f222 =rs.getString(6);System.out.println(a222+","+b222+" ,"+c222+","+d222);lll++;}if(lll==0){System.out.println( "没有这条记录,请重新输入");}else{// System.out.println( "要修改的信息");//String aa=scanner.next();System.out.println("要将借阅日期改为");String bb=scanner.next();String updateSql="UPDATE borrowbook SET outDate='"+bb+"' WHERE bookID='"+S+"'";int hh=stmt.executeUpdate(updateSql); //返回记录影响的条数if(hh!=0){System.out.println("修改成功!");}System.out.println("是否继续修改yes/no no返回主菜单");String o=scanner.next();if(o.startsWith("yes")){System.out.println();};if(o.startsWith("no")){mm=1;System.out.println();};}break;}break;。
图书馆管理系统完整代码
<body> <table border="0" width="751" height="62" align="center"> <tbody><tr> <td> <img border="0" src="Images/banner.png" width="1300" height="200"></td></tr> </tbody></table><br><table border="0" width="1300" height="76"> <tbody><tr> <td align="right"> <a href="queryBook.jsp">图书检索</a></td> <td align="center"> <a href="login.jsp">用户登陆</a></td> <td><a href="logon.jsp">用户注册</a></td></tr>
</tbody></table><br></body> </html>
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
目录第1章本设计所要达到的目的和要求1.1 设计目的1.2 设计要求第2章设计内容第3 章开发和运行环境介绍第4章需求分析1、本设计所要达到的目的和要求1.1 设计目的管理信息系统(MIS)的应用已深入到社会的各行各业,它是信息、软件与科学管理相结合的产物。
MIS的开发过程不仅是一个编写应用程序的过程,而且是一个以软件工程的思想为指导,从可行性研究开始,经过系统分析、系统设计、系统实施到等主要阶段的规范开发过程。
本题目实现的是JAVA系统,我们选择的是图书馆管理系统,不同角色的用户登录,用户信息的管理包括密码管理,及用户借还书,用户对图书信息及本人借还情况的查询,超级管理员对图书信息的增删查改,用户信息的增删查改及借还情况总的查询。
1.2 设计要求1、主题明确,软体开发要有创新性,能体现SQL的存储过程、触发器、游标技术等;2、用高级语言结合SQL Server数据库进行开发;3、写出数据库关系模式及相应的数据库表关系图;4、绘制成绩MIS相应的系统流程图、E-R图等;5、完成成绩MIS登陆界面、主界面、图书信息录入、图书信息查询和其各项设计与操作。
2、设计内容我们设计的图书馆管理系统主要用于对图书馆日常工作的管理,主要任务是用计算机对读者、图书等各种信息进行日常管理,如查询、修改、增加、删除、图书借阅和归还的管理等。
本系统实现了图书馆的信息化管理,完成了图书馆管理系统的基本功能。
该系统主要包括读者用户登录系统、管理员用户登入系统、图书管理系统、图书借阅、图书和用户信息查询子系统四个部分,各部分主要功能如下:读者用户登录子系统:用于数据库的连接,主界面的设计和读者身份用户的登录管理。
管理员用户登入系统:用于管理员用户的管理,如图书添加、图书信息修改。
图书管理系统:用于图书信息的管理,如新书入库、图书信息修改、图书信息删除。
图书借阅系统:用于用户借阅和归还图书。
图书和用户信息查询:图书和用户信息的查询。
留言系统:用于留言管理。
3、开发和运行环境介绍开发语言:前台开发语言为java,后台数据库为SQL server2000运行环境:eclipseEclipse是著名的跨平台的自有(IDE)。
最初主要用来Java语言开发,但是目前亦有人通过插件使其作为其他计算机语言比如C++和Python的开发工具。
Eclipse的本身只是一个框架平台,但是众多插件的支持使得Eclipse拥有其他功能相对固定的IDE软件很难具有的灵活性。
许多软件开发商以Eclipse为框架开发自己的IDE。
4、需求分析4.1系统需求描述实现管理员对用户的增删改查,对图书信息增删查改、图书借阅信息的修改以,实现用户对图书的查找、借阅、续借、归还以及修改密码。
...4.2系统功能结构图图1 图书管理系统系统流程图..4.3 系统E-R图图2 用户实体图图3 书籍实体图图4 实体属性图4.5数据库表结构表1 图书信息表表2 用户借阅表表3用户信息表5.系统设计与实现5.1 模块功能描述○1.在整个图书管理系统中读者用户登录系统的设计,主要包括如下功能:连接远程数据库:首先建立连接,然后配置数据源。
整个界面的设计:主框架,点击按钮分别触发事件。
用户登录:管理员,图书馆工作人员,普通用户分别实现进入自己的界面。
○2.在整个图书管理系统中管理员用户管理子系统的设计,主要包括如下功能:用户添加:用于添加用户信息。
用户信息修改:管理员可以修改用户所有信息,用户可以修改自己的密码。
用户删除:用于删除用户信息。
包括按用户id和密码删除。
○3.在整个图书馆管理系统中图书管理子系统的设计,主要包括如下功能:图书添加:用于添加图书信息。
图书信息修改:管理员可以修改图书所有信息。
图书删除:用于删除图书信息。
包括按图书id删除。
○4.在整个图书馆管理系统中图书借阅管理子系统的设计,主要包括如下功能:借阅图书:用户借书。
续借:通过改变归还日期来续借。
借阅信息显示:管理员和工作人员可以查看所有用户借阅信息,普通用户只可以查看自己的借阅信息。
5.2 软件实现读者用户登录系统:package hehe;import java.awt.Frame;import java.awt.Menu;import java.awt.MenuBar;import java.awt.MenuItem;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;@SuppressWarnings("serial")public class 菜单1 extends Frame implements ActionListener{//TextArea ta; //文本区MenuBar mb; //MenuBar 类封装绑定到框架的菜单栏的Menu mnLog,mnJy,mnFy,mnLy; //从菜单栏部署的下拉式菜单组件MenuItem mizhuce,milog,miExit,miyhzh,miyhxx; //菜单中的所有项必须属于类MenuItem 或其子类之一MenuItemmifyshow,mifydelete,mifyinsert,mifymodify,milyshow,miyshow,mijyshow,mijyinsert,m ijymodify;public 菜单1(){super("图书管理系统"); //调用父类构造方法// ta = new TextArea("",20,20); //新建文本区,第一个参数是默认文本,第二个参数是行数,第三个是列数/** BorderLayout边框布局* 添加文本区到Frame,BorderLayout.CENTER是居中位置* */// add(ta,BorderLayout.CENTER);mb = new MenuBar(); //创建菜单栏对象/** 创建菜单,指定菜单名* */mnLog= new Menu("退出");mnFy= new Menu("读者信息管理");mnJy= new Menu("借阅管理");mnLy= new Menu("意见簿留言");/* jLabel=new JLabel("欢迎进入设备管理系统");jLabel.setHorizontalAlignment(JLabel.CENTER);jLabel.setForeground(Color.red);*//** 创建子菜单,并指定名称* */miExit=new MenuItem("退出");miExit.addActionListener(this); //为退出菜单添加监听/** 添加上面创建的子菜单到文件菜单下* */mnLog.add(miExit);//将一个分隔线或连字符添加到菜单的当前位置/** 添加miBinary、miFont两个子菜单到mnFormat(格式)下* */mifyshow=new MenuItem("查看");mifyshow.addActionListener(this);mnFy.add(mifyshow);milyshow=new MenuItem("留言");mnLy.add(milyshow);milyshow.addActionListener(this);miyshow=new MenuItem("查看");mnLy.add(miyshow);miyshow.addActionListener(this);mijyinsert=new MenuItem("借书");mijyinsert.addActionListener(this);mnJy.add(mijyinsert);/** 将文件、编辑、格式、帮助添加到菜单栏* */mb.add(mnLog);mb.add(mnJy);mb.add(mnFy);mb.add(mnLy);setMenuBar(mb); //添加菜单栏到Frame/** 关闭窗口时,关闭运行成语* */addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent e){System.exit(0);}});}public static void main(String args[]){菜单1 tm=new 菜单1();tm.setSize(700,500); //设置窗体的宽、高tm.setLocation(300,100); //将组件移到新位置Component类方法tm.setVisible(true); //设置显示窗体,true为显示,false为隐藏}/*** 监听事件,实现ActionListener接口的actionPerformed方法*/public void actionPerformed(ActionEvent e){if(e.getSource()==miExit){System.exit(0); //停止运行程序}if(e.getSource()==mifyshow){读者信息查询wo= new 读者信息查询("查看");this.setVisible(true);}if(e.getSource()==mijyinsert){读者借阅信息插入wo= new 读者借阅信息插入("借书");this.setVisible(true);}if(e.getSource()==milyshow){意见留言wo= new 意见留言("留言");this.setVisible(true);}if(e.getSource()==miyshow){留言查看wo= new 留言查看("查看");this.setVisible(true);}}}管理员用户登录:package hehe;import java.awt.Frame;import java.awt.Menu;import java.awt.MenuBar;import java.awt.MenuItem;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;@SuppressWarnings("serial")public class 菜单1 extends Frame implements ActionListener{//TextArea ta; //文本区MenuBar mb; //MenuBar 类封装绑定到框架的菜单栏的Menu mnLog,mnJy,mnFy,mnLy; //从菜单栏部署的下拉式菜单组件MenuItem mizhuce,milog,miExit,miyhzh,miyhxx; //菜单中的所有项必须属于类MenuItem 或其子类之一MenuItemmifyshow,mifydelete,mifyinsert,mifymodify,milyshow,miyshow,mijyshow,mijyinsert,mijymodify;public 菜单1(){super("图书管理系统"); //调用父类构造方法// ta = new TextArea("",20,20); //新建文本区,第一个参数是默认文本,第二个参数是行数,第三个是列数/** BorderLayout边框布局* 添加文本区到Frame,BorderLayout.CENTER是居中位置* */// add(ta,BorderLayout.CENTER);mb = new MenuBar(); //创建菜单栏对象/** 创建菜单,指定菜单名* */mnLog= new Menu("退出");mnFy= new Menu("读者信息管理");mnJy= new Menu("借阅管理");mnLy= new Menu("意见簿留言");/* jLabel=new JLabel("欢迎进入设备管理系统");jLabel.setHorizontalAlignment(JLabel.CENTER);jLabel.setForeground(Color.red);*//** 创建子菜单,并指定名称* */miExit=new MenuItem("退出");miExit.addActionListener(this); //为退出菜单添加监听/** 添加上面创建的子菜单到文件菜单下* */mnLog.add(miExit);//将一个分隔线或连字符添加到菜单的当前位置/** 添加miBinary、miFont两个子菜单到mnFormat(格式)下* */mifyshow=new MenuItem("查看");mifyshow.addActionListener(this);mnFy.add(mifyshow);milyshow=new MenuItem("留言");mnLy.add(milyshow);milyshow.addActionListener(this);miyshow=new MenuItem("查看");mnLy.add(miyshow);miyshow.addActionListener(this);mijyinsert=new MenuItem("借书");mijyinsert.addActionListener(this);mnJy.add(mijyinsert);/** 将文件、编辑、格式、帮助添加到菜单栏* */mb.add(mnLog);mb.add(mnJy);mb.add(mnFy);mb.add(mnLy);setMenuBar(mb); //添加菜单栏到Frame/** 关闭窗口时,关闭运行成语* */addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent e){System.exit(0);}});}public static void main(String args[]){菜单1 tm=new 菜单1();tm.setSize(700,500); //设置窗体的宽、高tm.setLocation(300,100); //将组件移到新位置Component类方法tm.setVisible(true); //设置显示窗体,true为显示,false为隐藏}/*** 监听事件,实现ActionListener接口的actionPerformed方法*/public void actionPerformed(ActionEvent e){if(e.getSource()==miExit){System.exit(0); //停止运行程序}if(e.getSource()==mifyshow){读者信息查询wo= new 读者信息查询("查看");this.setVisible(true);}if(e.getSource()==mijyinsert){读者借阅信息插入wo= new 读者借阅信息插入("借书");this.setVisible(true);}if(e.getSource()==milyshow){意见留言wo= new 意见留言("留言");this.setVisible(true);}if(e.getSource()==miyshow){留言查看wo= new 留言查看("查看");this.setVisible(true);}}}登入界面系统:package hehe;import java.awt.Color;import java.awt.Container;import java.awt.Dimension;import java.awt.Font;import java.awt.Toolkit;import java.awt.Image;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import javax.swing.ButtonGroup;import javax.swing.ImageIcon;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPasswordField;import javax.swing.JRadioButton;import javax.swing.JTextField;public class 登陆界面implements ActionListener{public JFrame jf= new JFrame("图书管理系统系统");public Container con = jf.getContentPane();public Toolkit toolkit = Toolkit.getDefaultToolkit(); //获取工具包public Dimension sc = toolkit.getScreenSize(); //getScreenSize(),最后的这个方法返回一个Dimension类型的对象.是返回当先分辨率的.Object a,b;public JRadioButton rb1 = new JRadioButton("读者");public JRadioButton rb2 = new JRadioButton("管理员");public ButtonGroup group = new ButtonGroup ();public JLabel yong_hu = new JLabel("用户名");public JLabel mi_ma = new JLabel("密码");public JTextField textName = new JTextField();public JPasswordField textPs = new JPasswordField();public JButton deng_ru = new JButton("登陆");public JButton qu_xiao = new JButton("取消");public Font font1 = new Font("宋体",1,14);public Font font2 = new Font("宋体",0,12);public 登陆界面() {//con.setLayout(null);//jf.setSize(sc.width/1,sc.height/2); //大小/*jf.setLocation(sc.width/5,sc.height/1010); */ /* public void setLocation(int x,int y)将组件移到新位置。