图书管理系统java代码Word文档格式.docx
《图书管理系统java代码Word文档格式.docx》由会员分享,可在线阅读,更多相关《图书管理系统java代码Word文档格式.docx(14页珍藏版)》请在冰豆网上搜索。
MenuItemmhelpp=newMenuItem("
关于"
Denglupdenglu=newDenglu();
Ptianjiaptianjia=newPtianjia();
Pmainpmain=newPmain();
Pchaxunpchaxun=newPchaxun();
Pshanchupshanchu=newPshanchu();
dbframe(Strings){//在窗口上添加菜单选项
setTitle(s);
mfile.add(mdenglu);
mfile.add(mtianjia);
mfile.add(mchaxun);
mfile.add(mshanchu);
mfile.add(mexit);
mhelp.add(mhelpp);
daohang.add(mfile);
daohang.add(mhelp);
setMenuBar(daohang);
add(pmain);
addWindowListener(newWindowAdapter(){
publicvoidwindowClosing(WindowEvente){
System.exit(0);
}
});
setBounds(200,200,340,250);
setResizable(false);
setVisible(true);
mexit.addActionListener(this);
mdenglu.addActionListener(this);
mtianjia.addActionListener(this);
mchaxun.addActionListener(this);
mshanchu.addActionListener(this);
mhelpp.addActionListener(this);
validate();
}//窗口事件监听
publicvoidactionPerformed(ActionEvente){
if(e.getSource()==mexit)
System.exit(0);
if(e.getSource()==mdenglu){
removeAll();
add(pdenglu);
validate();
}
if(e.getSource()==mtianjia){
add(ptianjia);
}//图书添加功能
if(e.getSource()==mchaxun){
add(pchaxun);
}//图书查询功能
if(e.getSource()==mshanchu){
add(pshanchu);
}//图书删除功能
if(e.getSource()==mhelpp){
JOptionPane.showMessageDialog(this,"
欢迎使用图书管理系统"
"
关于本系统"
JOptionPane.INFORMATION_MESSAGE);
}//各功能菜单事件监听
//
classPtianjiaextendsPanelimplementsActionListener{
TextFieldtname,tauthor,tpublish,tdate,tcomment;
Labellname,lauthor,lpublish,ldate,lcomment;
Buttonbtn;
Ptianjia(){
setLayout(null);
btn=newButton("
//创建“添加”按钮
tname=newTextField();
tauthor=newTextField();
tpublish=newTextField();
tdate=newTextField();
tcomment=newTextField();
//创建5个文本框
lname=newLabel("
书名"
lauthor=newLabel("
作者"
lpublish=newLabel("
出版社"
ldate=newLabel("
出版日期"
lcomment=newLabel("
评论"
add(lname);
add(tname);
add(lauthor);
add(tauthor);
add(lpublish);
add(tpublish);
add(ldate);
add(tdate);
add(lcomment);
add(tcomment);
add(btn);
//添加“按钮”到窗口面板上
lname.setBounds(10,10,70,25);
tname.setBounds(90,10,220,25);
lauthor.setBounds(10,40,70,25);
tauthor.setBounds(90,40,220,25);
lpublish.setBounds(10,70,70,25);
tpublish.setBounds(90,70,220,25);
ldate.setBounds(10,100,70,25);
tdate.setBounds(90,100,220,25);
lcomment.setBounds(10,130,70,25);
tcomment.setBounds(90,130,220,25);
btn.setBounds(130,160,70,25);
//设置按钮位置
btn.addActionListener(this);
//设置按钮监听
setSize(340,250);
//设置窗口大小
setBackground(Color.white);
//设置窗口背景颜色
Stringsname=tname.getText();
Stringsauthor=tauthor.getText();
Stringspublish=tpublish.getText();
Stringsdate=tdate.getText();
Stringscomment=tcomment.getText();
Stringinsertstr="
insertintobookvalues"
+"
("
'
"
+sname+"
+"
"
+sauthor+"
+spublish+"
+sdate+"
+scomment+"
)"
;
//SQL语句
Connectioncon;
Statementsta;
ResultSetrs;
try{
Class.forName("
oracle.jdbc.driver.OracleDriver"
//加载JDBC驱动
}catch(ClassNotFoundExceptionee){
System.out.println("
+ee);
con=DriverManager.getConnection("
jdbc:
oracle:
thin:
@localhost:
1521:
orcl"
sa"
//连接数据库
sta=con.createStatement();
sta.executeUpdate(insertstr);
//执行SQL语句
con.close();
//关闭数据库
tname.setText("
tauthor.setText("
tpublish.setText("
tdate.setText("
tcomment.setText("
//重新初始化文本框内容
添加成功"
图书管理系统"
}catch(SQLExceptioneee){
+eee);
添加失败"
JOptionPane.WARNING_MESSAGE);
classPmainextendsPanel{//窗口面板布局
Labell1=newLabel("
Label.CENTER);
Labell2=newLabel("
计算机学院"
Label.RIGHT);
Labell3=newLabel("
Labell4=newLabel("
作者:
JHL"
Pmain(){
add(l1);
add(l2);
add(l3);
add(l4);
l1.setBounds(10,60,320,40);
l2.setBounds(240,120,80,22);
l3.setBounds(240,142,80,22);
l4.setBounds(240,164,80,22);
classPchaxunextendsPanelimplementsActionListener{//图书查询
Choicecchaxun;
TextFieldtchaxun;
Buttonbtnchaxun;
TextAreatachaxun;
Pchaxun(){
cchaxun=newChoice();
//创建下拉菜单
cchaxun.add("
tchaxun=newTextField();
btnchaxun=newButton("
//创建按钮
tachaxun=newTextArea();
//创建多行文本框
add(cchaxun);
add(tchaxun);
add(btnchaxun);
add(tachaxun);
tchaxun.setText("
cchaxun.setBounds(10,10,65,20);
tchaxun.setBounds(85,10,180,20);
btnchaxun.setBounds(275,10,40,20);
tachaxun.setBounds(10,40,305,145);
cchaxun.select(0);
//下拉菜单的初始选项
btnchaxun.addActionListener(this);
inti=cchaxun.getSelectedIndex();
Strings=tchaxun.getText();
if(s.equals("
))
查询内容不能为空"
查询系统"
else{
Connectioncon;
Statementsql;
ResultSetrs;
try{
Class.forName("
}catch(ClassNotFoundExceptionee){
System.out.println("
con=DriverManager.getConnection("
//连接数据库
sql=con.createStatement();
if(i==0)//根据下拉菜单的选项执行不同的SQL语句
rs=sql.executeQuery("
select*frombookwherebookName="
+"
+s+"
elseif(i==1)
select*frombookwhereauthor="
else
select*frombookwherepublisher="
+"
tachaxun.setText("
Stringpanduan="
false"
while(rs.next()){
panduan="
true"
tachaxun.append("
书名:
+rs.getString
(1)+"
\n"
作者:
+rs.getString
(2)+"
出版社:
+rs.getString(3)+"
出版日期:
+rs.getString(4)+"
评论:
+rs.getString(5)+"
}//显示查询到的图书信息
rs=sql.executeQuery("
selectcount(*)frombook"
//统计所有图书数
图书馆暂有"
本图书"
}//显示所有图书数量信息
con.close();
if(panduan.equals("
JOptionPane.showMessageDialog(this,"
没有该记录"
JOptionPane.WARNING_MESSAGE);
}catch(SQLExceptioneee){
System.out.println(eee);
classPshanchuextendsPanelimplementsActionListener{//删除功能模块
Choicecshanchu;
TextFieldtshanchu;
Buttonbtnshanchu;
ZCS"
Pshanchu(){
cshanchu=newChoice();
cshanchu.add("
tshanchu=newTextField();
btnshanchu=newButton("
add(cshanchu);
add(tshanchu);
add(btnshanchu);
//添加标签、按钮等到窗口面板
tshanchu.setText("
cshanchu.setBounds(10,10,65,20);
tshanchu.setBounds(85,10,180,20);
btnshanchu.setBounds(275,10,40,20);
l1.setBounds(10,40,300,40);
l2.setBounds(240,130,80,22);
l3.setBounds(240,152,80,22);
l4.setBounds(240,174,80,22);
cshanchu.select(0);
btnshanchu.addActionListener(this);
Strings=tshanchu.getText();
请输入要删除的图书"
删除功能"
+"
if(!
rs.next())
没有该图书"