前言:
項目是使用Java swing開發,可實作基礎資料維護、圖書類型管理和維護、圖書資訊管理和維護、登出退出、關于作者簡介等功能。界面設計比較簡介、适合作為Java課設設計以及學習技術使用。引言
随着計算機及網絡技術的飛速發展,Intranet 應用在全球範圍内日益普及, 當今社會正快速向資訊化社會前進,資訊系統的作用也越來越大。圖書館在正常營運中總是面對大量的讀者資訊,書籍資訊以及由兩者互相作用産生的借書資訊,還書資訊。是以圖書管理資訊化是發展的必然趨勢。用結構化系統分析與設計的方法,建立一套有效的圖書資訊管理系統,可以減輕工作,将工作科學化、規範化,提高了圖書館資訊管理的工作品質是以根據圖書館目前實際的管理情況開發一套冬書管理系統是一分必要的。
主要技術和工具:
eclipse+JDK1..8+Navicat +swing +mysql
功能截圖:
圖書類型管理:
圖書類型管理維護、可以根據圖書類型檢視圖書資訊、可以根據編号和資訊删除修改圖書類型資訊
圖書資訊管理:
圖書資訊維護管理、點選圖書維護可以根據圖書名稱、作者以及圖書類型模糊查詢圖書資訊、可以點選下面的輸入框進行資料修改和删除操作
選中資料進行修改和删除操作
圖書添加:
作者簡介:
登出退出:
關鍵代碼:
主入口:
package com.HPioneer.view;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import java.awt.GridLayout;
import javax.swing.SpringLayout;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.ImageIcon;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JDesktopPane;
import java.awt.Color;
import java.awt.SystemColor;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class MainFrm extends JFrame {
private JPanel contentPane;
private JDesktopPane table = null;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
MainFrm frame = new MainFrm();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public MainFrm() {
setTitle("圖書管理主界面");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
JMenuBar menuBar = new JMenuBar();
setJMenuBar(menuBar);
JMenu menu = new JMenu("基本資料維護");
menu.setIcon(new ImageIcon(MainFrm.class.getResource("/images/base.png")));
menuBar.add(menu);
JMenu mnNewMenu = new JMenu("圖書類别管理");
mnNewMenu.setIcon(new ImageIcon(MainFrm.class.getResource("/images/bookTypeManager.png")));
menu.add(mnNewMenu);
JMenuItem menuItem = new JMenuItem("圖書類别添加");
menuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
BookTypeAddInterFrm bookTypeAddInterFrm = new BookTypeAddInterFrm();
bookTypeAddInterFrm.setVisible(true);
table.add(bookTypeAddInterFrm);
}
});
menuItem.setIcon(new ImageIcon(MainFrm.class.getResource("/images/add.png")));
mnNewMenu.add(menuItem);
JMenuItem menuItem_2 = new JMenuItem("圖書類别維護");
menuItem_2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
BookTypeManagerInterFrm bookTypeManagerInterFrm = new BookTypeManagerInterFrm();
bookTypeManagerInterFrm.setVisible(true);
table.add(bookTypeManagerInterFrm);
}
});
menuItem_2.setIcon(new ImageIcon(MainFrm.class.getResource("/images/edit.png")));
mnNewMenu.add(menuItem_2);
JMenu mnNewMenu_1 = new JMenu("圖書管理");
mnNewMenu_1.setIcon(new ImageIcon(MainFrm.class.getResource("/images/bookManager.png")));
menu.add(mnNewMenu_1);
JMenuItem menuItem_1 = new JMenuItem("圖書添加");
menuItem_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
BookAddInterFrm bookAddInterFrm = new BookAddInterFrm();
bookAddInterFrm.setVisible(true);
table.add(bookAddInterFrm);
}
});
menuItem_1.setIcon(new ImageIcon(MainFrm.class.getResource("/images/add.png")));
mnNewMenu_1.add(menuItem_1);
JMenuItem mntmNewMenuItem = new JMenuItem("圖書維護");
mntmNewMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
BookManageInterFrm bookManagerInterFrm = new BookManageInterFrm();
bookManagerInterFrm.setVisible(true);
table.add(bookManagerInterFrm);
}
});
mntmNewMenuItem.setIcon(new ImageIcon(MainFrm.class.getResource("/images/edit.png")));
mnNewMenu_1.add(mntmNewMenuItem);
JMenuItem menuItem_3 = new JMenuItem("安全退出");
menuItem_3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int result =JOptionPane.showConfirmDialog(null,"是否退出系統");
}
});
menuItem_3.setIcon(new ImageIcon(MainFrm.class.getResource("/images/exit.png")));
menu.add(menuItem_3);
JMenu menu_1 = new JMenu("關于作者");
menu_1.setIcon(new ImageIcon(MainFrm.class.getResource("/images/about.png")));
menuBar.add(menu_1);
JMenuItem mntmhpioneer = new JMenuItem("關于奧斯卡");
mntmhpioneer.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
HPioneer1234InterFrm hPioneer1234InterFrm = new HPioneer1234InterFrm();
hPioneer1234InterFrm.setVisible(true);
table.add(hPioneer1234InterFrm);
}
});
mntmhpioneer.setIcon(new ImageIcon(MainFrm.class.getResource("/images/userName.png")));
menu_1.add(mntmhpioneer);
contentPane = new JPanel();
contentPane.setForeground(Color.BLUE);
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(new BorderLayout(0, 0));
table = new JDesktopPane();
table.setBackground(Color.WHITE);
contentPane.add(table);
//設定Jrame最大化
this.setExtendedState(JFrame.MAXIMIZED_BOTH);
}
}
添加圖書:
package com.HPioneer.view;
import java.awt.EventQueue;
import javax.swing.JInternalFrame;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.border.LineBorder;
import com.HPioneer.dao.BookDao;
import com.HPioneer.dao.BookTypeDao;
import com.HPioneer.model.Book;
import com.HPioneer.model.BookType;
import com.HPioneer.util.DbUtil;
import com.HPioneer.util.StringUtil;
import com.mysql.jdbc.Connection;
import javax.swing.JRadioButton;
import javax.swing.ButtonGroup;
import javax.swing.JTextArea;
import javax.swing.JComboBox;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
import java.awt.event.ActionEvent;
import javax.swing.ImageIcon;
public class BookAddInterFrm extends JInternalFrame {
private JTextField bookNameTxt;
private JTextField authorTxt;
private final ButtonGroup buttonGroup = new ButtonGroup();
private JTextField priceTxt;
private DbUtil dbUtil = new DbUtil();
private BookTypeDao bookTypeDao = new BookTypeDao();
private BookDao bookDao = new BookDao();
private JComboBox bookTypeJcb;
private JTextArea bookDescTxt;
private JRadioButton manJrb;
private JRadioButton femaleJrb;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
BookAddInterFrm frame = new BookAddInterFrm();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public BookAddInterFrm() {
setIconifiable(true);
setClosable(true);
setTitle("圖書添加");
setBounds(100, 100, 450, 463);
JLabel lblNewLabel = new JLabel("圖書名字:");
bookNameTxt = new JTextField();
bookNameTxt.setColumns(10);
JLabel lblNewLabel_1 = new JLabel("圖書作者:");
authorTxt = new JTextField();
authorTxt.setColumns(10);
JLabel lblNewLabel_2 = new JLabel("作者性别:");
manJrb = new JRadioButton("男");
buttonGroup.add(manJrb);
manJrb.setSelected(true);
femaleJrb = new JRadioButton("女");
buttonGroup.add(femaleJrb);
JLabel lblNewLabel_3 = new JLabel("圖書價格:");
priceTxt = new JTextField();
priceTxt.setColumns(10);
JLabel lblNewLabel_4 = new JLabel("圖書描述:");
bookDescTxt = new JTextArea();
JLabel lblNewLabel_5 = new JLabel("圖書類别:");
bookTypeJcb = new JComboBox();
JButton btnNewButton = new JButton("添加");
btnNewButton.setIcon(new ImageIcon(BookAddInterFrm.class.getResource("/images/add.png")));
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
bookAddActionPerformed(e);
}
});
JButton btnNewButton_1 = new JButton("重置");
btnNewButton_1.setIcon(new ImageIcon(BookAddInterFrm.class.getResource("/images/add.png")));
btnNewButton_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
bookValueActionPerformed(e);
}
});
btnNewButton_1.setIcon(new ImageIcon(BookAddInterFrm.class.getResource("/images/reset.png")));
GroupLayout groupLayout = new GroupLayout(getContentPane());
groupLayout.setHorizontalGroup(
groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addGap(28)
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addComponent(lblNewLabel_4)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(bookDescTxt, GroupLayout.DEFAULT_SIZE, 262, Short.MAX_VALUE))
.addGroup(groupLayout.createSequentialGroup()
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING, false)
.addGroup(groupLayout.createSequentialGroup()
.addComponent(lblNewLabel_2)
.addPreferredGap(ComponentPlacement.UNRELATED)
.addComponent(manJrb)
.addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(femaleJrb))
.addGroup(groupLayout.createSequentialGroup()
.addComponent(lblNewLabel)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(bookNameTxt, GroupLayout.PREFERRED_SIZE, 91, GroupLayout.PREFERRED_SIZE)))
.addGap(18)
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
.addComponent(lblNewLabel_3)
.addComponent(lblNewLabel_1))
.addPreferredGap(ComponentPlacement.RELATED)
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
.addComponent(authorTxt, GroupLayout.DEFAULT_SIZE, 89, Short.MAX_VALUE)
.addComponent(priceTxt, GroupLayout.DEFAULT_SIZE, 89, Short.MAX_VALUE)))
.addGroup(groupLayout.createSequentialGroup()
.addComponent(btnNewButton)
.addGap(33)
.addComponent(btnNewButton_1))
.addGroup(groupLayout.createSequentialGroup()
.addComponent(lblNewLabel_5)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(bookTypeJcb, 0, 262, Short.MAX_VALUE)))
.addGap(80))
);
groupLayout.setVerticalGroup(
groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addGap(33)
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
.addComponent(lblNewLabel)
.addComponent(bookNameTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(authorTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(lblNewLabel_1))
.addGap(26)
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
.addComponent(lblNewLabel_2)
.addComponent(manJrb)
.addComponent(femaleJrb)
.addComponent(lblNewLabel_3)
.addComponent(priceTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGap(26)
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
.addComponent(lblNewLabel_5)
.addComponent(bookTypeJcb, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGap(30)
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
.addComponent(lblNewLabel_4)
.addComponent(bookDescTxt, GroupLayout.PREFERRED_SIZE, 140, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(ComponentPlacement.RELATED, 38, Short.MAX_VALUE)
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
.addComponent(btnNewButton)
.addComponent(btnNewButton_1))
.addGap(50))
);
getContentPane().setLayout(groupLayout);
//顯示文本域邊框
bookDescTxt.setBorder(new LineBorder(new java.awt.Color(127,157,185),1,false));
fillBookType();
}
/**
* 重置事件處理
* @param e
*/
private void bookValueActionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
this.resetValue();
}
private void bookAddActionPerformed(ActionEvent evt) {
// TODO Auto-generated method stub
String bookName = this.bookNameTxt.getText();
String author = this.authorTxt.getText();
String price = this.priceTxt.getText();
String bookDesc = this.bookDescTxt.getText();
if(StringUtil.isEmpty(bookName)){
JOptionPane.showMessageDialog(null,"圖書名稱不能為空");
}
if(StringUtil.isEmpty(author)){
JOptionPane.showMessageDialog(null,"圖書作者不能為空");
}
if(StringUtil.isEmpty(price)){
JOptionPane.showMessageDialog(null,"圖書價格不能為空");
}
String sex ="";
if(manJrb.isSelected()){
sex="男";
}else{
sex="女";
}
BookType bookType =(BookType) bookTypeJcb.getSelectedItem();
int bookTypeId = bookType.getId();
Book book = new Book(bookName,author,sex,Float.parseFloat(price),bookTypeId,bookDesc);
Connection con = null;
try{
con=dbUtil.getCon();
int addNum = bookDao.add(con, book);
if(addNum == 1){
JOptionPane.showMessageDialog(null,"圖書類别添加成功");
resetValue();
}else{
JOptionPane.showMessageDialog(null,"圖書類别添加失敗");
}
}catch(Exception e){
e.printStackTrace();
JOptionPane.showMessageDialog(null,"圖書類别添加失敗");
}finally{
try{
dbUtil.closeCon(con);
}catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
}
/**
* 重置表單
*/
private void resetValue() {
// TODO Auto-generated method stub
this.bookNameTxt.setText("");
this.authorTxt.setText("");
this.priceTxt.setText("");
this.manJrb.setSelected(true);
this.bookDescTxt.setText("");
if(this.bookTypeJcb.getItemCount()>0){
this.bookTypeJcb.setSelectedIndex(0);
}
}
/**
* 初始化圖書類别下拉框
*/
private void fillBookType(){
Connection con = null;
BookType bookType = null;
try{
con = dbUtil.getCon();
ResultSet rs = bookTypeDao.list(con, new BookType());
while( rs.next() ){
bookType = new BookType();
bookType.setId(rs.getInt("id"));
bookType.setBookTypeName(rs.getString("bookTypeName"));
this.bookTypeJcb.addItem(bookType);
}
}catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}finally{
}
}
}
資料庫設計:
使用者表:
CREATE TABLE `NewTable` (
`id` int(11) NOT NULL AUTO_INCREMENT ,
`userName` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL ,
`password` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL ,
PRIMARY KEY (`id`)
)
ENGINE=InnoDB
DEFAULT CHARACTER SET=utf8 COLLATE=utf8_general_ci
AUTO_INCREMENT=2
ROW_FORMAT=COMPACT
;
圖書表:
CREATE TABLE `NewTable` (
`id` int(11) NOT NULL AUTO_INCREMENT ,
`bookName` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL ,
`author` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL ,
`sex` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL ,
`price` float NULL DEFAULT NULL ,
`bookTypeId` int(255) NULL DEFAULT NULL ,
`bookTypeName` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL ,
`bookDesc` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL ,
PRIMARY KEY (`id`),
FOREIGN KEY (`bookTypeId`) REFERENCES `t_booktype` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
INDEX `by` (`bookTypeId`) USING BTREE
)
ENGINE=InnoDB
DEFAULT CHARACTER SET=utf8 COLLATE=utf8_general_ci
AUTO_INCREMENT=3
ROW_FORMAT=COMPACT
;
圖書類型表
CREATE TABLE `NewTable` (
`id` int(11) NOT NULL AUTO_INCREMENT ,
`bookTypeName` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL ,
`bookTypeDesc` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL ,
PRIMARY KEY (`id`)
)
ENGINE=InnoDB
DEFAULT CHARACTER SET=utf8 COLLATE=utf8_general_ci
AUTO_INCREMENT=9
ROW_FORMAT=COMPACT
;
備注:項目來于網絡、作者整理優化測試、若有侵權聯系作者删除
總結:
本系統是在湯蓉老師的悉心指導下順利完成的,從系統的選題、方案的制定以及論文的撰寫,每一步都傾注着我們整個團隊的心血。在此,衷心感謝大家對我們這個項目整個過程的積極籌劃以及出謀劃策,在面對困難的時候大家共通過不放棄,通過各種辦法解決各種困難在此同時感謝湯蓉和徐振明老師,缜密的邏輯,活躍的思維,敏銳的洞察力,嚴謹的治學态度以及民主的作風給我留下了深刻的印象,為我開闊了視野,豐富了學識,并将使我受益終身,我學習的楷模;湯蓉老師的工作态度和說教方式讓我們感到很親切與他相處的也很融洽。感謝計算機科學與技術專業、計算機系的全體老師辛勤培養和教誨!完整源碼下載下傳位址
JavaSwing系列項目推薦:
基于JavaSwing的經典坦克大戰遊戲設計實作
基于JavaSwing ATM取款機系統的設計和實作
基于JavaSwing+mysql的學生社團管理系統設計和實作
打卡JavaSwing項目更新 2 / 100篇