Using the Firecracker Virtio-vsock Device + F_UNIX 套接字通訊
阿新 • • 發佈:2020-10-23
檢視更多系統:系統大全,課程設計、畢業設計,請點選這裡檢視
01 概述
一款功能強大的圖書館管理系統,功能齊全,小白/大學生專案實訓,學習的不二之選。
02 技術
此係統使用 java awt 實現。java.awt是一個軟體包,包含用於建立使用者介面和繪製圖形影象的所有分類。在AWT術語中,諸如按鈕或滾動條之類的使用者介面物件稱為元件。Component類是所有 AWT 元件的根。
03 功能詳解
基礎維護
圖書維護
- 新增:輸入圖書編號、圖書名稱、圖書頁數、圖書作者、出版社、庫存數量、所屬型別等圖書資訊,點選Save按鈕新增新圖書。
- 修改:首先根據圖書編號查詢到所要修改的圖書,然後對圖書的名稱、圖書頁數、作者、出版時間、定價、庫存等資訊進行修改。
- 刪除:首先根據圖書編號查詢到所要刪除的圖書,然後進行刪除操作。
讀者維護
- 新增:輸入讀者編號、讀者姓名、讀者類別、讀者性別、可借天數等資訊,然後點選“Add”按鈕新增新讀者。
- 修改:首先根據讀者編號查詢到要修改的讀者資訊,再對讀者編號、讀者姓名、讀者類別、讀者性別、可借天數等資訊進行修改,修改完成點選“儲存”按鈕完成修改。
- 刪除:首先根據讀者編號查詢到要刪除的讀者資訊,然後進行刪除操作。
借閱管理
- 借書管理:首先根據圖書編號和讀者編號查詢到圖書和讀者資訊,在點選“借出”按鈕完成借書。
- 還書管理:首先根據圖書編號和讀者編號查詢到圖書和讀者資訊,在點選“還書”按鈕完成還書。
查詢管理
- 圖書查詢:輸入圖書名稱、作者、出版時間中的任意一項,點選“查詢”按鈕查詢圖書。
- 讀者查詢:輸入讀者姓名、讀者型別中的任意一項,點選“查詢”按鈕查詢讀者。
系統管理
- 修改密碼:首先輸入舊密碼等待校驗,舊密碼輸入正確後即可設定新的密碼。
- 退出系統:退出圖書管理系統程式。
04 執行截圖
新增圖書
新增讀者
借書管理
圖書查詢
修改密碼
05 主要程式碼
新增圖書
package com.jason.frame;//com.jason.frame.BookAdd.java import java.awt.*; import java.awt.event.*; import java.sql.ResultSet; import java.sql.SQLException; import java.text.ParseException; import java.text.SimpleDateFormat; import javax.swing.JOptionPane; public class BookAdd extends Frame implements ActionListener{ Toolkit tool= getToolkit(); String url="src/bookbk.png"; Image img=tool.getImage(url); public void paint(Graphics g){ g.drawImage(img,0,0,this); } public void clearAndSetBookId(){ for(int j=0;j<booktxt.length;j++){ booktxt[j].setText(""); } String str=getInsertOrderedList(); booktxt[0].setEditable(false); booktxt[0].setText(str); } String[] lbname={"圖書編號","圖書名稱","圖書頁數","圖書作者","翻 譯","出 版 社","出版時間","定價","庫存數量","所屬型別"}; Label[] booklb=new Label[10]; TextField[] booktxt=new TextField[10]; Button savebtn=new Button("Save"); Button closebtn=new Button("Close"); Choice booktype=new Choice(); public BookAdd(){ setTitle("新增新書"); setLayout(null); setSize(500,250); setResizable(false); //this.setOpaque(false); this.setForeground(Color.BLACK); int lx=50,ly=50; booktype.add("程式設計"); booktype.add("圖形設計"); booktype.add("其他"); booktype.add("科技"); booktype.add("文學"); booktype.add("歷史"); booktype.add("百科"); booktype.add("英語"); booktype.add("計算機"); booktype.add("Internet"); booktype.add("數學"); String str=getInsertOrderedList(); for(int i=0;i<booklb.length;i++){ if(lx>240){ lx=50; ly=ly+30; } booklb[i]=new Label(lbname[i]); booklb[i].setBounds(lx,ly,50,20); booktxt[i]=new TextField(); booktxt[i].setBounds(lx+60,ly,100,20); lx=lx+190; add(booklb[i]);add(booktxt[i]); } booktxt[0].setEditable(false); booktxt[0].setText(str); booktxt[9].setVisible(false); booktype.setBounds(300,170,100,20); add(booktype); savebtn.setBounds(150,210,80,25); closebtn.setBounds(280,210,80,25); add(savebtn);add(closebtn); addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){ DbOp.close(); dispose(); } }); savebtn.addActionListener(this); closebtn.addActionListener(this); setLocationRelativeTo(null); setVisible(true); } public static String getInsertOrderedList(){ String returnstring=""; String sql="select * from book"; try{ int count=0; ResultSet rs=DbOp.executeQuery(sql); while(rs.next()){ count++; } String[] allid=new String[count]; int[] intofid=new int[count]; int i=0; ResultSet rs1=DbOp.executeQuery(sql); while(rs1.next()){ allid[i]=rs1.getString("id"); String mystr=allid[i].substring(1); intofid[i]=Integer.parseInt(mystr); i++; } int temp=-1; for(int j=0;j<intofid.length;j++){ if(intofid[j]>temp){ temp=intofid[j]; } } returnstring=String.valueOf(temp+1); int len=returnstring.length(); for(int f=0;f<5-len;f++){ returnstring="0"+returnstring; } returnstring="A"+returnstring; DbOp.close(); }catch(SQLException ee){ } return returnstring; } public void actionPerformed(ActionEvent e){ Object ob=e.getSource(); if(ob==savebtn){ savebtnActionPerformed(); clearAndSetBookId(); } if(ob==closebtn){ DbOp.close(); dispose(); } } public void savebtnActionPerformed(){ String id=booktxt[0].getText(); String typestr=booktype.getSelectedItem().toString(); String[] inputstring=new String[9]; boolean emptyequals=false; for(int i=0;i<inputstring.length;i++){ inputstring[i]=booktxt[i].getText(); if(inputstring[i].equals("")){ JOptionPane.showMessageDialog(null,"請務必填寫完整"); return; } } if(id.equals("")){ JOptionPane.showMessageDialog(null,"圖書編號不能為空"); return; } if(IfBookIdExit(id)){ JOptionPane.showMessageDialog(null,"圖書編號已存在"); return; } try{ SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM"); sdf.parse(inputstring[6]); float price=Float.parseFloat(inputstring[7]); int stock= Integer.parseInt(inputstring[8]); int page=Integer.parseInt(inputstring[2]); String sql="insert into book(id,bookname,booktype,author,translator,publisher,publish_time,price,stock,page)"; sql=sql+"values('"+id+"','"+inputstring[1]+"','"+typestr+"','"+inputstring[3]+"','"+inputstring[4]+"','"; sql=sql+inputstring[5]+"','"+inputstring[6]+"',"+price+","+stock+","+page+")"; int i=DbOp.executeUpdate(sql); if(i==1){ JOptionPane.showMessageDialog(null,"圖書新增成功!"); clearAllText(); } }catch(ParseException e2){ JOptionPane.showMessageDialog(null,"出版時間格式錯誤,正確為(年-月)"); }catch(NumberFormatException e1){ JOptionPane.showMessageDialog(null,"庫存數量,價格,頁數錯誤,應為數字"); } } public boolean IfBookIdExit(String id){ boolean right=false; String sql="select*from book where id='"+id+"'"; ResultSet rs=DbOp.executeQuery(sql); try{ while(rs.next()){ right = true; } //right = false; }catch(SQLException e){ JOptionPane.showMessageDialog(null,"無法正常讀取資料"); } return right; } public void clearAllText(){ for(int i=0;i<booktxt.length;i++){ booktxt[i].setText(""); } } public static void main(String[] args){ new BookAdd(); } }
新增讀者
package com.jason.frame;//com.jason.frame.ReaderAdd.java
import java.awt.*;
import java.awt.event.*;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JOptionPane;
public class ReaderAdd extends Frame{
Toolkit tool= getToolkit();
String url="src/bookbk.png";
Image img=tool.getImage(url);
public void paint(Graphics g){
g.drawImage(img,0,0,this);
}
public void clearAndSetReaderId(){
for(int j=0;j<readertxt.length;j++){
readertxt[j].setText("");
}
String str=getInsertOrderedList();
readertxt[0].setEditable(false);
readertxt[0].setText(str);
}
String[] labelsign={"讀者編號","讀者姓名","讀者類別","讀者性別","可借數量","可借天數"};
Label[] readerlb=new Label[6];
static TextField[] readertxt=new TextField[6];
Button querybtn,closebtn;
static Choice readertype,readersex;
public ReaderAdd(){
setLayout(null);
setSize(500,200);setResizable(false);
setTitle("新增新讀者");
String str=getInsertOrderedList();
int lx=50,ly=50;
for(int i=0;i<readertxt.length;i++){
if(lx>240){
ly=ly+30;
lx=50;
}
readerlb[i]=new Label(labelsign[i]);
readertxt[i]=new TextField();
readerlb[i].setBounds(lx,ly,50,20);
readertxt[i].setBounds(lx+60,ly,100,20);
lx=lx+190;
add(readerlb[i]);
add(readertxt[i]);
}
readertxt[0].setEditable(false);
readertxt[0].setText(str);
readertype=new Choice();
readertype.add("教師");
readertype.add("學生");
readertype.add("作家");
readertype.add("職工");
readertype.add("其他");
readersex=new Choice();
readersex.add("男");
readersex.add("女");
readertxt[2].setVisible(false);
readertxt[3].setVisible(false);
readertype.setBounds(110,80,100,20);
readersex.setBounds(300,80,100,20);
add(readertype);add(readersex);
querybtn=new Button("Add");
closebtn=new Button("Close");
querybtn.setBounds(130,140,50,20);
closebtn.setBounds(310,140,50,20);
add(querybtn);add(closebtn);
querybtn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
updateActionPerformed(e);
clearAndSetReaderId();
}
});
closebtn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
DbOp.close();
dispose();
//System.exit(0);
}
});
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
DbOp.close();
dispose();
//System.exit(0);
}
});
setLocationRelativeTo(null);
setVisible(true);
}
public static String getInsertOrderedList(){
String returnstring="";
String sql="select * from reader";
try{
int count=0;
ResultSet rs=DbOp.executeQuery(sql);
while(rs.next()){
count++;
}
String[] allid=new String[count];
int[] intofid=new int[count];
int i=0;
ResultSet rs1=DbOp.executeQuery(sql);
while(rs1.next()){
allid[i]=rs1.getString("id");
intofid[i]=Integer.parseInt(allid[i]);
i++;
}
int temp=-1;
for(int j=0;j<intofid.length;j++){
if(intofid[j]>temp){
temp=intofid[j];
}
}
returnstring=String.valueOf(temp+1);
int len=returnstring.length();
for(int f=0;f<5-len;f++){
returnstring="0"+returnstring;
}
DbOp.close();
}catch(SQLException ee){
}
return returnstring;
}
public static void updateActionPerformed(ActionEvent e){
String[] readerstr=new String[6];
readerstr[2]=readertype.getSelectedItem().toString();
readerstr[3]=readersex.getSelectedItem().toString();
for(int i=0;i<readerstr.length;i++){
if(i==2||i==3){
continue;
}
readerstr[i]=readertxt[i].getText();
if(readerstr[i].equals("")){
JOptionPane.showMessageDialog(null,"請務必填寫完整");
return;
}
}
String id=readerstr[0];
if(IfReaderExit(id)){
JOptionPane.showMessageDialog(null,"該讀者已經存在!");
return;
}
try{
int max_num=Integer.parseInt(readerstr[4]);
int days_num=Integer.parseInt(readerstr[5]);
String sql="insert into reader(id,readername,readertype,sex,max_num,days_num) values('";
sql=sql+id+"','"+readerstr[1]+"','"+readerstr[2]+"','"+readerstr[3]+"',"+max_num+","+days_num+")";
int a=DbOp.executeUpdate(sql);
if(a==1){
JOptionPane.showMessageDialog(null,"讀者新增成功");
}else{
JOptionPane.showMessageDialog(null,"讀者新增失敗");
}
DbOp.close();
}catch(NumberFormatException e1){
JOptionPane.showMessageDialog(null,"可借數量和可借天數必須是整數");
}
}
public static boolean IfReaderExit(String id){
String sql="select * from reader where id='"+id+"'";
try{
ResultSet rs=DbOp.executeQuery(sql);
if(rs.next()){
return true;
}else{
return false;
}
}catch(SQLException e){
JOptionPane.showMessageDialog(null,"查詢資料錯誤");
}
return false;
}
public static void main(String[] args){
new ReaderAdd();
}
}
修改密碼
package com.jason.frame;//com.jason.frame.ChangePassWord.java;
import java.awt.*;
import java.awt.event.*;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JOptionPane;
public class ChangePassWord extends Frame{
String[] sign={"舊密碼:","設定新密碼:","重複新密碼:"};
Label[] textlb=new Label[3];
TextField[] passtxt=new TextField[3];
Button reset=new Button("新密碼設定");
public ChangePassWord(){
setTitle("修改密碼");
setSize(300,250);
setLayout(null);
setResizable(false);
int y=50;
for(int i=0;i<3;i++){
textlb[i]=new Label(sign[i]);
passtxt[i]=new TextField();
textlb[i].setBounds(50,y,80,20);
passtxt[i].setBounds(130,y,100,20);
passtxt[i].setEchoChar('●');
add(textlb[i]);add(passtxt[i]);
y=y+50;
}
reset.setBounds(110,200,80,20);
add(reset);
setLocationRelativeTo(null);
reset.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
setNewPassWord(e);
}
});
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
setVisible(true);
}
public void setNewPassWord(ActionEvent e){
String[] password=new String[3];
String sql;
for (int i=0;i<password.length;i++){
password[i]=passtxt[i].getText();
}
if(!password[0].equals("")){
sql="select * from user where username='"+GlobalVar.login_user+"'";
}else{
JOptionPane.showMessageDialog(null,"Empty String Just Input");
return;
}
if(password[0].equals(password[1])){
}
try{
ResultSet rs=DbOp.executeQuery(sql);
while(rs.next()){
if(password[0].equals(rs.getString("password"))){
}else{
JOptionPane.showMessageDialog(null,"Sorroy It's Fail It's not Old PassWord");
return;
}
}
}catch(SQLException ee){
JOptionPane.showMessageDialog(null,"Sorroy It's Fail Some Data Wrong");
return;
}
if(password[0].equals(password[1])){
JOptionPane.showMessageDialog(null,"Sorroy It's Fail Same From Old Password");
return;
}
if(!password[1].equals(password[2])){
JOptionPane.showMessageDialog(null,"Sorroy It's Fail Again Password wrong");
return;
}
if(password[1].equals("")&&password[1].equals("")){
JOptionPane.showMessageDialog(null,"Sorroy It's Fail one Empty");
return;
}
sql="";
sql="update user set password='"+password[1]+"'where username='"+GlobalVar.login_user+"'";
int da=DbOp.executeUpdate(sql);
if(da==1){
JOptionPane.showMessageDialog(null,"yet It's Successed Update PassWord");
}else{
JOptionPane.showMessageDialog(null,"Sorroy It's Fail try again");
}
}
public static void main(String[] args){
new ChangePassWord();
}
}
06 原始碼下載
關注公眾號【C you again】,回覆“Java GUI圖書管理系統”免費領取。
亦可直接掃描主頁二維碼關注,回覆“Java GUI圖書管理系統”免費領取,點此打開個人主頁
說明:此原始碼來源於網路,若有侵權,請聯絡刪除!!