图书管理系统实验报告+源代码Word格式文档下载.docx
《图书管理系统实验报告+源代码Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《图书管理系统实验报告+源代码Word格式文档下载.docx(46页珍藏版)》请在冰豆网上搜索。
Borrow(读者号,ISBN,借阅日期,归还日期,办理人,归还办理人)
(横线为主键,蓝色字体为外键)
管理员信息表:
Administrator(管理员编号,管理员密码,管理员姓名,性别,年龄,联系电话)
数据库的连接:
publicclassDataclass{
privatestaticConnectionconn=null;
StringdriverName="
com.microsoft.sqlserver.jdbc.SQLServerDriver"
;
StringdbURL="
jdbc:
sqlserver:
//localhost:
1433;
DatabaseName=Java课程设计数据库"
StringuserName="
sa"
//默认用户名
StringuserPwd="
1111"
//密码
//构造函数
publicDataclass(){//用于连接数库
try{
if(conn==null){
Class.forName(driverName);
conn=DriverManager.getConnection(dbURL,userName,userPwd);
}
else
return;
catch(Exceptione){//捕获数据库连接不成功异常
e.printStackTrace();
}
publicstaticResultSetexecuteQuery(Stringsql){//传送返回结果集的SQL语句
if(conn==null)
newDataclass();
//调用构造函数连接数据库
returnconn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE).executeQuery(sql);
//返回可滚动的并发事件
}
catch(SQLExceptione){//捕获访问数据库失败异常
e.printStackTrace();
returnnull;
publicstaticbooleanexecuteUpdate(Stringsql){//发送不返回结果集的SQL语句
newDataclass();
inti=conn.createStatement().executeUpdate(sql);
if(i!
=0)
returntrue;
System.out.println(e.getMessage());
returnfalse;
//不成功返回-1
returnfalse;
publicstaticvoidclose(){//断开数据库连接方法
conn.close();
catch(SQLExceptione){
finally{
conn=null;
//设置数据库连接对象为空
}
登录界面的实现:
代码为:
publicclassKCSJDLextendsJFrame{
JTextFieldtextField1;
JPasswordFieldtextField2;
publicKCSJDL(){
try{//设置Windows观感
UIManager.setLookAndFeel("
com.sun.java.swing.plaf.windows.WindowsLookAndFeel"
);
}catch(Exceptione){
System.out.println("
LookandFeelException"
System.exit(0);
setTitle("
图书管理系统登录界面"
setBounds(400,200,376,300);
setResizable(false);
Containercon=getContentPane();
JLabellblNewLabel=newJLabel();
lblNewLabel.setIcon(newImageIcon("
images/head.jpg"
));
JPanelJpanel1=newJPanel();
Jpanel1.setLayout(newGridLayout(2,1,0,0));
JPanelJpanel1_1=newJPanel();
Jpanel1_1.setLayout(newFlowLayout(FlowLayout.CENTER,5,30));
Jpanel1.add(Jpanel1_1);
JLabellblNewLabel2=newJLabel("
管理员编号:
"
Jpanel1_1.add(lblNewLabel2);
textField1=newJTextField();
Jpanel1_1.add(textField1);
textField1.setColumns(25);
JPanelJpanel1_2=newJPanel();
Jpanel1_2.setLayout(newFlowLayout(FlowLayout.CENTER,5,20));
Jpanel1.add(Jpanel1_2);
JLabellabel_1=newJLabel("
管理员密码:
Jpanel1_2.add(label_1);
textField2=newJPasswordField();
Jpanel1_2.add(textField2);
textField2.setColumns(25);
JPanelJpanel2=newJPanel();
JLabellabel=newJLabel("
"
JButtonbutton1=newJButton("
登录"
JButtonbutton2=newJButton("
注册"
Jpanel2.add(label);
Jpanel2.add(button1);
Jpanel2.add(button2);
con.add(lblNewLabel,"
North"
con.add(Jpanel1,"
Center"
con.add(Jpanel2,"
South"
textField1.addActionListener(newKCSJDLEvent(this));
textField2.addActionListener(newKCSJDLEvent(this));
button1.addActionListener(newKCSJDLEvent(this));
button2.addActionListener(newKCSJDLEvent(this));
publicstaticvoidmain(String[]args){
KCSJDLtest=newKCSJDL();
test.setVisible(true);
test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
注册界面的实现:
publicclassKCSJZCextendsJFrame{
privateButtonGroupbuttonGroup=newButtonGroup();
JTextFieldtextField1_1;
JTextFieldtextField2_1;
JTextFieldtextField3_1;
JTextFieldtextField4_1;
JTextFieldtextField4_2;
JRadioButtonradioButton1;
JRadioButtonradioButton2;
publicKCSJZC(){
注册"
setBounds(400,200,500,550);
images/ZC.png"
JPanelJpanel=newJPanel();
Jpanel.setBorder(newTitledBorder(null,"
管理员注册"
TitledBorder.CENTER,TitledBorder.TOP,null,null));
Jpanel.setLayout(newGridLayout(5,1,0,0));
con.add(Jpanel,"
JPanelJ1=newJPanel();
J1.setLayout(newFlowLayout(FlowLayout.CENTER,5,20));
Jpanel.add(J1);
JLabellb1_1=newJLabel("
管理员编号:
textField1_1=newJTextField();
textField1_1.setColumns(20);
JLabellb1_2=newJLabel("
J1.add(lb1_1);
J1.add(textField1_1);
J1.add(lb1_2);
JPanelJ2=newJPanel();
J2.setLayout(newFlowLayout(FlowLayout.CENTER,5,20));
Jpanel.add(J2);
JLabellb2_1=newJLabel("
管理员密码:
textField2_1=newJTextField();
textField2_1.setColumns(20);
JLabellb2_2=newJLabel("
确认密码:
JTextFieldtextField2_2=newJTextField();
textField2_2.setColumns(20);
J2.add(lb2_1);
J2.add(textField2_1);
J2.add(lb2_2);
J2.add(textField2_2);
JPanelJ3=newJPanel();
J3.setLayout(newFlowLayout(FlowLayout.CENTER,5,20));
Jpanel.add(J3);
JLabellb3_1=newJLabel("
管理员姓名:
textField3_1=newJTextField();
textField3_1.setColumns(20);
JLabellb3_2=newJLabel("
性别:
radioButton1=newJRadioButton("
男"
//"
buttonGroup.add(radioButton1);
JLabellb3_3=newJLabel("
radioButton2=newJRadioButton("
女"
buttonGroup.add(radioButton2);
J3.add(lb3_1);
J3.add(textField3_1);
J3.add(lb3_2);
J3.add(radioButton1);
J3.add(lb3_3);
J3.add(radioButton2);
JPanelJ4=newJPanel();
J4.setLayout(newFlowLayout(FlowLayout.CENTER,5,20));
Jpanel.add(J4);
JLabellb4_1=newJLabel("
年龄:
textField4_1=newJTextField();
textField4_1.setColumns(20);
JLabellb4_2=newJLabel("
联系电话:
textField4_2=newJTextField();
textField4_2.setColumns(20);
J4.add(lb4_1);
J4.add(textField4_1);
J4.add(lb4_2);
J4.add(textField4_2);
JPanelJ5=newJPanel();
J5.setLayout(newFlowLayout(FlowLayout.CENTER,5,20));
Jpanel.add(J5);
JButtonJb1=newJButton("
Jb1.setIcon(newImageIcon("
images/JY.png"
Jb1.addActionListener(newenrollEvent(this));
JButtonJb2=newJButton("
返回登录界面"
Jb2.setIcon(newImageIcon("
images/GH.png"
Jb2.addActionListener(newenrollEvent(this));
J5.add(Jb1);
J5.add(Jb2);
首页界面的实现:
classKCSJMainextendsJFrame{
JButtonJbutton[]=newJButton[6];
JPanelJpanel;
JPanelJpanel1;
JPanelJpanel2;
JPanelJpanel3;
JPanelJpanel4;
JPanelJpanel5;
JTextFieldtextField_1;
JTextFieldtextField_2;
JTextFieldtextField_3;
JTextFieldtextField_4;
JTextFieldtextField_5;
publicKCSJMain(){
图书管理系统"
setBounds(150,150,950,620);
Stringstr[]={"
首页"
"
教师信息管理"
图书信息管理"
借书登记"
还书登记"
催还"
};
StringPfilename[]={"
images/c6.png"
images/p1.png"
images/p2.png"
images/p3.png"
images/p4.png"
images/p5.png"
for(inti=0;
i<
str.length;
i++){
Jbutton[i]=newJButton(str[i]);
Jbutton[i].setIcon(newImageIcon(Pfilename[i]));
Jbutton[i].setHorizontalTextPosition(JButton.CENTER);
Jbutton[i].setVerticalTextPosition(JButton.BOTTOM);
JPanelpanel=newJPanel();
panel.setBorder(newLineBorder(Color.LIGHT_GRAY));
panel.add(Jbutton[i]);
//左边
JPaneljpanel=newJPanel();
jpanel.setBorder(newLineBorder(Color.LIGHT_GRAY));
jpanel.setLayout(newBoxLayout(jpanel,BoxLayout.Y_AXIS));
JPanelpanel_1=newJPanel();
panel_1.setBorder(newTitledBorder(UIManager.getBorder("
TitledBorder.border"
),"
欢迎使用图书管理系统"
TitledBorder.CENTER,TitledBorder.TOP,null,newColor(0,0,0)));
jpanel.add(panel_1);
JTextAreatextArea=newJTextArea();
textArea.setColumns(30);
textArea.setRows(5);
textArea.setText("
【功能简要介绍】:
\n该系统可以对教师读者以及图\n书进行管理,包括增删改查等功能\n,方便于管理,是管理员的小小\n助手!
textArea.setBackground(SystemColor.control);
textArea.setEditable(false);
panel_1.add(textArea);
JPanelpanel_2=newJPanel();
panel_2.setBorder(newTitledBorder(null,"
您好,欢迎登录图书管理系统"
jpanel.add(panel_2);
JPaneljp=newJPanel();
jp.setLayout(newGridLayout(5,1,0,0));
panel_2.add(jp);
Stringstr1[]={"
性别:
年龄:
JPanelJP[]=newJPanel[str1.length];
JLabellabel[]=newJLabel[str1.length];
str1.length;
JP[i]=newJPanel();
label[i]=newJLabel(str1[i]);
JP[i].add(label[i]);
jp.add(JP[i]);
textField_1=newJTextField();
textField_1.setColumns(20);
JP[0].add(textField_1);
textField_2=newJTextField();
textField_2.setColumns(20);
JP[1].add(textField_2);
textField_3=newJTextField();
textField_3.setColumns