简易图书管理系统方案.docx

上传人:b****5 文档编号:7994001 上传时间:2023-01-27 格式:DOCX 页数:18 大小:239.13KB
下载 相关 举报
简易图书管理系统方案.docx_第1页
第1页 / 共18页
简易图书管理系统方案.docx_第2页
第2页 / 共18页
简易图书管理系统方案.docx_第3页
第3页 / 共18页
简易图书管理系统方案.docx_第4页
第4页 / 共18页
简易图书管理系统方案.docx_第5页
第5页 / 共18页
点击查看更多>>
下载资源
资源描述

简易图书管理系统方案.docx

《简易图书管理系统方案.docx》由会员分享,可在线阅读,更多相关《简易图书管理系统方案.docx(18页珍藏版)》请在冰豆网上搜索。

简易图书管理系统方案.docx

简易图书管理系统方案

本程序以java为设计语言,能够实现一个简单的图书管理系统,可以实现简单的增加图书,查询图书,删除图书的功能,其中用到数据库的连接,窗体的布局管理。

本程序有以下几个功能函数组成

所有模块都在名为bookmanager的包中

1:

主函数mainframe.java

2:

增加模块adddialog.java

3:

查询模块searchdialog.java

4:

查询结果模块searchresult.java

5:

书本类book.java

6:

数据库连接类dbcon.java

1.主界面

2.添加模块

3.查询模块

4.输出模块

5.

6.

源程序如下

1.mainframe.java

packagebookmanager;

importjavax.swing.*;

importjavax.swing.table.DefaultTableModel;

importjava.awt.*;

importjava.awt.event.*;

importjava.sql.Connection;

importjava.sql.PreparedStatement;

importjava.sql.ResultSet;

importjava.sql.SQLException;

importjava.util.LinkedList;

