简易图书管理系统Word文档格式.docx

上传人:b****1 文档编号:419818 上传时间:2023-04-28 格式:DOCX 页数:21 大小:239.90KB
下载 相关 举报
简易图书管理系统Word文档格式.docx_第1页
第1页 / 共21页
简易图书管理系统Word文档格式.docx_第2页
第2页 / 共21页
简易图书管理系统Word文档格式.docx_第3页
第3页 / 共21页
简易图书管理系统Word文档格式.docx_第4页
第4页 / 共21页
简易图书管理系统Word文档格式.docx_第5页
第5页 / 共21页
简易图书管理系统Word文档格式.docx_第6页
第6页 / 共21页
简易图书管理系统Word文档格式.docx_第7页
第7页 / 共21页
简易图书管理系统Word文档格式.docx_第8页
第8页 / 共21页
简易图书管理系统Word文档格式.docx_第9页
第9页 / 共21页
简易图书管理系统Word文档格式.docx_第10页
第10页 / 共21页
简易图书管理系统Word文档格式.docx_第11页
第11页 / 共21页
简易图书管理系统Word文档格式.docx_第12页
第12页 / 共21页
简易图书管理系统Word文档格式.docx_第13页
第13页 / 共21页
简易图书管理系统Word文档格式.docx_第14页
第14页 / 共21页
简易图书管理系统Word文档格式.docx_第15页
第15页 / 共21页
简易图书管理系统Word文档格式.docx_第16页
第16页 / 共21页
简易图书管理系统Word文档格式.docx_第17页
第17页 / 共21页
简易图书管理系统Word文档格式.docx_第18页
第18页 / 共21页
简易图书管理系统Word文档格式.docx_第19页
第19页 / 共21页
简易图书管理系统Word文档格式.docx_第20页
第20页 / 共21页
亲,该文档总共21页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

简易图书管理系统Word文档格式.docx

《简易图书管理系统Word文档格式.docx》由会员分享,可在线阅读,更多相关《简易图书管理系统Word文档格式.docx(21页珍藏版)》请在冰点文库上搜索。

简易图书管理系统Word文档格式.docx

publicclassmainframeextendsJFrameimplementsActionListener{

privateJToolBartb;

String[]btntitle={"

增加"

"

查询"

删除"

退出"

};

String[]tabeltitle={"

图书编号"

书名"

定价"

出版社"

JButtonbtn[]=newJButton[4];

JTabletable;

DefaultTableModelmodel;

publicmainframe(){

super("

图书管理系统"

);

//初始化各个按钮

tb=newJToolBar("

工具栏"

for(inti=0;

i<

btntitle.length;

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;

list.size();

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添加模块

publicclassadddialogimplementsActionListener{

JLabellabel[]=newJLabel[4];

JTextFieldtxt[]=newJTextField[4];

String[]ltitle={"

图书名称"

单价"

出版社"

String[]btitle={"

上一个"

下一个"

确定"

取消"

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

ltitle.length;

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

label[i].setFont(newFont("

宋体"

Font.PLAIN,18));

txt[i]=newJTextField();

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

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

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查找模块

publicclasssearchdialogimplementsActionListener,ItemListener{

JRadioButton[]radio=newJRadioButton[3];

ButtonGroupgroup;

String[]rtitle={"

确定(Yes)"

取消(Esc)"

JTextFieldtxtfield[]=newJTextField[3];

JButtonbtn[]=newJButton[2];

searchresultst;

publicsearchdialog(JFramef,intx,inty){

//初始化单选按钮

group=newButtonGroup();

st=newsearchresult();

radio.length;

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

radio[i].addActionListener(this);

radio[i].setFont(newFont("

radio[i].addItemListener(this);

group.add(radio[i]);

txtfield[i]=newJTextField();

txtfield[i].setEditable(false);

2;

dialog=newJDialog(f,"

//初始化

radio[0].setSelected(true);

txtfield[0].setEditable(true);

//设定各个组件的边界

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

radio.length;

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

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

select*frombookwherebnamelike'

+txtfield[1].getText().trim()+"

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

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

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

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

st.model.addRow(ob);

}

总共找到"

+list.size()+"

条记录!

信息"

JOptionPane.INFORMATION_MESSAGE);

st.show();

}catch(SQLExceptione1){

//TODOAuto-generatedcatchblock

e1.printStackTrace();

publicvoiditemStateChanged(ItemEvente){

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

txtfield[i].setEditable(true);

elsetxtfield[i].setEditable(false);

4.searchresult.java查找结果

publicclasssearchresultextendsJFrameimplementsActionListener{

JTabletable;

String[]rtitle={"

单价"

JDialogdialog;

publicsearchresult(){

super("

查询结果"

model=newDefaultTableModel(rtit

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

当前位置:首页 > 自然科学 > 物理

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2