基于java的图书管理系统源代码_第1页
基于java的图书管理系统源代码_第2页
基于java的图书管理系统源代码_第3页
基于java的图书管理系统源代码_第4页
基于java的图书管理系统源代码_第5页
已阅读5页,还剩22页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

千里之行,始于足下让知识带有温度。第第2页/共2页精品文档推荐基于java的图书管理系统源代码基于java的图书管理系统源代码声明:本系统是基于C/S的图书管理系统,主要使用的是Oracle数据库,下面附全部实现代码

packagelibrary;

importjava.awt.BorderLayout;

importjava.awt.Container;

importjava.awt.GridLayout;

importjava.awt.event.ActionEvent;import

java.awt.event.ActionListener;importjava.sql.ResultSet;

importjavax.swing.JButton;

importjavax.swing.JComboBox;

importjavax.swing.JFrame;

importjavax.swing.JLabel;

importjavax.swing.JOptionPane;importjavax.swing.JPanel;

importjavax.swing.JTextField;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,a

ddress;

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);

1

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("清空");

2

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(""))

3

{

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="insertinto

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))

{

4

this.dispose();

JOptionPane.showMessageDialog(null,"添加图书胜利");

}

else

{

JOptionPane.showMessageDialog(null,"添加图书失败");

this.dispose();

}

db.closeConnection();

}catch(Exceptionex)

{

System.out.println(ex.toString());}

}

}

}

}

packagelibrary;

importjavax.swing.*;

importjava.awt.*;

importjava.awt.event.*;

importjava.sql.ResultSet;

importjava.sql.SQLException;publicclassbook_deleteextendsJFrameimplementsActionListener{

DataBaseManagerdb=newDataBaseManager();

ResultSetrs;

Containerc;

JLabelTipLabel=newJLabel("请挑选要删除的书名",JLabel.CENTER);

JComboBoxbb=newJComboBox();

JButtonyes,exit;

JPanelpanel1=newJPanel();

publicbook_delete()

{

super("删除图书信息");

c=getContentPane();

c.setLayout(newBorderLayout());

5

try{

StringstrSQL="selectbook_namefrombookwhere

book_count>borrowed_count";

rs=db.getResult(strSQL);

while(rs.next())

{

bb.addItem(rs.getString(1));

}

}catch(SQLExceptionsqle){

System.out.println(sqle.toString());

}catch(Exceptionex){

System.out.println(ex.toString());

}

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_countfrombookwhere

book_name='"

+bb.getSelectedItem()+"'";

rs=db.getResult(strSQL);

if(!rs.first())

{

JOptionPane.showMessageDialog(null,"书库里没有你要删除的书");

}

else

{

6

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){

System.out.println(sqle.toString());

}catch(Exceptionex){

System.out.println(ex.toString());

}

}

}

}

packagelibrary;

importjava.awt.BorderLayout;importjava.awt.Container;

importjava.awt.GridLayout;importjava.awt.event.ActionEvent;

importjava.awt.event.ActionListener;importjava.sql.ResultSet;

importjavax.swing.JButton;importjavax.swing.JFrame;

7

importjavax.swing.JLabel;

importjavax.swing.JOptionPane;

importjavax.swing.JPanel;

importjavax.swing.JTextField;

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);

8

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"));

9

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){

System.out.println(upe.toString());

}catch(Exceptiones){

System.out.println(es.toString());

}

}

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()+"'where

book_name='"+book_name_TextField.getText().trim()+"'";

if(db.updateSql(strSQL))

{

this.dispose();

JOptionPane.showMessageDialog(null,"更新图书胜利");

}

else{

JOptionPane.showMessageDialog(null,"更新图书失败");

}

db.closeConnection();

}catch(Exceptionsqle){

System.out.println(sqle.toString());

}

}

}

}

packagelibrary;

importjava.awt.BorderLayout;

importjava.awt.Container;

importjava.awt.GridLayout;

importjava.awt.event.ActionEvent;

10

importjava.awt.event.ActionListener;importjava.sql.ResultSet;importjava.sql.SQLException;

importjava.text.DateFormat;

importjava.text.SimpleDateFormat;importjava.util.Calendar;importjava.util.Date;

importjavax.swing.JButton;

importjavax.swing.JComboBox;

importjavax.swing.JFrame;

importjavax.swing.JLabel;

importjavax.swing.JOptionPane;

importjavax.swing.JPanel;

importjavax.swing.JTextField;

publicclassbookborrowextendsJFrameimplementsActionListener{DataBaseManagerdb=newDataBaseManager();

ResultSetrs;

Containerc;

JPanelpanel1,panel2;

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论