publicclassmainframeextendsJFrameimplementsActionListener{

privateJToolBartb;

String[]btntitle={"增加","查询","删除","退出"};

String[]tabeltitle={"图书编号","书名","定价",""};

JButtonbtn[]=newJButton[4];

JTabletable;

DefaultTableModelmodel;

publicmainframe(){

super("图书管理系统");

//初始化各个按钮

tb=newJToolBar("工具栏");

for(inti=0;i

btn[i]=newJButton(btntitle[i]);

btn[i].addActionListener(this);

tb.add(btn[i]);

}

//创建表模型

model=newDefaultTableModel(tabeltitle,10);

table=newJTable(model);

//设定单元格的高度

table.setRowHeight(25);

add(tb,BorderLayout.NORTH);

add(newJScrollPane(table),BorderLayout.CENTER);

setSize(900,600);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setLocation(100,30);

init();

}

publicvoidactionPerformed(ActionEvente){

mainframem=newmainframe();

Objecto=e.getSource();

{

if(o==btn[0]){

adddialogad=newadddialog(m,25,25);

init();

}

if(o==btn[1]){

searchdialogsd=newsearchdialog(m,25,25);

sd.dialog.setVisible(true);

init();

}

if(o==btn[2]){

intresult=JOptionPane.showConfirmDialog(null,"确实要删除该条图书信息吗?

","确认",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE);

if(result==0){

Connectioncon=dbcon.getconnectin();

Objectob=model.getValueAt(table.getSelectedRow(),0);

dbcon.delete(con,ob);

init();

}

else{

return;

}

}

if(o==btn[3]){

System.exit(0);

}

}

}

publicvoidinit(){

Connectioncon=dbcon.getconnectin();

LinkedListlist=null;

try{

PreparedStatementstmt=con.prepareStatement("select*frombook");

ResultSetrs=stmt.executeQuery();

list=newLinkedList();

while(rs.next()){

Stringid=rs.getString

(1);

Stringname=rs.getString

(2);

Stringprice=rs.getString(3);

Stringpublish=rs.getString(4);

bookb=newbook(id,name,Float.valueOf(price),publish);

list.add(b);

}

model.setRowCount(0);

for(inti=0;i

bookb=(book)list.get(i);

Object[]str={b.getid(),b.getname(),b.getprice(),b.getpublish()};

model.addRow(str);

}

}catch(SQLExceptione){

//TODOAuto-generatedcatchblock

e.printStackTrace();

}

}

publicstaticvoidmain(Stringargs[]){

newmainframe().show();

}

}

*********************************************************

*********************************************************

2.Adddialog.java添加模块

packagebookmanager;

importjava.awt.*;

importjava.awt.event.*;

importjava.util.LinkedList;

importjavax.swing.*;

publicclassadddialogimplementsActionListener{

JLabellabel[]=newJLabel[4];

JTextFieldtxt[]=newJTextField[4];

String[]ltitle={"图书编号","图书名称","单价","出版社"};

String[]btitle={"上一个","下一个","确定","取消"};

JButtonbtn[]=newJButton[4];

JDialogdialog;

JPanelp;

LinkedListlist;

publicadddialog(JFramef,intx,inty){

dialog=newJDialog(f,"增加",true);

dialog.setLocation(x,y);

p=newJPanel();

list=newLinkedList();

//p.setBorder(BorderFactory.createTitledBorder("请选择操作"));

//p.setBorder(BorderFactory.createLineBorder(Color.red));

//p.setBorder(BorderFactory.createBevelBorder(0,Color.red,Color.green));

p.setBorder(BorderFactory.createBevelBorder(0,Color.red,Color.green,Color.blue,Color.yellow));

for(inti=0;i

label[i]=newJLabel(ltitle[i]);

label[i].setFont(newFont("宋体",Font.PLAIN,18));

txt[i]=newJTextField();

btn[i]=newJButton(btitle[i]);

btn[i].addActionListener(this);

btn[i].setFont(newFont("幼圆",Font.PLAIN,15));

dialog.add(label[i]);

dialog.add(txt[i]);

dialog.add(btn[i]);

}

dialog.setLayout(null);

p.setBounds(10,150,310,160);

p.setBackground(Color.green);

label[0].setBounds(10,10,90,25);txt[0].setBounds(110,10,200,25);

label[1].setBounds(10,45,90,25);txt[1].setBounds(110,45,200,25);

label[2].setBounds(10,80,90,25);txt[2].setBounds(110,80,200,25);

label[3].setBounds(10,115,90,25);txt[3].setBounds(110,115,200,25);

dialog.add(p);

btn[0].setBounds(60,180,80,25);btn[1].setBounds(175,180,80,25);

btn[2].setBounds(60,250,80,25);btn[3].setBounds(175,250,80,25);

dialog.setSize(400,400);

dialog.show();

dialog.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

}

publicvoidactionPerformed(ActionEvente){

intsize=list.size();

//init();

//list.add(b);

//if(e.getSource()==btn[0]){

//

//bookb1=(book)list.get(size);

//size--;

//txt[0].setText(b1.getid());

//txt[1].setText(b1.getname());

//txt[2].setText(Float.toString(b1.getprice()));

//txt[3].setText(b1.getpublish());

//}

//if(e.getSource()==btn[1]){

//

//bookb2=(book)list.get(size);

//size++;

//txt[0].setText(b2.getid());

//txt[1].setText(b2.getname());

//txt[2].setText(Float.toString(b2.getprice()));

//txt[3].setText(b2.getpublish());

//}

if(e.getSource()==btn[2]){

Stringid=txt[0].getText();

Stringname=txt[1].getText();

floatprice=getprice(txt[2].getText());

Stringpublish=txt[3].getText();

Objectstr[]={id,name,price,publish};

dbcon.insert(dbcon.getconnectin(),str);

}

}

privatefloatgetprice(Stringstr){

floatprice=0;

try{

price=Float.valueOf(str);

}

catch(Exceptionex){

JOptionPane.showMessageDialog(null,"价格必须是数字,请重新输入!

","错误",JOptionPane.WARNING_MESSAGE);

}

returnprice;

}

//设定上一个,下一个按钮的可用性

//privatevoidinit(){

//if(list.size()==0)

//{

//btn[0].setEnabled(false);

//btn[1].setEnabled(false);

//}

//else{

//btn[0].setEnabled(true);

//btn[1].setEnabled(true);

//}

//}

}

3.searchdialog.java查找模块

packagebookmanager;

importjavax.swing.*;

importjava.awt.*;

importjava.awt.event.*;

importjava.sql.Connection;

importjava.sql.PreparedStatement;

importjava.sql.ResultSet;

importjava.sql.SQLException;

importjava.util.LinkedList;

publicclasssearchdialogimplementsActionListener,ItemListener{

JRadioButton[]radio=newJRadioButton[3];

ButtonGroupgroup;

String[]rtitle={"图书编号","图书名称","出版社"};

String[]btitle={"确定(Yes)","取消(Esc)"};

JTextFieldtxtfield[]=newJTextField[3];

JButtonbtn[]=newJButton[2];

JDialogdialog;

searchresultst;

publicsearchdialog(JFramef,intx,inty){

//初始化单选按钮

group=newButtonGroup();

st=newsearchresult();

for(inti=0;i

radio[i]=newJRadioButton(rtitle[i]);

radio[i].addActionListener(this);

radio[i].setFont(newFont("宋体",Font.PLAIN,15));

radio[i].addItemListener(this);

group.add(radio[i]);

txtfield[i]=newJTextField();

txtfield[i].setEditable(false);

}

for(inti=0;i<2;i++){

btn[i]=newJButton(btitle[i]);

btn[i].addActionListener(this);

btn[i].setFont(newFont("宋体",Font.PLAIN,15));

}

dialog=newJDialog(f,"查询",true);

//初始化

radio[0].setSelected(true);

txtfield[0].setEditable(true);

dialog.setLocation(x,y);

dialog.setLayout(null);

//设定各个组件的边界

radio[0].setBounds(10,10,90,25);txtfield[0].setBounds(110,10,250,25);

radio[1].setBounds(10,45,90,25);txtfield[1].setBounds(110,45,250,25);

radio[2].setBounds(10,80,90,25);txtfield[2].setBounds(110,80,250,25);

for(inti=0;i

dialog.add(radio[i]);

dialog.add(txtfield[i]);

}

btn[0].setBounds(20,135,120,25);btn[1].setBounds(200,135,120,25);

dialog.add(btn[0]);dialog.add(btn[1]);

dialog.setSize(400,250);

dialog.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

}

publicvoidactionPerformed(ActionEvente){

if(e.getSource()==btn[0]){

st.init();

Connectioncon=dbcon.getconnectin();

PreparedStatementstmt=null;

ResultSetrs=null;

LinkedListlist=newLinkedList();

try{

if(radio[0].isSelected()){

stmt=con.prepareStatement("select*frombookwherebidlike'%"+txtfield[0].getText().trim()+"%'");

}

if(radio[1].isSelected()){

stmt=con.prepareStatement("select*frombookwherebnamelike'%"+txtfield[1].getText().trim()+"%'");

}

if(radio[2].isSelected()){

stmt=con.prepareStatement("select*frombookwherebpublishlike'%"+txtfield[2].getText().trim()+"%'");

}

rs=stmt.executeQuery();

while(rs.next()){

Stringid=rs.getString

(1);

Stringname=rs.getString

(2);

Stringprice=rs.getString(3);

Stringpublish=rs.getString(4);

bookb=newbook(id,name,Float.valueOf(price),publish);

list.add(b);

}

for(inti=0;i

bookb=(book)list.get(i);

Objectob[]={b.getid(),b.getname(),b.getprice(),b.getpublish()};

st.model.addRow(ob);

}

JOptionPane.showMessageDialog(null,"总共找到"+list.size()+"条记录!

","信息",JOptionPane.INFORMATION_MESSAGE);

st.show();

}catch(SQLExceptione1){

//TODOAuto-generatedcatchblock

e1.printStackTrace();

}

}

}

publicvoiditemStateChanged(ItemEvente){

for(inti=0;i

if(radio[i].isSelected()){

txtfield[i].setEditable(true);

}

elsetxtfield[i].setEditable(false);

}

}

}

4.searchresult.java查找结果

packagebookmanager;

importjavax.swing.*;

importjavax.swing.table.DefaultTableModel;

importjava.awt.*;

importjava.awt.event.*;

publicclasssearchresultextendsJFrameimplementsActionListener{

JTabletable;

DefaultTableModelmodel;

String[]rtitle={"图书编号","图书名称","单价","出版社"};

JDialogdialog;

publicsearchresult(){

super("查询结果");

model=newDefaultTableModel(rtitl

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 初中教育 > 政史地

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1