简易图书管理系统Word文档下载推荐.docx
- 文档编号:22648435
- 上传时间:2023-02-05
- 格式:DOCX
- 页数:21
- 大小:239.08KB
简易图书管理系统Word文档下载推荐.docx
《简易图书管理系统Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《简易图书管理系统Word文档下载推荐.docx(21页珍藏版)》请在冰豆网上搜索。
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(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
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 简易 图书 管理 系统
![提示](https://static.bdocx.com/images/bang_tan.gif)