This is the 23rd day of my participation in the August More Text Challenge

Preface:

The project is developed using Java Swing, which can achieve basic data maintenance, book type management and maintenance, book information management and maintenance, logout and exit, about the author profile and other functions. The interface design is relatively brief, suitable for Java class design and learning technology.

The introduction

With the rapid development of computer and network technology, Intranet applications are increasingly popular in the world. Today’s society is rapidly advancing to the information society, and the role of information system is becoming more and more important. In normal operation, the library always faces a large number of reader information, book information and the information of borrowing books and returning books produced by the interaction of the two. Therefore, library management information is the inevitable trend of development. With the method of structured system analysis and design, establish a set of effective books information management system, can reduce the work, the work of scientific, standardized, improve the quality of library information management so according to the actual management of the library to develop a set of winter books management system is a necessary.

Main technologies and tools:

eclipse+JDK1.. 8+Navicat +swing +mysql

Function screenshots:

Book Type Management:

Book type management and maintenance, can view the book information according to the book type, can delete and modify the book type information according to the number and information

Library information Management:

Book information maintenance management, click The book maintenance can be based on the book name, author and book type fuzzy query book information, you can click the following input box for data modification and deletion operation

Select data to modify or delete

 

Book add:

  

About the author:

Logout exit:

Key code:

Main entry:

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(" library MainFrm "); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 450, 300); JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar); JMenu = new JMenu(" Basic data maintenance "); menu.setIcon(new ImageIcon(MainFrm.class.getResource("/images/base.png"))); menuBar.add(menu); JMenu mnNewMenu = new JMenu(" Book category management "); mnNewMenu.setIcon(new ImageIcon(MainFrm.class.getResource("/images/bookTypeManager.png"))); menu.add(mnNewMenu); JMenuItem menuItem = new JMenuItem(" Add book category "); 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(" Book category maintenance "); 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(" Library "); mnNewMenu_1.setIcon(new ImageIcon(MainFrm.class.getResource("/images/bookManager.png"))); menu.add(mnNewMenu_1); JMenuItem menuItem_1 = new JMenuItem(" Book add "); 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(" Book maintenance "); 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(" exit "); menuItem_3.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int result = JOptionPane. ShowConfirmDialog (null, "whether to exit the system"); }}); menuItem_3.setIcon(new ImageIcon(MainFrm.class.getResource("/images/exit.png"))); menu.add(menuItem_3); JMenu menu_1 = new JMenu(" about author "); menu_1.setIcon(new ImageIcon(MainFrm.class.getResource("/images/about.png"))); menuBar.add(menu_1); JMenuItem mntmhpioneer = new JMenuItem(" About Oscar "); 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); // Set Jrame to maximize this.setextendedState (jframe.maximized_both); }}Copy the code

Add books:

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{
			
		}
	}
}

		
	
Copy the code

Database design:

The users table:

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
;
Copy the code

Book table:

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
;
Copy the code

List of book types

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
;
Copy the code

Note: the project comes from the network, the author arranges and optimizes the test, if has the infringement contact the author to delete

Conclusion:

This system is successfully completed under the careful guidance of Teacher Tang Rong, from the system topic selection, the formulation of the scheme and the writing of the paper, every step of our team has poured into the effort. Here, I sincerely thank you all for us the whole process of the project planning and ideas actively, in the face of difficulties all join by not giving up, through a variety of means to solve various difficulties at the same time thank Shang Rong and zhen-ming xu teacher, rigorous logic, active thinking, keen insight, rigorous doing scholarly research attitude and democratic attitude left a deep impression on me, Broaden my horizons, enrich my knowledge, and will benefit me for life, I learn the model; Teacher Tang Rong’s working attitude and preaching way make us feel very cordial and get along with him very harmoniously. Thanks to all the teachers of computer Science and Technology major and computer Department for their hard cultivation and instruction!

Javascript project updates 2/100

Everyone can like, like, follow and comment on me now