JAVA课程设计基于UI的图书管理系统.docx
《JAVA课程设计基于UI的图书管理系统.docx》由会员分享,可在线阅读,更多相关《JAVA课程设计基于UI的图书管理系统.docx(66页珍藏版)》请在冰豆网上搜索。
JAVA课程设计基于UI的图书管理系统
JAVA
课程设计报告
(图书管理系统)
1.系统目的与功能
(1)本系统通链接ACCESS完成对用户信息和图书信息的管理,并制作可视化界面进行操作。
(2)系统主要实现的功能有用户的登陆,图书的插入、修改、删除、查看、借阅、归还。
2.开发工具
开发工具使用Eclipse作为主用开发环境,并使用VE相关制作系统界面部分。
3.系统说明(以下名字都是类名)
1.Access类来进行界面切换,数据库操作等。
2.MainMenu、Regsdit类是系统登陆界面和用户注册界面。
3.MainCl类是系统的主要界面。
4.Insert、Look、Update、Delete、Sendbook、Backbook类分别用来进行图书插入、图书信息查看、图书信息修改、图书删除、借阅图书、归还图书。
5.程序代码
Access类
packageaccess;
importjava.sql.*;
importjavax.swing.JLabel;
importjavax.swing.JPanel;
importjavax.swing.JTextField;
importview.*;
publicclassAccess{
Connectionconn=null;
Statementstmt=null;
ResultSetrs=null;
PreparedStatementps=null;
Stringusername;
Stringtemp;
Stringpassword;
Stringbookname;
Stringbookid;
Stringauthor;
Stringpublisher;
Stringname;
intcount;
JTextFieldtest;
JTextFieldtest1;
JLabeljLabel;
JPaneljpane;
intresult=0;
publicAccess(Stringusername,Stringpassword){
this.username=username;
this.password=password;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Stringstrurl="jdbc:
odbc:
driver={MicrosoftAccessDriver(*.mdb)};DBQ=D:
\\workspace\\bookmis.mdb";
conn=DriverManager.getConnection(strurl);
stmt=conn.createStatement();
}catch(Exceptione){
}
}
publicAccess(Stringbookname,Stringbookid,Stringauthor,Stringpublisher,JTextFieldtest){
this.bookname=bookname;
this.bookid=bookid;
this.author=author;
this.publisher=publisher;
this.test=test;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Stringstrurl="jdbc:
odbc:
driver={MicrosoftAccessDriver(*.mdb)};DBQ=D:
\\workspace\\bookmis.mdb";
conn=DriverManager.getConnection(strurl);
stmt=conn.createStatement();
}catch(Exceptione){
}
}
publicAccess(Stringbookname,Stringbookid,Stringauthor,Stringpublisher,JLabeljlabel){
this.bookname=bookname;
this.bookid=bookid;
this.author=author;
this.publisher=publisher;
this.jLabel=jlabel;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Stringstrurl="jdbc:
odbc:
driver={MicrosoftAccessDriver(*.mdb)};DBQ=D:
\\workspace\\bookmis.mdb";
conn=DriverManager.getConnection(strurl);
stmt=conn.createStatement();
}catch(Exceptione){
}
}
publicAccess(){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Stringstrurl="jdbc:
odbc:
driver={MicrosoftAccessDriver(*.mdb)};DBQ=D:
\\workspace\\bookmis.mdb";
conn=DriverManager.getConnection(strurl);
stmt=conn.createStatement();
}catch(Exceptione){
}
}
publicAccess(Stringtemp,JTextFieldtest1){
this.temp=temp;
this.test1=test1;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Stringstrurl="jdbc:
odbc:
driver={MicrosoftAccessDriver(*.mdb)};DBQ=D:
\\workspace\\bookmis.mdb";
conn=DriverManager.getConnection(strurl);
stmt=conn.createStatement();
}catch(Exceptione){
}
}
publicAccess(Stringaname,JPaneljpane,JLabeljLabel){
name=aname;
this.jpane=jpane;
this.jLabel=jLabel;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Stringstrurl="jdbc:
odbc:
driver={MicrosoftAccessDriver(*.mdb)};DBQ=D:
\\workspace\\bookmis.mdb";
conn=DriverManager.getConnection(strurl);
stmt=conn.createStatement();
}catch(Exceptione){
}
}
publicAccess(Stringaname,JLabeljLabel){
name=aname;
this.jLabel=jLabel;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Stringstrurl="jdbc:
odbc:
driver={MicrosoftAccessDriver(*.mdb)};DBQ=D:
\\workspace\\bookmis.mdb";
conn=DriverManager.getConnection(strurl);
stmt=conn.createStatement();
}catch(Exceptione){
}
}
publicvoidregsdit(){
try{
result=stmt.executeUpdate("insertintouserinform(username,password)values('"+username+"','"+password+"')");
}catch(SQLExceptione){
//TODO自动生成catch块
newFail().getJDialog();
}
if(result==1){
MainMenumainmenu=newMainMenu();
mainmenu.getJFrame();
}else{
}
}
publicvoidlogin(){
try{
rs=stmt.executeQuery("select*fromuserinformwhereusername='"+username+"'andpassword='"+password+"'");
if(rs.next())
{
MainClmaincl=newMainCl();
maincl.getJFrame();
}
else{
LoginFailloginfail=newLoginFail();
loginfail.getJDialog();
}
}catch(SQLExceptione){
//TODO自动生成catch块
e.printStackTrace();
}
}
publicvoidinsert(){
try{
result=stmt.executeUpdate("insertintobookmis(bookname,num,auther,publisher)values('"+bookname+"','"+bookid+"','"+author+"','"+publisher+"')");
}catch(SQLExceptione){
//TODO自动生成catch块
e.printStackTrace();
}
if(result==1){
test.setText("插入成功");
}
elsetest.setText("插入失败");
}
publicvoidlook(){
Lookalook=newLook();
try{
rs=stmt.executeQuery("select*frombookmis");
while(rs.next())
{
bookname=rs.getString("bookname");
bookid=rs.getString("num");
author=rs.getString("auther");
publisher=rs.getString("publisher");
count=rs.getInt("count");
Stringacount=Integer.toString(count);
Stringtemp="书名:
"+bookname+"编号:
"+bookid+"作者:
"+author+"出版社:
"+publisher+"数量:
"+acount;
alook.getList().add(temp);
alook.getJFrame();
alook.getList().add("\n\n\n\n");
}
}catch(Exceptione){
}
}
publicvoiddelete(){
try{result=0;
result=stmt.executeUpdate("deletefrombookmiswherebookname='"+temp+"'");
}catch(Exceptione){
}
if(result==1){
test1.setText("删除成功");
}
elsetest1.setText("删除失败,你输入的书名有误");
}
publicvoidupdate(){
try{
rs=stmt.executeQuery("select*frombookmiswherebookname='"+name+"'");
if(rs.next())
{
stmt.executeUpdate("deletefrombookmiswherebookname='"+name+"'");
jpane.setVisible(true);
}
else
{
jLabel.setText("请输入正确的书名");
}
}catch(SQLExceptione){
}
}
publicvoidaupdate(){
try{
result=stmt.executeUpdate("insertintobookmis(bookname,num,auther,publisher)values('"+bookname+"','"+bookid+"','"+author+"','"+publisher+"')");
}catch(SQLExceptione){
//TODO自动生成catch块
e.printStackTrace();
}
if(result==1){
jLabel.setText("修改成功");
}
elsejLabel.setText("修改失败");
}
publicvoidsendbook(){
try{
rs=stmt.executeQuery("select*frombookmiswherebookname='"+name+"'");
if(rs.next())
{
intbcount=rs.getInt("count");
if(bcount<=0){
jLabel.setText("书已经全部借完");return;
}
stmt.executeUpdate("updatebookmissetcount=count-1wherebookname='"+name+"'");
jLabel.setText("借阅成功");
}
else
{
jLabel.setText("没有这本书");
}
}catch(SQLExceptione){
e.printStackTrace();
}
}
publicvoidbackbook(){
try{
stmt.executeUpdate("updatebookmissetcount=count+1wherebookname='"+name+"'");
jLabel.setText("还书成功");
}catch(SQLExceptione){
}
}
MainMenu类
packageview;
importjavax.swing.JFrame;
importjavax.swing.JPanel;
importjava.awt.Dimension;
importjavax.swing.JLabel;
importjava.awt.Rectangle;
importjavax.swing.JTextField;
importjavax.swing.JButton;
importaccess.Access;
importjavax.swing.JPasswordField;
publicclassMainMenu{
privateJFramejFrame=null;//@jve:
decl-index=0:
visual-constraint="159,78"
privateJPaneljContentPane=null;
privateJLabeljLabel=null;
privateJTextFieldjTextField=null;
privateJLabeljLabel1=null;
privateJButtonjButton=null;
privateJButtonjButton1=null;
privateJPasswordFieldjPasswordField=null;
/**
*ThismethodinitializesjFrame
*
*@returnjavax.swing.JFrame
*/
publicJFramegetJFrame(){
if(jFrame==null){
jFrame=newJFrame();
jFrame.setSize(newDimension(461,320));
jFrame.setTitle("图书管理系统登陆界面");
jFrame.setContentPane(getJContentPane());
jFrame.setVisible(true);
}
returnjFrame;
}
/**
*ThismethodinitializesjContentPane
*
*@returnjavax.swing.JPanel
*/
privateJPanelgetJContentPane(){
if(jContentPane==null){
jLabel1=newJLabel();
jLabel1.setBounds(newRectangle(30,121,167,30));
jLabel1.setText("密码");
jLabel=newJLabel();
jLabel.setBounds(newRectangle(30,45,167,31));
jLabel.setText("用户名");
jContentPane=newJPanel();
jContentPane.setLayout(null);
jContentPane.add(jLabel,null);
jContentPane.add(getJTextField(),null);
jContentPane.add(jLabel1,null);
jContentPane.add(getJButton(),null);
jContentPane.add(getJButton1(),null);
jContentPane.add(getJPasswordField(),null);
}
returnjContentPane;
}
/**
*ThismethodinitializesjTextField
*
*@returnjavax.swing.JTextField
*/
privateJTextFieldgetJTextField(){
if(jTextField==null){
jTextField=newJTextField();
jTextField.setBounds(newRectangle(211,44,223,35));
}
returnjTextField;
}
/**
*ThismethodinitializesjButton
*
*@returnjavax.swing.JButton
*/
privateJButtongetJButton(){
if(jButton==null){
jButton=newJButton();
jButton.setBounds(newRectangle(61,211,121,32));
jButton.setText("登陆");
jButton.addActionListener(newjava.awt.event.ActionListener(){
publicvoidactionPerformed(java.awt.event.ActionEvente){
Stringusername=jTextField.getText();
Stringpassword=jPasswordField.getText();
Accessaccess=newAccess(username,password);
access.login();
jFrame.setVisible(false);
}
});
}
returnjButton;
}
/**
*ThismethodinitializesjButton1
*