简易图书管理系统Word文档下载推荐.docx
《简易图书管理系统Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《简易图书管理系统Word文档下载推荐.docx(20页珍藏版)》请在冰豆网上搜索。
![简易图书管理系统Word文档下载推荐.docx](https://file1.bdocx.com/fileroot1/2022-10/9/4962b3a4-d45c-4d3e-b338-2926420b6aaa/4962b3a4-d45c-4d3e-b338-2926420b6aaa1.gif)
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<
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(