源代码.docx
《源代码.docx》由会员分享,可在线阅读,更多相关《源代码.docx(12页珍藏版)》请在冰豆网上搜索。
![源代码.docx](https://file1.bdocx.com/fileroot1/2023-3/19/b5072f14-1f87-46ea-84c4-44ea055becac/b5072f14-1f87-46ea-84c4-44ea055becac1.gif)
源代码
登陆界面
classLoginextendsJFrameimplementsActionListener
{Containercp=null;
JFramef=null;
JButtonj1,j2;
JTextFieldt1;
JPasswordFieldt2;
JLabeljlable1,jlable2;
Colorc;
JPaneljp1,jp2;
publicvoidconfirm()//验证用户和密码是否存在
{try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(ClassNotFoundExceptione){System.out.println("加载驱动程序失败!
");}
try{Stringurl="jdbc:
odbc:
driver={MicrosoftAccessDriver(*.mdb)};DBQ=Book.mdb";//直接使用当前类目录下的数据库文件
Connectioncon=DriverManager.getConnection(url);
Statementsql=con.createStatement();
Stringuname=t1.getText().trim();
StringMima=t2.getText().trim();
StringqueryMima="select*fromuserwhere用户名='"+uname+"'and密码='"+Mima+"'";
ResultSetrs=sql.executeQuery(queryMima);
if(rs.next())
{newBook(uname);
f.hide();
con.close();
}else{JOptionPane.showMessageDialog(null,"该用户不存在","提示!
",
JOptionPane.YES_NO_OPTION);}
t1.setText("");
t2.setText("");
}catch(SQLExceptiong)
{System.out.println("ECode"+g.getErrorCode());
System.out.println("EM"+g.getMessage());}}
主界面
classBookextendsJFrameimplementsActionListener
{JButtonQueryBook=newJButton("期刊查询");
JButtonBookIn=newJButton("期刊入库");
JButtonRemoveBook=newJButton("期刊删除");
JButtonBookBrower=newJButton("期刊概览");
JButtonUpdateMima=newJButton("修改密码");
JMenuBarmb=newJMenuBar();//菜单栏
JPaneljp=newJPanel();//用来填放子模块
Containercp=getContentPane();
Stringusername;
Book(Stringusername)
{this.username=username;
mb.add(QueryBook);
mb.add(BookIn);
mb.add(RemoveBook);
mb.add(BookBrower);
mb.add(UpdateMima);
cp.add(mb,"North");
jp.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.blue,2),null,TitledBorder.CENTER,TitledBorder.TOP));
jp.setLayout(newBorderLayout());
JLabellabel1=newJLabel(newImageIcon("4.jpg"));
jp.add(label1);
JLabelJL=newJLabel("欢迎登陆",SwingConstants.CENTER);
jp.add(JL,"North");
JScrollPanescrollpane=newJScrollPane(jp);
cp.add(scrollpane);
setTitle("欢迎登陆");
Toolkitkit=Toolkit.getDefaultToolkit();
Dimensionscreen=kit.getScreenSize();
intx=screen.width;/*取得显示器窗口的宽度*/
inty=screen.height;/*取得显示器窗口的高度*/
//setSize(x,y);/*让系统窗口平铺整个显示器窗口*/
setSize(600,600);
intxcenter=(x-600)/2;
intycenter=(y-600)/2;
setLocation(xcenter,ycenter);/*显示在窗口中央*/
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//注册临听器
QueryScore.addActionListener(this);
QueryXuefen.addActionListener(this);
jiangfa.addActionListener(this);
xuanke.addActionListener(this);
gaiMima.addActionListener(this);}
publicvoidactionPerformed(ActionEvente)
{Stringcmd=e.getActionCommand();
if(cmd.equals("期刊查询")){newQueryBook();}
if(cmd.equals("期刊入库")){newBookIn();}
if(cmd.equals("期刊删除")){newRemoveBook();}
if(cmd.equals("期刊概览")){newBookBrower().showRecord();}
if(cmd.equals("期刊密码")){newUpdateMima(username);}}
期刊入库
classBookInimplementsActionListener
{JFramef3;
Containercp;
JPaneljp1,jp2,jp3,jp4,jp,jpanelWest;
JButtonjbt1,jbt2;//按钮:
确定、取消、
JLabellabel;//标签
JTextFieldtf1,tf2,tf3,tf4,tf5,tf6;//定义文本框
JLabellabel1,label2,label3,label4;
Stringsno;
publicvoidinsertRecord()
{if(tf1.getText().equals("")||tf2.getText().equals("")||tf3.getText().equals("")||tf4.getText().equals("")||tf5.getText().equals("")||tf6.getText().equals(""))
{JOptionPane.showMessageDialog(f3,"请填写图书资料");
return;}
try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(ClassNotFoundExceptione){System.out.println("加载驱动程序失败!
");}
try{
Stringurl="jdbc:
odbc:
driver={MicrosoftAccessDriver(*.mdb)};DBQ=Book.mdb";//直接使用当前类目录下的数据库文件
Connectioncon=DriverManager.getConnection(url);
Statementsql;
Strings="insertintobookvalues('"+tf1.getText()+"','"+tf2.getText()+"','"+
tf3.getText()+"','"+tf4.getText()+"','"+tf5.getText()+"','"+tf6.getText()+"');";//查询输入的图书号是否在数据库中存在
Stringquery="select*frombookwhere期刊号='"+tf2.getText()+"'";
sql=con.createStatement();
ResultSetrs=sql.executeQuery(query);//返回查询结果集
booleanmoreRecords=rs.next();//判断结果集是否有数据
if(moreRecords)
{JOptionPane.showMessageDialog(f3,"期刊号已经被使用,请重新输入");
con.close();
tf2.setText("");
return;}
intinsert=sql.executeUpdate(s);
if(insert==1)
{JOptionPane.showMessageDialog(null,"期刊信息录入成功!
");
tf1.setText("");
tf2.setText("");
tf3.setText("");
tf4.setText("");
tf5.setText("");
tf6.setText("");
}}catch(SQLExceptiong)
{System.out.println("ECode"+g.getErrorCode());
System.out.println("EM"+g.getMessage());}}
期刊借阅
classBookBrowerimplementsActionListener
{JFramef;
Containercp;
JPaneljpS,jpanelWest;
JButtonjbt1,jbt2;//按钮,确定,返回
JLabellabel,L;//标签
JTabletable;//用来接收数据库中返回的信息
ObjectcolumnName[]={"期刊名","期刊号","单价","作者","出版社","入库时间"};
Objectar[][]=newObject[80][6];
Stringsno;
Stringcount="xx";
publicvoidshowRecord()
{while(i>=0)
{ar[i][0]="";
ar[i][1]="";
ar[i][2]="";
ar[i][3]="";
ar[i][4]="";
ar[i][5]="";
i--;}
i=0;
try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(ClassNotFoundExceptione){System.out.println("加载驱动程序失败!
");}
try{Stringurl="jdbc:
odbc:
driver={MicrosoftAccessDriver(*.mdb)};DBQ=Book.mdb";//直接使用当前类目录下的数据库文件
Connectioncon=DriverManager.getConnection(url);
Strings="select*frombook";
Statementsql=con.createStatement();
ResultSetrs=sql.executeQuery(s);
while(rs.next())
{Stringbname=rs.getString
(1);
Stringbno=rs.getString
(2);
Stringprice=rs.getString(3);
Stringwriter=rs.getString(4);
Stringpublish=rs.getString(5);
Stringindate=rs.getString(6);
ar[i][0]=bname;
ar[i][1]=bno;
ar[i][2]=price;
ar[i][3]=writer;
ar[i][4]=publish;
ar[i][5]=indate;
i++;}
count=""+i+"";
L.setText("书库现在共有期刊"+count+"本");
f.repaint();
con.close();
}catch(SQLExceptiong)
{System.out.println("ECode"+g.getErrorCode());
System.out.println("EM"+g.getMessage());}}
期刊删除
classRemoveBookimplementsActionListener
{JFramef;
Containercp;
JPaneljpS,jpanelWest;
JButtonjbt1,jbt2,jbt3;//按钮,查询、取消、修改
JLabellabel,L;//标签:
请输入学号
JTextFieldtf;//定义文本框
JTabletable;//用来接收数据库中返回的信息
ObjectcolumnName[]={"期刊名","期刊号","单价","作者","出版社","入库时间"};
Objectar[][]=newObject[80][6];
Stringcount="xx";
publicvoidshowRecord(Stringql)
{while(i>=0)
{ar[i][0]="";
ar[i][1]="";
ar[i][2]="";
ar[i][3]="";
ar[i][4]="";
ar[i][5]="";
i--;}
i=0;
try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(ClassNotFoundExceptione){System.out.println("加载驱动程序失败!
");}
try{Stringurl="jdbc:
odbc:
driver={MicrosoftAccessDriver(*.mdb)};DBQ=Book.mdb";//直接使用当前类目录下的数据库文件
Connectioncon=DriverManager.getConnection(url);
Statementsql;
Strings="select*frombookwhere期刊名='"+ql+"'";
sql=con.createStatement();
ResultSetrs=sql.executeQuery(s);
while(rs.next())
{Stringbname=rs.getString
(1);
Stringbno=rs.getString
(2);
Stringprice=rs.getString(3);
Stringwriter=rs.getString(4);
Stringpublish=rs.getString(5);
Stringindate=rs.getString(6);
ar[i][0]=bname;
ar[i][1]=bno;
ar[i][2]=price;
ar[i][3]=writer;
ar[i][4]=publish;
ar[i][5]=indate;
i++;}
count=""+i+"";
L.setText("该种期刊共有"+count+"本");
f.repaint();
con.close();System.out.println(ar[0][1]);
}catch(SQLExceptiong)
{System.out.println("ECode"+g.getErrorCode());
System.out.println("EM"+g.getMessage());}}
publicvoiddeleteRecord(intindex){
try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
catch(ClassNotFoundExceptione){System.out.println("加载驱动程序失败!
");}
try{Stringurl="jdbc:
odbc:
driver={MicrosoftAccessDriver(*.mdb)};DBQ=Book.mdb";//直接使用当前类目录下的数据库文件
Connectioncon=DriverManager.getConnection(url);
Statementsql;
Stringql=(String)(ar[index][1]);
Strings="delete*frombookwhere期刊号='"+ql+"'";
sql=con.createStatement();
intdel=sql.executeUpdate(s);
if(del==1)
{JOptionPane.showMessageDialog(null,"删除成功!
",
"信息",JOptionPane.YES_NO_OPTION);
}con.close();
f.repaint();
}catch(SQLExceptiong)
{System.out.println("ECode"+g.getErrorCode());
System.out.println("EM"+g.getMessage());}}
期刊查询
classQueryBookimplementsActionListener
{JFramef3;
Containercp;
JPaneljp1,jp2,jp3,jp4,jp,jpanelWest;
JButtonjbt1,jbt2;//按钮,确定、取消
JLabellabel;//标签:
请输入期刊号
JTextFieldtf,tf1,tf2,tf3,tf4,tf5,tf6;//定义文本框
JLabellabel1,label2,label3,label4;
publicvoidshowRecord(){
try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(ClassNotFoundExceptione){System.out.println("加载驱动程序失败!
");}try{Stringurl="jdbc:
odbc:
driver={MicrosoftAccessDriver(*.mdb)};DBQ=Book.mdb";//直接使用当前类目录下的数据库文件
Connectioncon=DriverManager.getConnection(url);
Statementsql;
Stringql=tf.getText().trim();
Strings="select*frombookwhere期刊号='"+ql+"'";
sql=con.createStatement();
ResultSetrs=sql.executeQuery(s);
if(rs.next())
{Stringbname=rs.getString
(1);
Stringbno=rs.getString
(2);
Stringprice=rs.getString(3);
Stringwriter=rs.getString(4);
Stringpublish=rs.getString(5);
Stringindate=rs.getString(6);
tf1.setText(bname);
tf2.setText(bno);
tf3.setText(price);
tf4.setText(writer);
tf5.setText(publish);
tf6.setText(indate);}
else
{JOptionPane.showMessageDialog(null,"您输入的期刊号不存在,请重新输入",
"输入错误",JOptionPane.YES_NO_OPTION);
}con.close();
}catch(SQLExceptiong)
{System.out.println("ECode"+g.getErrorCode());
System.out.println("EM"+g.getMessage());}
tf1.setEditable(false);
tf