基于JavaSwing+mysql的图书管理系统设计和实现
前言:
? ? ? ? 項(xiàng)目是使用Java swing開(kāi)發(fā),可實(shí)現(xiàn)基礎(chǔ)數(shù)據(jù)維護(hù)、圖書(shū)類型管理和維護(hù)、圖書(shū)信息管理和維護(hù)、注銷退出、關(guān)于作者簡(jiǎn)介等功能。界面設(shè)計(jì)比較簡(jiǎn)介、適合作為Java課設(shè)設(shè)計(jì)以及學(xué)習(xí)技術(shù)使用。
引言
? ? ? ?隨著計(jì)算機(jī)及網(wǎng)絡(luò)技術(shù)的飛速發(fā)展,Intranet 應(yīng)用在全球范圍內(nèi)日益普及,?當(dāng)今社會(huì)正快速向信息化社會(huì)前進(jìn),信息系統(tǒng)的作用也越來(lái)越大。圖書(shū)館在正常運(yùn)營(yíng)中總是面對(duì)大量的讀者信息,書(shū)籍信息以及由兩者相互作用產(chǎn)生的借書(shū)信息,還書(shū)信息。因此圖書(shū)管理信息化是發(fā)展的必然趨勢(shì)。用結(jié)構(gòu)化系統(tǒng)分析與設(shè)計(jì)的方法,建立一套有效的圖書(shū)信息管理系統(tǒng),可以減輕工作,將工作科學(xué)化、規(guī)范化,提高了圖書(shū)館信息管理的工作質(zhì)量因此根據(jù)圖書(shū)館目前實(shí)際的管理情況開(kāi)發(fā)一套冬書(shū)管理系統(tǒng)是一分必要的。
主要技術(shù)和工具:
eclipse+JDK1..8+Navicat +swing +mysql
功能截圖:
圖書(shū)類型管理:
圖書(shū)類型管理維護(hù)、可以根據(jù)圖書(shū)類型查看圖書(shū)信息、可以根據(jù)編號(hào)和信息刪除修改圖書(shū)類型信息
圖書(shū)信息管理:
圖書(shū)信息維護(hù)管理、點(diǎn)擊圖書(shū)維護(hù)可以根據(jù)圖書(shū)名稱、作者以及圖書(shū)類型模糊查詢圖書(shū)信息、可以點(diǎn)擊下面的輸入框進(jìn)行數(shù)據(jù)修改和刪除操作
選中數(shù)據(jù)進(jìn)行修改和刪除操作
?
圖書(shū)添加:
??
作者簡(jiǎn)介:
注銷退出:
關(guān)鍵代碼:
?主入口:
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("圖書(shū)管理主界面");setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);setBounds(100, 100, 450, 300);JMenuBar menuBar = new JMenuBar();setJMenuBar(menuBar);JMenu menu = new JMenu("基本數(shù)據(jù)維護(hù)");menu.setIcon(new ImageIcon(MainFrm.class.getResource("/images/base.png")));menuBar.add(menu);JMenu mnNewMenu = new JMenu("圖書(shū)類別管理");mnNewMenu.setIcon(new ImageIcon(MainFrm.class.getResource("/images/bookTypeManager.png")));menu.add(mnNewMenu);JMenuItem menuItem = new JMenuItem("圖書(shū)類別添加");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("圖書(shū)類別維護(hù)");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("圖書(shū)管理");mnNewMenu_1.setIcon(new ImageIcon(MainFrm.class.getResource("/images/bookManager.png")));menu.add(mnNewMenu_1);JMenuItem menuItem_1 = new JMenuItem("圖書(shū)添加");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("圖書(shū)維護(hù)");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,"是否退出系統(tǒng)");}});menuItem_3.setIcon(new ImageIcon(MainFrm.class.getResource("/images/exit.png")));menu.add(menuItem_3);JMenu menu_1 = new JMenu("關(guān)于作者");menu_1.setIcon(new ImageIcon(MainFrm.class.getResource("/images/about.png")));menuBar.add(menu_1);JMenuItem mntmhpioneer = new JMenuItem("關(guān)于奧斯卡");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);//設(shè)置Jrame最大化this.setExtendedState(JFrame.MAXIMIZED_BOTH);} }添加圖書(shū):
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("圖書(shū)添加");setBounds(100, 100, 450, 463);JLabel lblNewLabel = new JLabel("圖書(shū)名字:");bookNameTxt = new JTextField();bookNameTxt.setColumns(10);JLabel lblNewLabel_1 = new JLabel("圖書(shū)作者:");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("圖書(shū)價(jià)格:");priceTxt = new JTextField();priceTxt.setColumns(10);JLabel lblNewLabel_4 = new JLabel("圖書(shū)描述:");bookDescTxt = new JTextArea();JLabel lblNewLabel_5 = new JLabel("圖書(shū)類別:");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 stubthis.resetValue();}private void bookAddActionPerformed(ActionEvent evt) {// TODO Auto-generated method stubString 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,"圖書(shū)名稱不能為空");}if(StringUtil.isEmpty(author)){JOptionPane.showMessageDialog(null,"圖書(shū)作者不能為空");}if(StringUtil.isEmpty(price)){JOptionPane.showMessageDialog(null,"圖書(shū)價(jià)格不能為空");}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,"圖書(shū)類別添加成功"); resetValue();}else{JOptionPane.showMessageDialog(null,"圖書(shū)類別添加失敗");}}catch(Exception e){e.printStackTrace(); JOptionPane.showMessageDialog(null,"圖書(shū)類別添加失敗");}finally{try{dbUtil.closeCon(con);}catch (Exception e) {// TODO: handle exceptione.printStackTrace(); }}}/*** 重置表單*/private void resetValue() {// TODO Auto-generated method stubthis.bookNameTxt.setText("");this.authorTxt.setText("");this.priceTxt.setText("");this.manJrb.setSelected(true);this.bookDescTxt.setText("");if(this.bookTypeJcb.getItemCount()>0){this.bookTypeJcb.setSelectedIndex(0);}}/*** 初始化圖書(shū)類別下拉框*/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 exceptione.printStackTrace();}finally{}} }數(shù)據(jù)庫(kù)設(shè)計(jì):
用戶表:
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 ;圖書(shū)表:
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 ;圖書(shū)類型表?
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 ;備注:項(xiàng)目來(lái)于網(wǎng)絡(luò)、作者整理優(yōu)化測(cè)試、若有侵權(quán)聯(lián)系作者刪除
總結(jié):
本系統(tǒng)是在湯蓉老師的悉心指導(dǎo)下順利完成的,從系統(tǒng)的選題、方案的制定以及論文的撰寫(xiě),每一步都傾注著我們整個(gè)團(tuán)隊(duì)的心血。在此,衷心感謝大家對(duì)我們這個(gè)項(xiàng)目整個(gè)過(guò)程的積極籌劃以及出謀劃策,在面對(duì)困難的時(shí)候大家共通過(guò)不放棄,通過(guò)各種辦法解決各種困難在此同時(shí)感謝湯蓉和徐振明老師,縝密的邏輯,活躍的思維,敏銳的洞察力,嚴(yán)謹(jǐn)?shù)闹螌W(xué)態(tài)度以及民主的作風(fēng)給我留下了深刻的印象,為我開(kāi)闊了視野,豐富了學(xué)識(shí),并將使我受益終身,我學(xué)習(xí)的楷模;湯蓉老師的工作態(tài)度和說(shuō)教方式讓我們感到很親切與他相處的也很融洽。感謝計(jì)算機(jī)科學(xué)與技術(shù)專業(yè)、計(jì)算機(jī)系的全體老師辛勤培養(yǎng)和教誨!
完整源碼下載地址
JavaSwing系列項(xiàng)目推薦:
基于JavaSwing的經(jīng)典坦克大戰(zhàn)游戲設(shè)計(jì)實(shí)現(xiàn)
基于JavaSwing ATM取款機(jī)系統(tǒng)的設(shè)計(jì)和實(shí)現(xiàn)
基于JavaSwing+mysql的學(xué)生社團(tuán)管理系統(tǒng)設(shè)計(jì)和實(shí)現(xiàn)
打卡JavaSwing項(xiàng)目更新?2?/ 100篇
大家可以點(diǎn)贊、收藏、關(guān)注、評(píng)論我啦?
總結(jié)
以上是生活随笔為你收集整理的基于JavaSwing+mysql的图书管理系统设计和实现的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: HTML+CSS+JS实现 ❤️照相机快
- 下一篇: https脚本调linux执行器,lin