版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
千里之行,始于足下讓知識帶有溫度。第第2頁/共2頁精品文檔推薦基于java的圖書管理系統(tǒng)源代碼基于java的圖書管理系統(tǒng)源代碼聲明:本系統(tǒng)是基于C/S的圖書管理系統(tǒng),主要使用的是Oracle數據庫,下面附全部實現代碼
packagelibrary;
importjava.awt.BorderLayout;
importjava.awt.Container;
importjava.awt.GridLayout;
importjava.awt.event.ActionEvent;import
java.awt.event.ActionListener;importjava.sql.ResultSet;
importjavax.swing.JButton;
importjavax.swing.JComboBox;
importjavax.swing.JFrame;
importjavax.swing.JLabel;
importjavax.swing.JOptionPane;importjavax.swing.JPanel;
importjavax.swing.JTextField;publicclassbook_addextendsJFrameimplementsActionListener{
DataBaseManagerdb=newDataBaseManager();
ResultSetrs;
JPanelpanel1,panel2;
JLabelbook_id_label,book_name_label,author_label,
press_label,press_date_label,price_label,book_num_label,borrowed_num_label,a
ddress;
JTextFieldbook_id_TextField,book_name_TextField,author_TextField,press_TextField,press_date_TextField,price_TextField,book_num_TextField,
borrowed_count;
JComboBoxaddresst;
Containerc;
JButtonclear,add,exit;
publicbook_add()
{
super("添加圖書信息");
c=getContentPane();
c.setLayout(newBorderLayout());
book_id_label=newJLabel("編號",JLabel.CENTER);
book_name_label=newJLabel("名稱",JLabel.CENTER);
1
author_label=newJLabel("",JLabel.CENTER);
press_label=newJLabel("出版社",JLabel.CENTER);
press_date_label=newJLabel("出版日期",JLabel.CENTER);
price_label=newJLabel("價格",JLabel.CENTER);
book_num_label=newJLabel("庫存數",JLabel.CENTER);
borrowed_num_label=newJLabel("已借閱數",JLabel.CENTER);
address=newJLabel("藏書地址",JLabel.CENTER);
book_id_TextField=newJTextField(15);
book_name_TextField=newJTextField(15);
author_TextField=newJTextField(15);press_TextField=newJTextField(15);press_date_TextField=newJTextField(15);price_TextField=newJTextField(15);book_num_TextField=newJTextField(15);borrowed_count=newJTextField(15);borrowed_count.setText("0");
addresst=newJComboBox();
addresst.addItem("揚子津圖書館");addresst.addItem("荷花池圖書館");addresst.addItem("瘦西湖圖書館");addresst.addItem("淮海路圖書館");
panel1=newJPanel();
panel1.setLayout(newGridLayout(9,2));panel1.add(book_id_label);
panel1.add(book_id_TextField);
panel1.add(book_name_label);
panel1.add(book_name_TextField);
panel1.add(press_label);
panel1.add(press_TextField);
panel1.add(author_label);
panel1.add(author_TextField);
panel1.add(press_date_label);
panel1.add(press_date_TextField);
panel1.add(price_label);
panel1.add(price_TextField);
panel1.add(book_num_label);
panel1.add(book_num_TextField);
panel1.add(borrowed_num_label);
panel1.add(borrowed_count);
panel1.add(address);
panel1.add(addresst);
panel2=newJPanel();
panel2.setLayout(newGridLayout(1,3));clear=newJButton("清空");
2
clear.addActionListener(this);
add=newJButton("添加");
add.addActionListener(this);
exit=newJButton("退出");
exit.addActionListener(this);
panel2.add(clear);
panel2.add(add);
panel2.add(exit);
c.add(panel1,BorderLayout.CENTER);
c.add(panel2,BorderLayout.SOUTH);setVisible(true);
}
publicvoidactionPerformed(ActionEvente)
{
if(e.getSource()==exit)
{
this.dispose();
}
elseif(e.getSource()==clear)
{
book_id_TextField.setText("");
book_name_TextField.setText("");
author_TextField.setText("");
press_TextField.setText("");
press_date_TextField.setText("");
price_TextField.setText("");
book_num_TextField.setText("");
}
elseif(e.getSource()==add)
{
if(book_id_TextField.getText().trim().equals(""))
{
JOptionPane.showMessageDialog(null,"書號不能為空");
}
elseif(book_name_TextField.getText().trim().equals("")){
JOptionPane.showMessageDialog(null,"書名不能為空");
}
elseif(author_TextField.getText().trim().equals("")){
JOptionPane.showMessageDialog(null,"不能為空");
}
elseif(press_TextField.getText().trim().equals(""))
3
{
JOptionPane.showMessageDialog(null,"出版社不能為空");
}
elseif(press_date_TextField.getText().trim().equals("")){
JOptionPane.showMessageDialog(null,"出版日期不能為空");}
elseif(price_TextField.getText().trim().equals(""))
{
JOptionPane.showMessageDialog(null,"價格不能為空");
}
elseif(book_num_TextField.getText().trim().equals("")){
JOptionPane.showMessageDialog(null,"庫存不能為空");
}
elseif(borrowed_count.getText().trim().equals(""))
{
JOptionPane.showMessageDialog(null,"借閱數不能為空");
}
else{
try{
StringstrSQL="insertinto
book(book_id,book_name,press,author,press_date,price,book_count,borrowed_count,
store_address)values('"
+book_id_TextField.getText().trim()
+"','"
+book_name_TextField.getText().trim()
+"','"
+press_TextField.getText().trim()
+"','"
+author_TextField.getText().trim()
+"','"
+press_date_TextField.getText().trim()
+"','"
+price_TextField.getText().trim()
+"','"
+book_num_TextField.getText().trim()
+"','"
+borrowed_count.getText().trim()
+"','"
+addresst.getSelectedItem()+"')";
if(db.updateSql(strSQL))
{
4
this.dispose();
JOptionPane.showMessageDialog(null,"添加圖書勝利");
}
else
{
JOptionPane.showMessageDialog(null,"添加圖書失敗");
this.dispose();
}
db.closeConnection();
}catch(Exceptionex)
{
System.out.println(ex.toString());}
}
}
}
}
packagelibrary;
importjavax.swing.*;
importjava.awt.*;
importjava.awt.event.*;
importjava.sql.ResultSet;
importjava.sql.SQLException;publicclassbook_deleteextendsJFrameimplementsActionListener{
DataBaseManagerdb=newDataBaseManager();
ResultSetrs;
Containerc;
JLabelTipLabel=newJLabel("請?zhí)暨x要刪除的書名",JLabel.CENTER);
JComboBoxbb=newJComboBox();
JButtonyes,exit;
JPanelpanel1=newJPanel();
publicbook_delete()
{
super("刪除圖書信息");
c=getContentPane();
c.setLayout(newBorderLayout());
5
try{
StringstrSQL="selectbook_namefrombookwhere
book_count>borrowed_count";
rs=db.getResult(strSQL);
while(rs.next())
{
bb.addItem(rs.getString(1));
}
}catch(SQLExceptionsqle){
System.out.println(sqle.toString());
}catch(Exceptionex){
System.out.println(ex.toString());
}
c.add(TipLabel,BorderLayout.NORTH);
c.add(bb,BorderLayout.CENTER);
yes=newJButton("確定");
exit=newJButton("退出");
yes.addActionListener(this);
exit.addActionListener(this);
panel1.add(yes);
panel1.add(exit);
c.add(panel1,BorderLayout.SOUTH);setVisible(true);
}
publicvoidactionPerformed(ActionEvente){
if(e.getSource()==exit)
{
this.dispose();
}
elseif(e.getSource()==yes)
{
try{
StringstrSQL="selectborrowed_countfrombookwhere
book_name='"
+bb.getSelectedItem()+"'";
rs=db.getResult(strSQL);
if(!rs.first())
{
JOptionPane.showMessageDialog(null,"書庫里沒有你要刪除的書");
}
else
{
6
StringstrSql="deletefrombookwherebook_name='"
+bb.getSelectedItem()
+"'andborrowed_count=0";
rs.first();
intcount=rs.getInt(1);
if(!(count==0))
{
JOptionPane.showMessageDialog(null,"此書還有同學沒有還,不行刪除");
}
elseif(db.updateSql(strSql))
{
JOptionPane.showMessageDialog(null,"刪除勝利");
db.closeConnection();
this.dispose();
}
else{
JOptionPane.showMessageDialog(null,"刪除失敗");
db.closeConnection();
this.dispose();
}
}
}catch(SQLExceptionsqle){
System.out.println(sqle.toString());
}catch(Exceptionex){
System.out.println(ex.toString());
}
}
}
}
packagelibrary;
importjava.awt.BorderLayout;importjava.awt.Container;
importjava.awt.GridLayout;importjava.awt.event.ActionEvent;
importjava.awt.event.ActionListener;importjava.sql.ResultSet;
importjavax.swing.JButton;importjavax.swing.JFrame;
7
importjavax.swing.JLabel;
importjavax.swing.JOptionPane;
importjavax.swing.JPanel;
importjavax.swing.JTextField;
publicclassbook_modifyextendsJFrameimplementsActionListener{DataBaseManagerdb=newDataBaseManager();
ResultSetrs;
JPanelpanel1,panel2,panel3;
JLabelTipLabel=newJLabel("輸入書名點確定,將調出此書的相關信息");
JLabelbook_name_label,author_label,
press_label,press_date_label,price_label;
JTextFieldbook_name_TextField,author_TextField,
press_TextField,press_date_TextField,price_TextField;
Containerc;
JButtonclear,yes,update,exit;
publicbook_modify()
{
super("修改圖書信息");
c=getContentPane();
c.setLayout(newBorderLayout());
panel3=newJPanel();
panel3.add(TipLabel);
c.add(panel3,BorderLayout.NORTH);
book_name_label=newJLabel("名稱",JLabel.CENTER);author_label=newJLabel("",JLabel.CENTER);
press_label=newJLabel("出版社",JLabel.CENTER);
press_date_label=newJLabel("出版日期",JLabel.CENTER);price_label=newJLabel("價格",JLabel.CENTER);
book_name_TextField=newJTextField(15);
author_TextField=newJTextField(15);
press_TextField=newJTextField(15);
press_date_TextField=newJTextField(15);
price_TextField=newJTextField(15);
panel1=newJPanel();
panel1.setLayout(newGridLayout(6,2));
panel1.add(book_name_label);
panel1.add(book_name_TextField);
panel1.add(author_label);
panel1.add(author_TextField);
panel1.add(press_label);
panel1.add(press_TextField);
panel1.add(press_date_label);
panel1.add(press_date_TextField);
panel1.add(price_label);
8
panel1.add(price_TextField);
panel2=newJPanel();
panel2.setLayout(newGridLayout(1,4));clear=newJButton("清空");
yes=newJButton("確定");
update=newJButton("更新");
exit=newJButton("退出");
panel2.add(clear);
panel2.add(yes);
panel2.add(update);
panel2.add(exit);
clear.addActionListener(this);
yes.addActionListener(this);
update.addActionListener(this);
exit.addActionListener(this);
update.setEnabled(false);
c.add(panel1,BorderLayout.CENTER);
c.add(panel2,BorderLayout.SOUTH);setVisible(true);
}
publicvoidactionPerformed(ActionEvente){
if(e.getSource()==exit)
{
this.dispose();;
}
elseif(e.getSource()==clear)
{
book_name_TextField.setText("");
author_TextField.setText("");
press_TextField.setText("");
press_date_TextField.setText("");
price_TextField.setText("");
}
elseif(e.getSource()==yes)
{
try{
StringstrSQL="select*frombookwherebook_name='"
+book_name_TextField.getText().trim()+"'";
rs=db.getResult(strSQL);
while(rs.next()){
book_name_TextField.setText(rs.getString("book_name"));author_TextField.setText(rs.getString("author"));
9
press_TextField.setText(rs.getString("press"));
press_date_TextField.setText(rs.getString("press_date"));price_TextField.setText(rs.getString("price"));
}
update.setEnabled(true);
}catch(NullPointerExceptionupe){
System.out.println(upe.toString());
}catch(Exceptiones){
System.out.println(es.toString());
}
}
elseif(e.getSource()==update)
{
try{
StringstrSQL="updatebooksetbook_name='"
+book_name_TextField.getText().trim()+"',press='"
+press_TextField.getText().trim()+"',author='"
+author_TextField.getText().trim()+"',press_date='"
+press_date_TextField.getText().trim()+"',price='"
+price_TextField.getText().trim()+"'where
book_name='"+book_name_TextField.getText().trim()+"'";
if(db.updateSql(strSQL))
{
this.dispose();
JOptionPane.showMessageDialog(null,"更新圖書勝利");
}
else{
JOptionPane.showMessageDialog(null,"更新圖書失敗");
}
db.closeConnection();
}catch(Exceptionsqle){
System.out.println(sqle.toString());
}
}
}
}
packagelibrary;
importjava.awt.BorderLayout;
importjava.awt.Container;
importjava.awt.GridLayout;
importjava.awt.event.ActionEvent;
10
importjava.awt.event.ActionListener;importjava.sql.ResultSet;importjava.sql.SQLException;
importjava.text.DateFormat;
importjava.text.SimpleDateFormat;importjava.util.Calendar;importjava.util.Date;
importjavax.swing.JButton;
importjavax.swing.JComboBox;
importjavax.swing.JFrame;
importjavax.swing.JLabel;
importjavax.swing.JOptionPane;
importjavax.swing.JPanel;
importjavax.swing.JTextField;
publicclassbookborrowextendsJFrameimplementsActionListener{DataBaseManagerdb=newDataBaseManager();
ResultSetrs;
Containerc;
JPanelpanel1,panel2;
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2024年店鋪增資擴股合同范本
- 2024建筑合同范文(中英版)
- 2024月嫂雇傭的合同模板
- 2024私人購土地合同樣本
- 2024年度委托研究合同:新材料開發(fā)
- 2024廣告屏租賃合同范文
- 2024個人借款還款合同范本
- 聯合開辦分公司合同模板新
- 全面網絡服務合同
- 專業(yè)房屋維修合同范本收錄
- 2024-2030年飛機租賃行業(yè)市場發(fā)展分析及發(fā)展趨勢前景預測報告
- 2025屆高考英語3500詞匯基礎+提升練01含解析
- 食源性疾病培訓內容知識
- LED顯示屏拆除方案
- 教科版六年級科學上冊期中測試卷
- 項目管理與風險管理考核試卷
- 2024年度假區(qū)(陽澄湖鎮(zhèn))國(集體)公司公開招聘工作人員高頻難、易錯點500題模擬試題附帶答案詳解
- 2024秋期國家開放大學本科《經濟學(本)》一平臺在線形考(形考任務1至6)試題及答案
- 小學生法制教育課件
- 浙江省杭州市五校聯考2025屆英語高三第一學期期末復習檢測試題含解析
- 期末(試題)-2024-2025學年人教PEP版(2024)英語三年級上冊
評論
0/150
提交評論