├── .classpath ├── .project ├── .settings └── org.eclipse.jdt.core.prefs ├── README.md ├── bin ├── com │ └── ccx │ │ ├── dao │ │ ├── BookDao.class │ │ ├── BookTypeDao.class │ │ └── UserDao.class │ │ ├── model │ │ ├── Book.class │ │ ├── BookType.class │ │ └── User.class │ │ ├── util │ │ ├── Dbutil.class │ │ └── StringUtil.class │ │ └── view │ │ ├── BookAddInterFrm$1.class │ │ ├── BookAddInterFrm$2.class │ │ ├── BookAddInterFrm$3.class │ │ ├── BookAddInterFrm.class │ │ ├── BookManagerInterFrm$1.class │ │ ├── BookManagerInterFrm$2.class │ │ ├── BookManagerInterFrm$3.class │ │ ├── BookManagerInterFrm$4.class │ │ ├── BookManagerInterFrm$5.class │ │ ├── BookManagerInterFrm$6.class │ │ ├── BookManagerInterFrm.class │ │ ├── BookTypeAddInterFrm$1.class │ │ ├── BookTypeAddInterFrm$2.class │ │ ├── BookTypeAddInterFrm$3.class │ │ ├── BookTypeAddInterFrm.class │ │ ├── BookTypeManagerInterFrm$1.class │ │ ├── BookTypeManagerInterFrm$2.class │ │ ├── BookTypeManagerInterFrm$3.class │ │ ├── BookTypeManagerInterFrm$4.class │ │ ├── BookTypeManagerInterFrm$5.class │ │ ├── BookTypeManagerInterFrm$6.class │ │ ├── BookTypeManagerInterFrm.class │ │ ├── Java$1.class │ │ ├── Java.class │ │ ├── LogOnFrm$1.class │ │ ├── LogOnFrm$2.class │ │ ├── LogOnFrm$3.class │ │ ├── LogOnFrm.class │ │ ├── MianFrm$1.class │ │ ├── MianFrm$2.class │ │ ├── MianFrm$3.class │ │ ├── MianFrm$4.class │ │ ├── MianFrm$5.class │ │ ├── MianFrm$6.class │ │ ├── MianFrm$7.class │ │ └── MianFrm.class └── images │ ├── about.png │ ├── add.png │ ├── base.png │ ├── bookManager.png │ ├── bookTypeManager.png │ ├── ccx.png │ ├── delete.png │ ├── edit.png │ ├── exit.png │ ├── login.png │ ├── logo.png │ ├── me.png │ ├── modify.png │ ├── password.png │ ├── reset.png │ ├── search.png │ └── userName.png ├── jdbc └── mysql-connector-java-8.0.18.jar ├── src ├── com │ └── ccx │ │ ├── dao │ │ ├── BookDao.java │ │ ├── BookTypeDao.java │ │ └── UserDao.java │ │ ├── model │ │ ├── Book.java │ │ ├── BookType.java │ │ └── User.java │ │ ├── util │ │ ├── Dbutil.java │ │ └── StringUtil.java │ │ └── view │ │ ├── BookAddInterFrm.java │ │ ├── BookManagerInterFrm.java │ │ ├── BookTypeAddInterFrm.java │ │ ├── BookTypeManagerInterFrm.java │ │ ├── Java.java │ │ ├── LogOnFrm.java │ │ └── MianFrm.java └── images │ ├── about.png │ ├── add.png │ ├── base.png │ ├── bookManager.png │ ├── bookTypeManager.png │ ├── ccx.png │ ├── delete.png │ ├── edit.png │ ├── exit.png │ ├── login.png │ ├── logo.png │ ├── me.png │ ├── modify.png │ ├── password.png │ ├── reset.png │ ├── search.png │ └── userName.png └── 项目截图 ├── Mysql8数据库三张表.PNG ├── t_booktype表设计.PNG ├── t_book表设计.PNG ├── t_user表设计.PNG ├── 主界面1.png ├── 主界面2.png ├── 图书添加.PNG ├── 图书类别添加.PNG ├── 图书类别管理.PNG ├── 图书维护.PNG └── 管理员登陆.PNG /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | BookManager 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 5 | org.eclipse.jdt.core.compiler.compliance=1.8 6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 10 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 11 | org.eclipse.jdt.core.compiler.source=1.8 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # BookManager 2 | Mysql+Swing+Java 图书管理系统 3 | -------------------------------------------------------------------------------- /bin/com/ccx/dao/BookDao.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/bin/com/ccx/dao/BookDao.class -------------------------------------------------------------------------------- /bin/com/ccx/dao/BookTypeDao.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/bin/com/ccx/dao/BookTypeDao.class -------------------------------------------------------------------------------- /bin/com/ccx/dao/UserDao.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/bin/com/ccx/dao/UserDao.class -------------------------------------------------------------------------------- /bin/com/ccx/model/Book.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/bin/com/ccx/model/Book.class -------------------------------------------------------------------------------- /bin/com/ccx/model/BookType.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/bin/com/ccx/model/BookType.class -------------------------------------------------------------------------------- /bin/com/ccx/model/User.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/bin/com/ccx/model/User.class -------------------------------------------------------------------------------- /bin/com/ccx/util/Dbutil.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/bin/com/ccx/util/Dbutil.class -------------------------------------------------------------------------------- /bin/com/ccx/util/StringUtil.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/bin/com/ccx/util/StringUtil.class -------------------------------------------------------------------------------- /bin/com/ccx/view/BookAddInterFrm$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/bin/com/ccx/view/BookAddInterFrm$1.class -------------------------------------------------------------------------------- /bin/com/ccx/view/BookAddInterFrm$2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/bin/com/ccx/view/BookAddInterFrm$2.class -------------------------------------------------------------------------------- /bin/com/ccx/view/BookAddInterFrm$3.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/bin/com/ccx/view/BookAddInterFrm$3.class -------------------------------------------------------------------------------- /bin/com/ccx/view/BookAddInterFrm.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/bin/com/ccx/view/BookAddInterFrm.class -------------------------------------------------------------------------------- /bin/com/ccx/view/BookManagerInterFrm$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/bin/com/ccx/view/BookManagerInterFrm$1.class -------------------------------------------------------------------------------- /bin/com/ccx/view/BookManagerInterFrm$2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/bin/com/ccx/view/BookManagerInterFrm$2.class -------------------------------------------------------------------------------- /bin/com/ccx/view/BookManagerInterFrm$3.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/bin/com/ccx/view/BookManagerInterFrm$3.class -------------------------------------------------------------------------------- /bin/com/ccx/view/BookManagerInterFrm$4.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/bin/com/ccx/view/BookManagerInterFrm$4.class -------------------------------------------------------------------------------- /bin/com/ccx/view/BookManagerInterFrm$5.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/bin/com/ccx/view/BookManagerInterFrm$5.class -------------------------------------------------------------------------------- /bin/com/ccx/view/BookManagerInterFrm$6.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/bin/com/ccx/view/BookManagerInterFrm$6.class -------------------------------------------------------------------------------- /bin/com/ccx/view/BookManagerInterFrm.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/bin/com/ccx/view/BookManagerInterFrm.class -------------------------------------------------------------------------------- /bin/com/ccx/view/BookTypeAddInterFrm$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/bin/com/ccx/view/BookTypeAddInterFrm$1.class -------------------------------------------------------------------------------- /bin/com/ccx/view/BookTypeAddInterFrm$2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/bin/com/ccx/view/BookTypeAddInterFrm$2.class -------------------------------------------------------------------------------- /bin/com/ccx/view/BookTypeAddInterFrm$3.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/bin/com/ccx/view/BookTypeAddInterFrm$3.class -------------------------------------------------------------------------------- /bin/com/ccx/view/BookTypeAddInterFrm.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/bin/com/ccx/view/BookTypeAddInterFrm.class -------------------------------------------------------------------------------- /bin/com/ccx/view/BookTypeManagerInterFrm$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/bin/com/ccx/view/BookTypeManagerInterFrm$1.class -------------------------------------------------------------------------------- /bin/com/ccx/view/BookTypeManagerInterFrm$2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/bin/com/ccx/view/BookTypeManagerInterFrm$2.class -------------------------------------------------------------------------------- /bin/com/ccx/view/BookTypeManagerInterFrm$3.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/bin/com/ccx/view/BookTypeManagerInterFrm$3.class -------------------------------------------------------------------------------- /bin/com/ccx/view/BookTypeManagerInterFrm$4.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/bin/com/ccx/view/BookTypeManagerInterFrm$4.class -------------------------------------------------------------------------------- /bin/com/ccx/view/BookTypeManagerInterFrm$5.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/bin/com/ccx/view/BookTypeManagerInterFrm$5.class -------------------------------------------------------------------------------- /bin/com/ccx/view/BookTypeManagerInterFrm$6.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/bin/com/ccx/view/BookTypeManagerInterFrm$6.class -------------------------------------------------------------------------------- /bin/com/ccx/view/BookTypeManagerInterFrm.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/bin/com/ccx/view/BookTypeManagerInterFrm.class -------------------------------------------------------------------------------- /bin/com/ccx/view/Java$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/bin/com/ccx/view/Java$1.class -------------------------------------------------------------------------------- /bin/com/ccx/view/Java.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/bin/com/ccx/view/Java.class -------------------------------------------------------------------------------- /bin/com/ccx/view/LogOnFrm$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/bin/com/ccx/view/LogOnFrm$1.class -------------------------------------------------------------------------------- /bin/com/ccx/view/LogOnFrm$2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/bin/com/ccx/view/LogOnFrm$2.class -------------------------------------------------------------------------------- /bin/com/ccx/view/LogOnFrm$3.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/bin/com/ccx/view/LogOnFrm$3.class -------------------------------------------------------------------------------- /bin/com/ccx/view/LogOnFrm.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/bin/com/ccx/view/LogOnFrm.class -------------------------------------------------------------------------------- /bin/com/ccx/view/MianFrm$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/bin/com/ccx/view/MianFrm$1.class -------------------------------------------------------------------------------- /bin/com/ccx/view/MianFrm$2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/bin/com/ccx/view/MianFrm$2.class -------------------------------------------------------------------------------- /bin/com/ccx/view/MianFrm$3.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/bin/com/ccx/view/MianFrm$3.class -------------------------------------------------------------------------------- /bin/com/ccx/view/MianFrm$4.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/bin/com/ccx/view/MianFrm$4.class -------------------------------------------------------------------------------- /bin/com/ccx/view/MianFrm$5.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/bin/com/ccx/view/MianFrm$5.class -------------------------------------------------------------------------------- /bin/com/ccx/view/MianFrm$6.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/bin/com/ccx/view/MianFrm$6.class -------------------------------------------------------------------------------- /bin/com/ccx/view/MianFrm$7.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/bin/com/ccx/view/MianFrm$7.class -------------------------------------------------------------------------------- /bin/com/ccx/view/MianFrm.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/bin/com/ccx/view/MianFrm.class -------------------------------------------------------------------------------- /bin/images/about.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/bin/images/about.png -------------------------------------------------------------------------------- /bin/images/add.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/bin/images/add.png -------------------------------------------------------------------------------- /bin/images/base.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/bin/images/base.png -------------------------------------------------------------------------------- /bin/images/bookManager.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/bin/images/bookManager.png -------------------------------------------------------------------------------- /bin/images/bookTypeManager.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/bin/images/bookTypeManager.png -------------------------------------------------------------------------------- /bin/images/ccx.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/bin/images/ccx.png -------------------------------------------------------------------------------- /bin/images/delete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/bin/images/delete.png -------------------------------------------------------------------------------- /bin/images/edit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/bin/images/edit.png -------------------------------------------------------------------------------- /bin/images/exit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/bin/images/exit.png -------------------------------------------------------------------------------- /bin/images/login.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/bin/images/login.png -------------------------------------------------------------------------------- /bin/images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/bin/images/logo.png -------------------------------------------------------------------------------- /bin/images/me.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/bin/images/me.png -------------------------------------------------------------------------------- /bin/images/modify.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/bin/images/modify.png -------------------------------------------------------------------------------- /bin/images/password.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/bin/images/password.png -------------------------------------------------------------------------------- /bin/images/reset.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/bin/images/reset.png -------------------------------------------------------------------------------- /bin/images/search.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/bin/images/search.png -------------------------------------------------------------------------------- /bin/images/userName.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/bin/images/userName.png -------------------------------------------------------------------------------- /jdbc/mysql-connector-java-8.0.18.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/jdbc/mysql-connector-java-8.0.18.jar -------------------------------------------------------------------------------- /src/com/ccx/dao/BookDao.java: -------------------------------------------------------------------------------- 1 | package com.ccx.dao; 2 | 3 | import java.sql.Connection; 4 | import java.sql.PreparedStatement; 5 | import java.sql.ResultSet; 6 | 7 | import com.ccx.model.Book; 8 | import com.ccx.util.StringUtil; 9 | 10 | /** 11 | * 图书Dao类 12 | * @author dell 13 | * 14 | */ 15 | public class BookDao { 16 | /** 17 | * 图书添加 18 | * @param con 19 | * @param book 20 | * @return 21 | * @throws Exception 22 | */ 23 | public int add(Connection con,Book book)throws Exception{ 24 | String sql="insert into t_book values(null,?,?,?,?,?,?)"; 25 | PreparedStatement pstmt=con.prepareStatement(sql); 26 | pstmt.setString(1,book.getBookName()); 27 | pstmt.setString(2,book.getAuthor()); 28 | pstmt.setString(3,book.getSex()); 29 | pstmt.setFloat(4,book.getPrice()); 30 | pstmt.setInt(5,book.getBookTypeId()); 31 | pstmt.setString(6,book.getBookDesc()); 32 | return pstmt.executeUpdate(); 33 | } 34 | 35 | /** 36 | * 图书信息查询 37 | * @param con 38 | * @param book 39 | * @return 40 | * @throws Exception 41 | */ 42 | public ResultSet list(Connection con,Book book)throws Exception { 43 | //数据拼接 44 | StringBuffer sb=new StringBuffer("select * from t_book b,t_booktype bt where b.bookTypeId=bt.id"); 45 | if(StringUtil.isNotEmpty(book.getBookName())) { 46 | sb.append(" and b.bookName like '%"+book.getBookName()+"%'"); 47 | } 48 | if(StringUtil.isNotEmpty(book.getAuthor())) { 49 | sb.append(" and b.author like '%"+book.getAuthor()+"%'"); 50 | } 51 | if(book.getBookTypeId()!=null && book.getBookTypeId()!=-1) { 52 | sb.append(" and b.bookTypeId="+book.getBookTypeId()); 53 | } 54 | PreparedStatement pstmt=con.prepareStatement(sb.toString()); 55 | return pstmt.executeQuery(); 56 | } 57 | 58 | /** 59 | * 图书信息删除 60 | * @param con 61 | * @param id 62 | * @return 63 | */ 64 | public int delete(Connection con,String id) throws Exception{ 65 | String sql="delete from t_book where id=?"; 66 | PreparedStatement pstmt=con.prepareStatement(sql); 67 | pstmt.setString(1, id); 68 | return pstmt.executeUpdate(); 69 | } 70 | 71 | /** 72 | * 图书信息修改 73 | * @param con 74 | * @param book 75 | * @return 76 | * @throws Exception 77 | */ 78 | public int update(Connection con,Book book) throws Exception{ 79 | String sql="update t_book set bookName=?,author=?,sex=?,price=?,bookDesc=?,bookTypeId=? where id=?"; 80 | PreparedStatement pstmt=con.prepareStatement(sql); 81 | pstmt.setString(1, book.getBookName()); 82 | pstmt.setString(2, book.getAuthor()); 83 | pstmt.setString(3, book.getSex()); 84 | pstmt.setFloat(4, book.getPrice()); 85 | pstmt.setString(5, book.getBookDesc()); 86 | pstmt.setInt(6, book.getBookTypeId()); 87 | pstmt.setInt(7,book.getId()); 88 | return pstmt.executeUpdate(); 89 | } 90 | /** 91 | * 指定图书类别下是否存在图书 92 | * @param con 93 | * @param bookTypeId 94 | * @return 95 | * @throws Exception 96 | */ 97 | public boolean existBookByBookTypeId(Connection con,String bookTypeId) throws Exception{ 98 | String sql="select * from t_book where bookTypeId=?"; 99 | PreparedStatement pstmt=con.prepareStatement(sql); 100 | pstmt.setString(1,bookTypeId ); 101 | ResultSet rs=pstmt.executeQuery(); 102 | return rs.next(); 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /src/com/ccx/dao/BookTypeDao.java: -------------------------------------------------------------------------------- 1 | package com.ccx.dao; 2 | 3 | import java.sql.Connection; 4 | import java.sql.PreparedStatement; 5 | import java.sql.ResultSet; 6 | 7 | import com.ccx.model.BookType; 8 | import com.ccx.util.StringUtil; 9 | 10 | /* 11 | * 图书类别添加 12 | */ 13 | public class BookTypeDao { 14 | public int add(Connection con,BookType bookType) throws Exception{ 15 | String sql="insert into t_bookType values(null,?,?)"; 16 | PreparedStatement pstmt=con.prepareStatement(sql); 17 | pstmt.setString(1,bookType.getBookTypeName()); 18 | pstmt.setString(2,bookType.getBookTypeDesc()); 19 | return pstmt.executeUpdate(); 20 | } 21 | /** 22 | * 查询图书类别集合 23 | * @param con 24 | * @param booktype 25 | * @return 26 | * @throws Exception 27 | */ 28 | public ResultSet list(Connection con,BookType bookType) throws Exception{ 29 | StringBuffer sb=new StringBuffer("select * from t_booktype"); 30 | if(StringUtil.isNotEmpty(bookType.getBookTypeName())) { 31 | sb.append(" and bookTypeName like '%"+bookType.getBookTypeName()+"%'"); 32 | } 33 | PreparedStatement pstmt=con.prepareStatement(sb.toString().replaceFirst("and", "where")); 34 | return pstmt.executeQuery(); 35 | } 36 | /** 37 | * 删除图书类别 38 | * @param con 39 | * @param id 40 | * @return 41 | * @throws Exception 42 | */ 43 | public int delete(Connection con,String id) throws Exception{ 44 | String sql="delete from t_bookType where id=?"; 45 | PreparedStatement pstmt=con.prepareStatement(sql); 46 | pstmt.setString(1, id); 47 | return pstmt.executeUpdate(); 48 | } 49 | 50 | /** 51 | * 更新图书类别 52 | * @param con 53 | * @param bookType 54 | * @return 55 | * @throws Exception 56 | */ 57 | public int update(Connection con,BookType bookType)throws Exception{ 58 | String sql="update t_bookType set bookTypeName=?,bookTypeDesc=? where id=?"; 59 | PreparedStatement pstmt=con.prepareStatement(sql); 60 | pstmt.setString(1, bookType.getBookTypeName()); 61 | pstmt.setString(2, bookType.getBookTypeDesc()); 62 | pstmt.setInt(3, bookType.getId()); 63 | return pstmt.executeUpdate(); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/com/ccx/dao/UserDao.java: -------------------------------------------------------------------------------- 1 | package com.ccx.dao; 2 | 3 | import java.sql.Connection; 4 | import java.sql.PreparedStatement; 5 | import java.sql.ResultSet; 6 | 7 | import com.ccx.model.User; 8 | 9 | /** 10 | * 用户Dao类 11 | * @author dell 12 | * 13 | */ 14 | public class UserDao { 15 | /** 16 | * 登陆验证 17 | * @param con 18 | * @param user 19 | * @return 20 | * @throws Exception 21 | */ 22 | public User login(Connection con,User user) throws Exception{ //user是从界面封装好的实体 23 | User resultUser=null; 24 | String sql="select * from t_user where userName = ? and password = ?"; 25 | PreparedStatement pstmt=con.prepareStatement(sql); 26 | pstmt.setString(1,user.getUserName()); 27 | pstmt.setString(2,user.getPassword());//设置? 28 | ResultSet rs=pstmt.executeQuery();//执行sql语句,返回结果集 ctl+shift+o 29 | if(rs.next()) {//判断是否有结果集,进行实例化 30 | resultUser=new User(); 31 | resultUser.setId(rs.getInt("id")); 32 | resultUser.setUserName(rs.getString("userName")); 33 | resultUser.setPassword("password"); 34 | } 35 | return resultUser; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/com/ccx/model/Book.java: -------------------------------------------------------------------------------- 1 | package com.ccx.model; 2 | 3 | /** 4 | * 图书实体 5 | * @author dell 6 | * 7 | */ 8 | public class Book { 9 | private int id;//编号 10 | private String bookName;//图书名称 11 | private String author;//作者 12 | private String sex;//性别 13 | private Float price;//图书价格 14 | private Integer bookTypeId;//图书类别id 15 | private String bookTypeName;//图书类别名称 16 | private String bookDesc;//备注 17 | 18 | public Book() { 19 | super(); 20 | // TODO Auto-generated constructor stub 21 | } 22 | 23 | 24 | 25 | public Book(int id, String bookName, String author, String sex, Float price, Integer bookTypeId, String bookDesc) { 26 | super(); 27 | this.id = id; 28 | this.bookName = bookName; 29 | this.author = author; 30 | this.sex = sex; 31 | this.price = price; 32 | this.bookTypeId = bookTypeId; 33 | this.bookDesc = bookDesc; 34 | } 35 | 36 | 37 | 38 | public Book(String bookName, String author, Integer bookTypeId) { 39 | super(); 40 | this.bookName = bookName; 41 | this.author = author; 42 | this.bookTypeId = bookTypeId; 43 | } 44 | 45 | 46 | 47 | public Book(String bookName, String author, String sex, Float price, Integer bookTypeId, String bookDesc) { 48 | super(); 49 | this.bookName = bookName; 50 | this.author = author; 51 | this.sex = sex; 52 | this.price = price; 53 | this.bookTypeId = bookTypeId; 54 | this.bookDesc = bookDesc; 55 | } 56 | 57 | 58 | 59 | public int getId() { 60 | return id; 61 | } 62 | public void setId(int id) { 63 | this.id = id; 64 | } 65 | public String getBookName() { 66 | return bookName; 67 | } 68 | public void setBookName(String bookName) { 69 | this.bookName = bookName; 70 | } 71 | public String getAuthor() { 72 | return author; 73 | } 74 | public void setAuthor(String author) { 75 | this.author = author; 76 | } 77 | public String getSex() { 78 | return sex; 79 | } 80 | public void setSex(String sex) { 81 | this.sex = sex; 82 | } 83 | public Float getPrice() { 84 | return price; 85 | } 86 | public void setPrice(Float price) { 87 | this.price = price; 88 | } 89 | public Integer getBookTypeId() { 90 | return bookTypeId; 91 | } 92 | public void setBookTypeId(Integer bookTypeId) { 93 | this.bookTypeId = bookTypeId; 94 | } 95 | public String getBookTypeName() { 96 | return bookTypeName; 97 | } 98 | public void setBookTypeName(String bookTypeName) { 99 | this.bookTypeName = bookTypeName; 100 | } 101 | public String getBookDesc() { 102 | return bookDesc; 103 | } 104 | public void setBookDesc(String bookDesc) { 105 | this.bookDesc = bookDesc; 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /src/com/ccx/model/BookType.java: -------------------------------------------------------------------------------- 1 | package com.ccx.model; 2 | 3 | /** 4 | * 图书类别实体 5 | * @author dell 6 | * 7 | */ 8 | public class BookType { 9 | private int id;//编号 10 | private String bookTypeName; 11 | private String bookTypeDesc;//备注 12 | 13 | public BookType(String bookTypeName, String bookTypeDesc) { 14 | super(); 15 | this.bookTypeName = bookTypeName; 16 | this.bookTypeDesc = bookTypeDesc; 17 | } 18 | 19 | 20 | public BookType(int id, String bookTypeName, String bookTypeDesc) { 21 | super(); 22 | this.id = id; 23 | this.bookTypeName = bookTypeName; 24 | this.bookTypeDesc = bookTypeDesc; 25 | } 26 | 27 | 28 | public BookType() { 29 | super(); 30 | // TODO Auto-generated constructor stub 31 | } 32 | public int getId() { 33 | return id; 34 | } 35 | public void setId(int id) { 36 | this.id = id; 37 | } 38 | public String getBookTypeName() { 39 | return bookTypeName; 40 | } 41 | public void setBookTypeName(String bookTypeName) { 42 | this.bookTypeName = bookTypeName; 43 | } 44 | 45 | public String getBookTypeDesc() { 46 | return bookTypeDesc; 47 | } 48 | public void setBookTypeDesc(String bookTypeDesc) { 49 | this.bookTypeDesc = bookTypeDesc; 50 | } 51 | 52 | @Override 53 | public String toString() { 54 | return bookTypeName; 55 | } 56 | 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/com/ccx/model/User.java: -------------------------------------------------------------------------------- 1 | package com.ccx.model; 2 | 3 | /** 4 | * 用户实体 5 | * @author dell 6 | * 7 | */ 8 | public class User { 9 | private String userName; 10 | private String password; 11 | private int id; 12 | 13 | 14 | public User() { 15 | super(); 16 | // TODO Auto-generated constructor stub 17 | } 18 | 19 | public User(String userName, String password) { 20 | super(); 21 | this.userName = userName; 22 | this.password = password; 23 | } 24 | 25 | public String getUserName() { 26 | return userName; 27 | } 28 | public void setUserName(String userName) { 29 | this.userName = userName; 30 | } 31 | public String getPassword() { 32 | return password; 33 | } 34 | public void setPassword(String password) { 35 | this.password = password; 36 | } 37 | public int getId() { 38 | return id; 39 | } 40 | public void setId(int id) { 41 | this.id = id; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/com/ccx/util/Dbutil.java: -------------------------------------------------------------------------------- 1 | package com.ccx.util; 2 | 3 | import java.sql.Connection; 4 | import java.sql.DriverManager; 5 | 6 | /** 7 | * 数据库工具类 8 | * @author dell 9 | * 10 | */ 11 | 12 | public class Dbutil { 13 | private String dbUrl="jdbc:mysql://localhost:3308/db_book?useSSL=false&serverTimezone=UTC";//数据库连接地址 14 | private String dbUserName="root"; 15 | private String dbPassWord="1234"; 16 | private String jdbcName="com.mysql.cj.jdbc.Driver";//驱动名称 17 | 18 | 19 | //获取数据库连接 20 | public Connection getCon() throws Exception{ 21 | Class.forName(jdbcName);//反射加载一下类名字 22 | Connection con=DriverManager.getConnection(dbUrl,dbUserName,dbPassWord); 23 | return con; 24 | } 25 | 26 | //关闭数据库连接 27 | public void closeCon(Connection con) throws Exception{ 28 | if(con!=null){ 29 | con.close(); 30 | } 31 | } 32 | 33 | public static void main(String[] args) {//main alt+/ 34 | Dbutil dbutil=new Dbutil(); 35 | try { 36 | dbutil.getCon(); 37 | System.out.println("数据库连接成功"); 38 | } catch (Exception e) { 39 | // TODO Auto-generated catch block 40 | e.printStackTrace(); 41 | System.out.println("数据库连接失败"); 42 | } 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/com/ccx/util/StringUtil.java: -------------------------------------------------------------------------------- 1 | package com.ccx.util; 2 | 3 | /** 4 | * 字符串工具类 5 | * @author dell 6 | * 7 | */ 8 | public class StringUtil { 9 | /** 10 | * 判断是否为空 11 | * @param str 12 | * @return 13 | */ 14 | public static boolean isEmpty(String str) { 15 | if(str==null||"".equals(str.trim())){ 16 | return true; 17 | }else { 18 | return false; 19 | } 20 | } 21 | 22 | public static boolean isNotEmpty(String str) { 23 | if(str!=null &&!"".equals(str.trim())) { 24 | return true; 25 | }else { 26 | return false; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/com/ccx/view/BookAddInterFrm.java: -------------------------------------------------------------------------------- 1 | package com.ccx.view; 2 | 3 | import java.awt.EventQueue; 4 | import java.awt.event.ActionEvent; 5 | import java.awt.event.ActionListener; 6 | import java.sql.Connection; 7 | import java.sql.ResultSet; 8 | 9 | import javax.swing.ButtonGroup; 10 | import javax.swing.GroupLayout; 11 | import javax.swing.GroupLayout.Alignment; 12 | import javax.swing.ImageIcon; 13 | import javax.swing.JButton; 14 | import javax.swing.JComboBox; 15 | import javax.swing.JInternalFrame; 16 | import javax.swing.JLabel; 17 | import javax.swing.JOptionPane; 18 | import javax.swing.JRadioButton; 19 | import javax.swing.JTextArea; 20 | import javax.swing.JTextField; 21 | import javax.swing.LayoutStyle.ComponentPlacement; 22 | import javax.swing.border.LineBorder; 23 | 24 | import com.ccx.dao.BookDao; 25 | import com.ccx.dao.BookTypeDao; 26 | import com.ccx.model.Book; 27 | import com.ccx.model.BookType; 28 | import com.ccx.util.Dbutil; 29 | import com.ccx.util.StringUtil; 30 | 31 | public class BookAddInterFrm extends JInternalFrame { 32 | private JTextField bookNameTxt; 33 | private JTextField authorTxt; 34 | private final ButtonGroup buttonGroup = new ButtonGroup(); 35 | private JTextField priceTxt; 36 | private JComboBox bookTypeJcb; 37 | private JTextArea bookDescTxt; 38 | private JRadioButton maleJrb; 39 | private JRadioButton femaleJrb; 40 | 41 | private Dbutil dbUtil=new Dbutil(); 42 | private BookTypeDao bookTypeDao=new BookTypeDao(); 43 | private BookDao bookDao=new BookDao(); 44 | 45 | /** 46 | * Launch the application. 47 | */ 48 | public static void main(String[] args) { 49 | EventQueue.invokeLater(new Runnable() { 50 | public void run() { 51 | try { 52 | BookAddInterFrm frame = new BookAddInterFrm(); 53 | frame.setVisible(true); 54 | } catch (Exception e) { 55 | e.printStackTrace(); 56 | } 57 | } 58 | }); 59 | } 60 | 61 | /** 62 | * Create the frame. 63 | */ 64 | public BookAddInterFrm() { 65 | setClosable(true); 66 | setIconifiable(true); 67 | setTitle("图书添加"); 68 | setBounds(100, 100, 594, 552); 69 | 70 | JLabel lblNewLabel = new JLabel("图书名称:"); 71 | 72 | bookNameTxt = new JTextField(); 73 | bookNameTxt.setColumns(10); 74 | 75 | JLabel lblNewLabel_1 = new JLabel("图书作者:"); 76 | 77 | authorTxt = new JTextField(); 78 | authorTxt.setColumns(10); 79 | 80 | JLabel lblNewLabel_2 = new JLabel("作者性别:"); 81 | 82 | maleJrb = new JRadioButton("男"); 83 | buttonGroup.add(maleJrb); 84 | maleJrb.setSelected(true); 85 | 86 | femaleJrb = new JRadioButton("女"); 87 | buttonGroup.add(femaleJrb); 88 | 89 | JLabel lblNewLabel_3 = new JLabel("图书价格:"); 90 | 91 | priceTxt = new JTextField(); 92 | priceTxt.setColumns(10); 93 | 94 | JLabel lblNewLabel_4 = new JLabel("图书描述:"); 95 | 96 | bookDescTxt = new JTextArea(); 97 | 98 | JLabel lblNewLabel_5 = new JLabel("图书类别:"); 99 | 100 | bookTypeJcb = new JComboBox(); 101 | 102 | JButton btnNewButton = new JButton("添加"); 103 | btnNewButton.addActionListener(new ActionListener() { 104 | public void actionPerformed(ActionEvent e) { 105 | bookAddActionPerformed(e); 106 | } 107 | }); 108 | btnNewButton.setIcon(new ImageIcon(BookAddInterFrm.class.getResource("/images/add.png"))); 109 | 110 | JButton btnNewButton_1 = new JButton("重置"); 111 | btnNewButton_1.addActionListener(new ActionListener() { 112 | public void actionPerformed(ActionEvent e) { 113 | resetValueActionPerformed(e); 114 | } 115 | }); 116 | btnNewButton_1.setIcon(new ImageIcon(BookAddInterFrm.class.getResource("/images/reset.png"))); 117 | GroupLayout groupLayout = new GroupLayout(getContentPane()); 118 | groupLayout.setHorizontalGroup( 119 | groupLayout.createParallelGroup(Alignment.LEADING) 120 | .addGroup(groupLayout.createSequentialGroup() 121 | .addGroup(groupLayout.createParallelGroup(Alignment.LEADING) 122 | .addGroup(groupLayout.createSequentialGroup() 123 | .addGap(49) 124 | .addGroup(groupLayout.createParallelGroup(Alignment.LEADING) 125 | .addGroup(groupLayout.createSequentialGroup() 126 | .addComponent(lblNewLabel_4) 127 | .addPreferredGap(ComponentPlacement.RELATED) 128 | .addComponent(bookDescTxt, GroupLayout.PREFERRED_SIZE, 371, GroupLayout.PREFERRED_SIZE)) 129 | .addGroup(groupLayout.createSequentialGroup() 130 | .addGroup(groupLayout.createParallelGroup(Alignment.LEADING) 131 | .addGroup(groupLayout.createSequentialGroup() 132 | .addComponent(lblNewLabel) 133 | .addGap(18) 134 | .addComponent(bookNameTxt, GroupLayout.PREFERRED_SIZE, 110, GroupLayout.PREFERRED_SIZE)) 135 | .addGroup(groupLayout.createSequentialGroup() 136 | .addComponent(lblNewLabel_2) 137 | .addPreferredGap(ComponentPlacement.UNRELATED) 138 | .addComponent(maleJrb) 139 | .addGap(18) 140 | .addComponent(femaleJrb))) 141 | .addGap(48) 142 | .addGroup(groupLayout.createParallelGroup(Alignment.LEADING, false) 143 | .addGroup(groupLayout.createSequentialGroup() 144 | .addComponent(lblNewLabel_1) 145 | .addPreferredGap(ComponentPlacement.RELATED) 146 | .addComponent(authorTxt)) 147 | .addGroup(groupLayout.createSequentialGroup() 148 | .addComponent(lblNewLabel_3) 149 | .addPreferredGap(ComponentPlacement.RELATED) 150 | .addComponent(priceTxt, GroupLayout.PREFERRED_SIZE, 111, GroupLayout.PREFERRED_SIZE)))) 151 | .addGroup(groupLayout.createSequentialGroup() 152 | .addComponent(lblNewLabel_5) 153 | .addPreferredGap(ComponentPlacement.UNRELATED) 154 | .addComponent(bookTypeJcb, GroupLayout.PREFERRED_SIZE, 108, GroupLayout.PREFERRED_SIZE)))) 155 | .addGroup(groupLayout.createSequentialGroup() 156 | .addGap(63) 157 | .addComponent(btnNewButton) 158 | .addGap(54) 159 | .addComponent(btnNewButton_1, GroupLayout.PREFERRED_SIZE, 102, GroupLayout.PREFERRED_SIZE))) 160 | .addContainerGap(77, Short.MAX_VALUE)) 161 | ); 162 | groupLayout.setVerticalGroup( 163 | groupLayout.createParallelGroup(Alignment.LEADING) 164 | .addGroup(groupLayout.createSequentialGroup() 165 | .addGap(46) 166 | .addGroup(groupLayout.createParallelGroup(Alignment.BASELINE) 167 | .addComponent(lblNewLabel) 168 | .addComponent(bookNameTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) 169 | .addComponent(lblNewLabel_1) 170 | .addComponent(authorTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) 171 | .addGap(31) 172 | .addGroup(groupLayout.createParallelGroup(Alignment.BASELINE) 173 | .addComponent(lblNewLabel_2) 174 | .addComponent(maleJrb) 175 | .addComponent(femaleJrb) 176 | .addComponent(lblNewLabel_3) 177 | .addComponent(priceTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) 178 | .addGap(29) 179 | .addGroup(groupLayout.createParallelGroup(Alignment.BASELINE) 180 | .addComponent(lblNewLabel_5) 181 | .addComponent(bookTypeJcb, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) 182 | .addGap(38) 183 | .addGroup(groupLayout.createParallelGroup(Alignment.BASELINE) 184 | .addComponent(lblNewLabel_4) 185 | .addComponent(bookDescTxt, GroupLayout.PREFERRED_SIZE, 150, GroupLayout.PREFERRED_SIZE)) 186 | .addGap(37) 187 | .addGroup(groupLayout.createParallelGroup(Alignment.BASELINE) 188 | .addComponent(btnNewButton) 189 | .addComponent(btnNewButton_1, GroupLayout.PREFERRED_SIZE, 39, GroupLayout.PREFERRED_SIZE)) 190 | .addContainerGap()) 191 | ); 192 | getContentPane().setLayout(groupLayout); 193 | 194 | //设置文本域边框 195 | bookDescTxt.setBorder(new LineBorder(new java.awt.Color(127,157,185),1,false)); 196 | 197 | filBookType(); 198 | 199 | } 200 | 201 | /** 202 | * 重置事件处理 203 | * @param e 204 | */ 205 | private void resetValueActionPerformed(ActionEvent e) { 206 | // TODO Auto-generated method stub 207 | this.resetValue(); 208 | } 209 | 210 | /** 211 | * 图书添加事件处理 212 | */ 213 | private void bookAddActionPerformed(ActionEvent evt) { 214 | // TODO Auto-generated method stub 215 | String bookName=this.bookNameTxt.getText(); 216 | String author=this.authorTxt.getText(); 217 | String price=this.priceTxt.getText(); 218 | String bookDesc=this.bookDescTxt.getText(); 219 | 220 | if(StringUtil.isEmpty(bookName)) { 221 | JOptionPane.showMessageDialog(null, "图书名称不能为空!"); 222 | return; 223 | } 224 | 225 | if(StringUtil.isEmpty(author)) { 226 | JOptionPane.showMessageDialog(null, "图书作者不能为空!"); 227 | return; 228 | } 229 | 230 | if(StringUtil.isEmpty(price)) { 231 | JOptionPane.showMessageDialog(null, "图书价格不能为空!"); 232 | return; 233 | } 234 | 235 | String sex=""; 236 | if(maleJrb.isSelected()) { 237 | sex="男"; 238 | }else if(femaleJrb.isSelected()){ 239 | sex="女"; 240 | } 241 | 242 | BookType bookType=(BookType) bookTypeJcb.getSelectedItem();//图书类别 243 | int bookTypeId=bookType.getId();//插入数据库 244 | 245 | Book book=new Book(bookName, author, sex, Float.parseFloat(price),bookTypeId,bookDesc); 246 | 247 | Connection con=null; 248 | try { 249 | con=dbUtil.getCon(); 250 | int addNum=bookDao.add(con,book); 251 | if(addNum==1) { 252 | JOptionPane.showMessageDialog(null, "图书添加成功!"); 253 | resetValue(); 254 | }else { 255 | JOptionPane.showMessageDialog(null, "图书添加失败!"); 256 | } 257 | }catch(Exception e) { 258 | e.printStackTrace(); 259 | JOptionPane.showMessageDialog(null, "图书添加失败!"); 260 | }finally { 261 | try { 262 | dbUtil.closeCon(con); 263 | } catch (Exception e) { 264 | // TODO Auto-generated catch block 265 | e.printStackTrace(); 266 | } 267 | } 268 | } 269 | 270 | /** 271 | * 重置表单 272 | */ 273 | private void resetValue() { 274 | // TODO Auto-generated method stub 275 | this.bookNameTxt.setText(""); 276 | this.authorTxt.setText(""); 277 | this.priceTxt.setText(""); 278 | this.maleJrb.setSelected(true); 279 | this.bookDescTxt.setText(""); 280 | if(this.bookTypeJcb.getItemCount()>0) 281 | //图书类别为空 282 | { 283 | this.bookTypeJcb.setSelectedIndex(0);//设置选中 284 | } 285 | } 286 | 287 | /** 288 | * 初始化图书类别下拉框 289 | */ 290 | private void filBookType() { 291 | Connection con=null; 292 | BookType bookType=null;//封装成数据添加进去 293 | try { 294 | con=dbUtil.getCon(); 295 | ResultSet rs=bookTypeDao.list(con, new BookType()); 296 | while(rs.next()) { 297 | bookType=new BookType(); 298 | bookType.setId(rs.getInt("id")); 299 | bookType.setBookTypeName(rs.getString("bookTypeName")); 300 | this.bookTypeJcb.addItem(bookType); 301 | } 302 | }catch(Exception e) { 303 | e.printStackTrace(); 304 | }finally { 305 | 306 | } 307 | } 308 | } 309 | -------------------------------------------------------------------------------- /src/com/ccx/view/BookManagerInterFrm.java: -------------------------------------------------------------------------------- 1 | package com.ccx.view; 2 | 3 | import java.awt.EventQueue; 4 | import java.awt.event.ActionEvent; 5 | import java.awt.event.ActionListener; 6 | import java.sql.Connection; 7 | import java.sql.ResultSet; 8 | import java.util.Vector; 9 | 10 | import javax.swing.GroupLayout; 11 | import javax.swing.GroupLayout.Alignment; 12 | import javax.swing.ImageIcon; 13 | import javax.swing.JButton; 14 | import javax.swing.JComboBox; 15 | import javax.swing.JInternalFrame; 16 | import javax.swing.JLabel; 17 | import javax.swing.JOptionPane; 18 | import javax.swing.JPanel; 19 | import javax.swing.JScrollPane; 20 | import javax.swing.JTable; 21 | import javax.swing.JTextField; 22 | import javax.swing.LayoutStyle.ComponentPlacement; 23 | import javax.swing.border.LineBorder; 24 | import javax.swing.border.TitledBorder; 25 | import javax.swing.table.DefaultTableModel; 26 | 27 | import com.ccx.dao.BookDao; 28 | import com.ccx.dao.BookTypeDao; 29 | import com.ccx.model.Book; 30 | import com.ccx.model.BookType; 31 | import com.ccx.util.Dbutil; 32 | import com.ccx.util.StringUtil; 33 | 34 | import javax.swing.JRadioButton; 35 | import javax.swing.ButtonGroup; 36 | import javax.swing.JTextArea; 37 | import java.awt.event.MouseAdapter; 38 | import java.awt.event.MouseEvent; 39 | 40 | public class BookManagerInterFrm extends JInternalFrame { 41 | private JTable bookTable; 42 | private JTextField s_bookNameTxt; 43 | private JTextField s_authorTxt; 44 | private JComboBox s_bookTypeJcb; 45 | 46 | private Dbutil dbutil=new Dbutil(); 47 | private BookTypeDao bookTypeDao=new BookTypeDao(); 48 | private BookDao bookDao=new BookDao(); 49 | private JTextField idTxt; 50 | private JTextField bookNameTxt; 51 | private final ButtonGroup buttonGroup = new ButtonGroup(); 52 | private JTextField priceTxt; 53 | private JTextField authorTxt; 54 | private JTextArea bookDescTxt; 55 | private JComboBox bookTypeJcb; 56 | 57 | private JRadioButton maleJrb; 58 | private JRadioButton femaleJrb; 59 | 60 | /** 61 | * Launch the application. 62 | */ 63 | public static void main(String[] args) { 64 | EventQueue.invokeLater(new Runnable() { 65 | public void run() { 66 | try { 67 | BookManagerInterFrm frame = new BookManagerInterFrm(); 68 | frame.setVisible(true); 69 | } catch (Exception e) { 70 | e.printStackTrace(); 71 | } 72 | } 73 | }); 74 | } 75 | 76 | /** 77 | * Create the frame. 78 | */ 79 | public BookManagerInterFrm() { 80 | setClosable(true); 81 | setIconifiable(true); 82 | setTitle("图书管理"); 83 | setBounds(100, 100, 822, 737); 84 | 85 | JScrollPane scrollPane = new JScrollPane(); 86 | 87 | JPanel panel = new JPanel(); 88 | panel.setBorder(new TitledBorder(null, "\u641C\u7D22\u6761\u4EF6", TitledBorder.LEADING, TitledBorder.TOP, null, null)); 89 | 90 | JPanel panel_1 = new JPanel(); 91 | panel_1.setBorder(new TitledBorder(null, "\u8868\u5355\u64CD\u4F5C", TitledBorder.LEADING, TitledBorder.TOP, null, null)); 92 | GroupLayout groupLayout = new GroupLayout(getContentPane()); 93 | groupLayout.setHorizontalGroup( 94 | groupLayout.createParallelGroup(Alignment.TRAILING) 95 | .addGroup(groupLayout.createSequentialGroup() 96 | .addGap(35) 97 | .addGroup(groupLayout.createParallelGroup(Alignment.TRAILING) 98 | .addComponent(panel_1, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 707, Short.MAX_VALUE) 99 | .addComponent(scrollPane, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 707, Short.MAX_VALUE) 100 | .addComponent(panel, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 707, Short.MAX_VALUE)) 101 | .addGap(32)) 102 | ); 103 | groupLayout.setVerticalGroup( 104 | groupLayout.createParallelGroup(Alignment.LEADING) 105 | .addGroup(groupLayout.createSequentialGroup() 106 | .addGap(31) 107 | .addComponent(panel, GroupLayout.PREFERRED_SIZE, 89, GroupLayout.PREFERRED_SIZE) 108 | .addGap(34) 109 | .addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, 165, GroupLayout.PREFERRED_SIZE) 110 | .addGap(18) 111 | .addComponent(panel_1, GroupLayout.DEFAULT_SIZE, 234, Short.MAX_VALUE) 112 | .addContainerGap()) 113 | ); 114 | 115 | JLabel lblNewLabel_3 = new JLabel("编号:"); 116 | 117 | idTxt = new JTextField(); 118 | idTxt.setEditable(false); 119 | idTxt.setColumns(10); 120 | 121 | JLabel lblNewLabel_4 = new JLabel("图书名称:"); 122 | 123 | bookNameTxt = new JTextField(); 124 | bookNameTxt.setColumns(10); 125 | 126 | JLabel lblNewLabel_5 = new JLabel("作者性别:"); 127 | 128 | maleJrb = new JRadioButton("男"); 129 | maleJrb.setSelected(true); 130 | buttonGroup.add(maleJrb); 131 | 132 | femaleJrb = new JRadioButton("女"); 133 | buttonGroup.add(femaleJrb); 134 | 135 | JLabel lblNewLabel_6 = new JLabel("价格:"); 136 | 137 | priceTxt = new JTextField(); 138 | priceTxt.setColumns(10); 139 | 140 | JLabel lblNewLabel_7 = new JLabel("图书作者:"); 141 | 142 | authorTxt = new JTextField(); 143 | authorTxt.setColumns(10); 144 | 145 | JLabel lblNewLabel_8 = new JLabel("图书类别:"); 146 | 147 | bookTypeJcb = new JComboBox(); 148 | 149 | JLabel lblNewLabel_9 = new JLabel("图书描述:"); 150 | 151 | bookDescTxt = new JTextArea(); 152 | 153 | JButton btnNewButton_1 = new JButton("修改"); 154 | btnNewButton_1.addActionListener(new ActionListener() { 155 | public void actionPerformed(ActionEvent evt) { 156 | bookUpdateActionPerformed(evt); 157 | } 158 | }); 159 | btnNewButton_1.setIcon(new ImageIcon(BookManagerInterFrm.class.getResource("/images/modify.png"))); 160 | 161 | JButton btnNewButton_2 = new JButton("删除"); 162 | btnNewButton_2.addActionListener(new ActionListener() { 163 | public void actionPerformed(ActionEvent evt) { 164 | bookDeleteActionPerformed(evt); 165 | } 166 | }); 167 | btnNewButton_2.setIcon(new ImageIcon(BookManagerInterFrm.class.getResource("/images/delete.png"))); 168 | GroupLayout gl_panel_1 = new GroupLayout(panel_1); 169 | gl_panel_1.setHorizontalGroup( 170 | gl_panel_1.createParallelGroup(Alignment.LEADING) 171 | .addGroup(gl_panel_1.createSequentialGroup() 172 | .addGap(26) 173 | .addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING) 174 | .addGroup(gl_panel_1.createSequentialGroup() 175 | .addComponent(lblNewLabel_9) 176 | .addPreferredGap(ComponentPlacement.RELATED) 177 | .addComponent(bookDescTxt, GroupLayout.PREFERRED_SIZE, 544, GroupLayout.PREFERRED_SIZE) 178 | .addContainerGap()) 179 | .addGroup(gl_panel_1.createSequentialGroup() 180 | .addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING) 181 | .addGroup(gl_panel_1.createSequentialGroup() 182 | .addComponent(lblNewLabel_3) 183 | .addPreferredGap(ComponentPlacement.RELATED) 184 | .addComponent(idTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) 185 | .addGroup(gl_panel_1.createSequentialGroup() 186 | .addComponent(lblNewLabel_6) 187 | .addPreferredGap(ComponentPlacement.RELATED) 188 | .addComponent(priceTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))) 189 | .addGap(77) 190 | .addGroup(gl_panel_1.createParallelGroup(Alignment.TRAILING) 191 | .addGroup(gl_panel_1.createSequentialGroup() 192 | .addComponent(lblNewLabel_4) 193 | .addPreferredGap(ComponentPlacement.UNRELATED) 194 | .addComponent(bookNameTxt, GroupLayout.DEFAULT_SIZE, 87, Short.MAX_VALUE)) 195 | .addGroup(gl_panel_1.createSequentialGroup() 196 | .addComponent(lblNewLabel_7) 197 | .addPreferredGap(ComponentPlacement.RELATED, 15, Short.MAX_VALUE) 198 | .addComponent(authorTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))) 199 | .addGap(77) 200 | .addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING) 201 | .addGroup(gl_panel_1.createSequentialGroup() 202 | .addComponent(lblNewLabel_5) 203 | .addPreferredGap(ComponentPlacement.UNRELATED) 204 | .addComponent(maleJrb) 205 | .addPreferredGap(ComponentPlacement.UNRELATED) 206 | .addComponent(femaleJrb)) 207 | .addGroup(gl_panel_1.createSequentialGroup() 208 | .addGap(4) 209 | .addComponent(lblNewLabel_8) 210 | .addGap(18) 211 | .addComponent(bookTypeJcb, GroupLayout.PREFERRED_SIZE, 94, GroupLayout.PREFERRED_SIZE))) 212 | .addGap(43)))) 213 | .addGroup(gl_panel_1.createSequentialGroup() 214 | .addGap(40) 215 | .addComponent(btnNewButton_1) 216 | .addGap(35) 217 | .addComponent(btnNewButton_2) 218 | .addContainerGap(476, Short.MAX_VALUE)) 219 | ); 220 | gl_panel_1.setVerticalGroup( 221 | gl_panel_1.createParallelGroup(Alignment.LEADING) 222 | .addGroup(gl_panel_1.createSequentialGroup() 223 | .addContainerGap() 224 | .addGroup(gl_panel_1.createParallelGroup(Alignment.BASELINE) 225 | .addComponent(bookNameTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) 226 | .addComponent(lblNewLabel_4) 227 | .addComponent(femaleJrb) 228 | .addComponent(maleJrb) 229 | .addComponent(lblNewLabel_5) 230 | .addComponent(idTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) 231 | .addComponent(lblNewLabel_3)) 232 | .addGap(27) 233 | .addGroup(gl_panel_1.createParallelGroup(Alignment.BASELINE) 234 | .addComponent(authorTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) 235 | .addComponent(lblNewLabel_7) 236 | .addComponent(priceTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) 237 | .addComponent(lblNewLabel_6) 238 | .addComponent(lblNewLabel_8) 239 | .addComponent(bookTypeJcb, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) 240 | .addGap(15) 241 | .addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING) 242 | .addComponent(lblNewLabel_9) 243 | .addComponent(bookDescTxt, GroupLayout.PREFERRED_SIZE, 112, GroupLayout.PREFERRED_SIZE)) 244 | .addPreferredGap(ComponentPlacement.RELATED, 35, Short.MAX_VALUE) 245 | .addGroup(gl_panel_1.createParallelGroup(Alignment.BASELINE) 246 | .addComponent(btnNewButton_1, GroupLayout.PREFERRED_SIZE, 37, GroupLayout.PREFERRED_SIZE) 247 | .addComponent(btnNewButton_2)) 248 | .addGap(34)) 249 | ); 250 | panel_1.setLayout(gl_panel_1); 251 | 252 | JLabel lblNewLabel = new JLabel("图书名称:"); 253 | 254 | s_bookNameTxt = new JTextField(); 255 | s_bookNameTxt.setColumns(10); 256 | 257 | JLabel lblNewLabel_1 = new JLabel("图书作者:"); 258 | 259 | s_authorTxt = new JTextField(); 260 | s_authorTxt.setColumns(10); 261 | 262 | JLabel lblNewLabel_2 = new JLabel("图书类别:"); 263 | 264 | s_bookTypeJcb = new JComboBox(); 265 | 266 | JButton btnNewButton = new JButton("查询"); 267 | btnNewButton.addActionListener(new ActionListener() { 268 | public void actionPerformed(ActionEvent e) { 269 | bookSearchActionPerformed(e); 270 | } 271 | }); 272 | btnNewButton.setIcon(new ImageIcon(BookManagerInterFrm.class.getResource("/images/search.png"))); 273 | GroupLayout gl_panel = new GroupLayout(panel); 274 | gl_panel.setHorizontalGroup( 275 | gl_panel.createParallelGroup(Alignment.LEADING) 276 | .addGroup(gl_panel.createSequentialGroup() 277 | .addComponent(lblNewLabel) 278 | .addPreferredGap(ComponentPlacement.RELATED) 279 | .addComponent(s_bookNameTxt, GroupLayout.PREFERRED_SIZE, 105, GroupLayout.PREFERRED_SIZE) 280 | .addGap(18) 281 | .addComponent(lblNewLabel_1) 282 | .addPreferredGap(ComponentPlacement.RELATED) 283 | .addComponent(s_authorTxt, GroupLayout.PREFERRED_SIZE, 97, GroupLayout.PREFERRED_SIZE) 284 | .addGap(18) 285 | .addComponent(lblNewLabel_2) 286 | .addPreferredGap(ComponentPlacement.RELATED) 287 | .addComponent(s_bookTypeJcb, 0, 79, Short.MAX_VALUE) 288 | .addGap(18) 289 | .addComponent(btnNewButton) 290 | .addContainerGap()) 291 | ); 292 | gl_panel.setVerticalGroup( 293 | gl_panel.createParallelGroup(Alignment.LEADING) 294 | .addGroup(gl_panel.createSequentialGroup() 295 | .addContainerGap() 296 | .addGroup(gl_panel.createParallelGroup(Alignment.BASELINE) 297 | .addComponent(lblNewLabel) 298 | .addComponent(s_bookNameTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) 299 | .addComponent(lblNewLabel_1) 300 | .addComponent(s_authorTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) 301 | .addComponent(lblNewLabel_2) 302 | .addComponent(s_bookTypeJcb, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) 303 | .addComponent(btnNewButton)) 304 | .addContainerGap(56, Short.MAX_VALUE)) 305 | ); 306 | panel.setLayout(gl_panel); 307 | 308 | bookTable = new JTable(); 309 | bookTable.addMouseListener(new MouseAdapter() { 310 | @Override 311 | public void mousePressed(MouseEvent emt) { 312 | bookTableMousePressed(emt); 313 | } 314 | }); 315 | scrollPane.setViewportView(bookTable); 316 | bookTable.setModel(new DefaultTableModel( 317 | new Object[][] { 318 | }, 319 | new String[] { 320 | "\u7F16\u53F7", "\u56FE\u4E66\u540D\u79F0", "\u56FE\u4E66\u4F5C\u8005", "\u4F5C\u8005\u6027\u522B", "\u56FE\u4E66\u4EF7\u683C", "\u56FE\u4E66\u63CF\u8FF0", "\u56FE\u4E66\u7C7B\u522B" 321 | } 322 | ) { 323 | boolean[] columnEditables = new boolean[] { 324 | false, false, false, false, false, false, false 325 | }; 326 | public boolean isCellEditable(int row, int column) { 327 | return columnEditables[column]; 328 | } 329 | }); 330 | bookTable.getColumnModel().getColumn(5).setPreferredWidth(107); 331 | getContentPane().setLayout(groupLayout); 332 | 333 | //设置文本域边框 334 | bookDescTxt.setBorder(new LineBorder(new java.awt.Color(127,157,185),1,false)); 335 | 336 | 337 | this.fillBookType("search"); 338 | this.fillBookType("modify"); 339 | this.fillTable(new Book()); 340 | 341 | } 342 | 343 | /** 344 | * 图书删除事件处理 345 | * @param evt 346 | */ 347 | private void bookDeleteActionPerformed(ActionEvent evt) { 348 | // TODO Auto-generated method stub 349 | // TODO Auto-generated method stub 350 | String id=idTxt.getText(); 351 | if(StringUtil.isEmpty(id)) { 352 | JOptionPane.showMessageDialog(null, "请选择要删除的记录"); 353 | return; 354 | } 355 | int n=JOptionPane.showConfirmDialog(null, "确定要删除该记录吗?"); 356 | if(n==0) { 357 | Connection con=null; 358 | try { 359 | con=dbutil.getCon(); 360 | int deleteNum=bookDao.delete(con, id); 361 | if(deleteNum==1) { 362 | JOptionPane.showMessageDialog(null, "删除成功"); 363 | this.resetValue(); 364 | this.fillTable(new Book()); 365 | }else { 366 | JOptionPane.showMessageDialog(null, "删除失败"); 367 | } 368 | }catch(Exception e) { 369 | e.printStackTrace(); 370 | JOptionPane.showMessageDialog(null, "删除失败"); 371 | }finally { 372 | try { 373 | dbutil.closeCon(con); 374 | } catch (Exception e) { 375 | // TODO Auto-generated catch block 376 | e.printStackTrace(); 377 | } 378 | } 379 | } 380 | } 381 | 382 | /** 383 | * 图书修改事件处理 384 | * @param evt 385 | */ 386 | private void bookUpdateActionPerformed(ActionEvent evt) { 387 | // TODO Auto-generated method stub 388 | String id=this.idTxt.getText(); 389 | if(StringUtil.isEmpty(id)) { 390 | JOptionPane.showMessageDialog(null, "请选择要修改的记录"); 391 | return; 392 | } 393 | String bookName=this.bookNameTxt.getText(); 394 | String author=this.authorTxt.getText(); 395 | String price=this.priceTxt.getText(); 396 | String bookDesc=this.bookDescTxt.getText(); 397 | 398 | if(StringUtil.isEmpty(bookName)) { 399 | JOptionPane.showMessageDialog(null, "图书名称不能为空!"); 400 | return; 401 | } 402 | 403 | if(StringUtil.isEmpty(author)) { 404 | JOptionPane.showMessageDialog(null, "图书作者不能为空!"); 405 | return; 406 | } 407 | 408 | if(StringUtil.isEmpty(price)) { 409 | JOptionPane.showMessageDialog(null, "图书价格不能为空!"); 410 | return; 411 | } 412 | 413 | String sex=""; 414 | if(maleJrb.isSelected()) { 415 | sex="男"; 416 | }else if(femaleJrb.isSelected()){ 417 | sex="女"; 418 | } 419 | 420 | BookType bookType=(BookType) bookTypeJcb.getSelectedItem();//图书类别 421 | int bookTypeId=bookType.getId();//插入数据库 422 | 423 | Book book=new Book(Integer.parseInt(id), bookName, author, sex, Float.parseFloat(price), bookTypeId, bookDesc); 424 | 425 | Connection con=null; 426 | try { 427 | con=dbutil.getCon(); 428 | int addNum=bookDao.update(con, book); 429 | if(addNum==1) { 430 | JOptionPane.showMessageDialog(null, "图书修改成功!"); 431 | resetValue(); 432 | this.fillTable(new Book()); 433 | }else { 434 | JOptionPane.showMessageDialog(null, "图书修改失败!"); 435 | } 436 | }catch(Exception e) { 437 | e.printStackTrace(); 438 | JOptionPane.showMessageDialog(null, "图书修改失败!"); 439 | }finally { 440 | try { 441 | dbutil.closeCon(con); 442 | } catch (Exception e) { 443 | // TODO Auto-generated catch block 444 | e.printStackTrace(); 445 | } 446 | } 447 | } 448 | 449 | /** 450 | * 重置表单 451 | */ 452 | private void resetValue() { 453 | // TODO Auto-generated method stub 454 | this.idTxt.setText(""); 455 | this.bookNameTxt.setText(""); 456 | this.authorTxt.setText(""); 457 | this.priceTxt.setText(""); 458 | this.maleJrb.setSelected(true); 459 | this.bookDescTxt.setText(""); 460 | if(this.bookTypeJcb.getItemCount()>0) 461 | //图书类别为空 462 | { 463 | this.bookTypeJcb.setSelectedIndex(0);//设置选中 464 | } 465 | } 466 | 467 | 468 | /** 469 | * 表格行点击事件处理 470 | * @param e 471 | */ 472 | private void bookTableMousePressed(MouseEvent emt) { 473 | // TODO Auto-generated method stub 474 | int row=this.bookTable.getSelectedRow(); 475 | this.idTxt.setText((String)bookTable.getValueAt(row, 0)); 476 | this.bookNameTxt.setText((String)bookTable.getValueAt(row, 1)); 477 | this.authorTxt.setText((String)bookTable.getValueAt(row, 2)); 478 | String sex=(String)bookTable.getValueAt(row, 3); 479 | if("男".equals(sex)) { 480 | this.maleJrb.setSelected(true); 481 | }else if("女".equals(sex)) { 482 | this.femaleJrb.setSelected(true); 483 | } 484 | this.priceTxt.setText((Float)bookTable.getValueAt(row, 4)+""); 485 | this.bookDescTxt.setText((String)bookTable.getValueAt(row, 5)); 486 | String bookTypeName=(String)this.bookTable.getValueAt(row, 6); 487 | int n=this.bookTypeJcb.getItemCount(); 488 | for(int i=0;i keys=UIManager.getDefaults().keys(); 63 | while(keys.hasMoreElements()){ 64 | Object key=keys.nextElement(); 65 | Object value=UIManager.get(key); 66 | if(value instanceof javax.swing.plaf.FontUIResource) { 67 | UIManager.put(key,font); 68 | } 69 | } 70 | 71 | setResizable(false); 72 | setTitle("管理员登陆"); 73 | setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 74 | setBounds(100, 100, 660, 422); 75 | contentPane = new JPanel(); 76 | contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); 77 | setContentPane(contentPane); 78 | 79 | JLabel label = new JLabel("图书管理系统"); 80 | label.setFont(new Font("宋体", Font.BOLD, 24)); 81 | label.setIcon(new ImageIcon(LogOnFrm.class.getResource("/images/logo.png"))); 82 | 83 | JLabel lblNewLabel = new JLabel("用户名:"); 84 | lblNewLabel.setIcon(new ImageIcon(LogOnFrm.class.getResource("/images/userName.png"))); 85 | 86 | JLabel lblNewLabel_1 = new JLabel("密 码:"); 87 | lblNewLabel_1.setIcon(new ImageIcon(LogOnFrm.class.getResource("/images/password.png"))); 88 | 89 | userNameTxt = new JTextField(); 90 | userNameTxt.setColumns(10); 91 | 92 | passwordTxt = new JPasswordField(); 93 | 94 | JButton btnNewButton = new JButton("登录"); 95 | btnNewButton.setIcon(new ImageIcon(LogOnFrm.class.getResource("/images/login.png"))); 96 | btnNewButton.addActionListener(new ActionListener() { 97 | public void actionPerformed(ActionEvent e) { 98 | loginActionPerformed(e); 99 | } 100 | }); 101 | 102 | JButton btnNewButton_1 = new JButton("重置"); 103 | btnNewButton_1.addActionListener(new ActionListener() { 104 | public void actionPerformed(ActionEvent e) { 105 | resetValueActionPerformed(e); 106 | } 107 | }); 108 | btnNewButton_1.setIcon(new ImageIcon(LogOnFrm.class.getResource("/images/reset.png"))); 109 | GroupLayout gl_contentPane = new GroupLayout(contentPane); 110 | gl_contentPane.setHorizontalGroup( 111 | gl_contentPane.createParallelGroup(Alignment.LEADING) 112 | .addGroup(gl_contentPane.createSequentialGroup() 113 | .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING) 114 | .addGroup(gl_contentPane.createSequentialGroup() 115 | .addGap(172) 116 | .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING) 117 | .addComponent(btnNewButton) 118 | .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING, false) 119 | .addComponent(lblNewLabel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 120 | .addComponent(lblNewLabel_1, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) 121 | .addPreferredGap(ComponentPlacement.UNRELATED) 122 | .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING) 123 | .addComponent(passwordTxt) 124 | .addGroup(gl_contentPane.createSequentialGroup() 125 | .addGap(39) 126 | .addComponent(btnNewButton_1)) 127 | .addComponent(userNameTxt, GroupLayout.DEFAULT_SIZE, 145, Short.MAX_VALUE))) 128 | .addGroup(gl_contentPane.createSequentialGroup() 129 | .addGap(207) 130 | .addComponent(label))) 131 | .addContainerGap(216, GroupLayout.PREFERRED_SIZE)) 132 | ); 133 | gl_contentPane.setVerticalGroup( 134 | gl_contentPane.createParallelGroup(Alignment.LEADING) 135 | .addGroup(gl_contentPane.createSequentialGroup() 136 | .addGap(40) 137 | .addComponent(label) 138 | .addGap(35) 139 | .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE) 140 | .addComponent(lblNewLabel, GroupLayout.PREFERRED_SIZE, 36, GroupLayout.PREFERRED_SIZE) 141 | .addComponent(userNameTxt, GroupLayout.PREFERRED_SIZE, 30, GroupLayout.PREFERRED_SIZE)) 142 | .addGap(30) 143 | .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE) 144 | .addComponent(lblNewLabel_1) 145 | .addComponent(passwordTxt, GroupLayout.PREFERRED_SIZE, 32, GroupLayout.PREFERRED_SIZE)) 146 | .addGap(65) 147 | .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE) 148 | .addComponent(btnNewButton) 149 | .addComponent(btnNewButton_1)) 150 | .addContainerGap(78, Short.MAX_VALUE)) 151 | ); 152 | contentPane.setLayout(gl_contentPane); 153 | 154 | //窗口居中 155 | this.setLocationRelativeTo(null); 156 | } 157 | 158 | /** 159 | * 登录事件处理 160 | * @param e 161 | */ 162 | private void loginActionPerformed(ActionEvent evt) { 163 | // TODO Auto-generated method stub 164 | String userName=this.userNameTxt.getText(); 165 | String password=new String(this.passwordTxt.getPassword());//返回是个×??? 166 | if(StringUtil.isEmpty(userName)) { 167 | JOptionPane.showMessageDialog(null,"用户名不能为空!"); 168 | return; 169 | } 170 | if(StringUtil.isEmpty(password)) { 171 | JOptionPane.showMessageDialog(null,"密码不能为空!"); 172 | return; 173 | } 174 | 175 | User user=new User(userName,password); 176 | Connection con=null; 177 | try { 178 | con=dbUtil.getCon(); 179 | User currentUser=userdao.login(con,user); 180 | if(currentUser!=null){ 181 | dispose();//销毁当前窗口 182 | new MianFrm().setVisible(true); 183 | }else { 184 | JOptionPane.showMessageDialog(null,"用户名或密码错误!"); 185 | } 186 | } catch (Exception e) { 187 | e.printStackTrace(); 188 | }finally { 189 | try{ 190 | dbUtil.closeCon(con);} 191 | catch(Exception e) { 192 | e.printStackTrace(); 193 | } 194 | } 195 | } 196 | 197 | /** 198 | * 重置事件处理 199 | * @param e 200 | */ 201 | private void resetValueActionPerformed(ActionEvent e) { 202 | // TODO Auto-generated method stub 203 | this.userNameTxt.setText(""); 204 | this.passwordTxt.setText(""); 205 | } 206 | } 207 | -------------------------------------------------------------------------------- /src/com/ccx/view/MianFrm.java: -------------------------------------------------------------------------------- 1 | package com.ccx.view; 2 | 3 | import java.awt.BorderLayout; 4 | import java.awt.EventQueue; 5 | 6 | import javax.swing.JFrame; 7 | import javax.swing.JPanel; 8 | import javax.swing.border.EmptyBorder; 9 | import javax.swing.JMenuBar; 10 | import javax.swing.JMenu; 11 | import javax.swing.JMenuItem; 12 | import javax.swing.JOptionPane; 13 | import javax.swing.ImageIcon; 14 | import javax.swing.GroupLayout; 15 | import javax.swing.GroupLayout.Alignment; 16 | import javax.swing.JDesktopPane; 17 | import java.awt.Color; 18 | import java.awt.event.ActionListener; 19 | import java.awt.event.ActionEvent; 20 | 21 | public class MianFrm extends JFrame { 22 | 23 | private JPanel contentPane; 24 | private JDesktopPane table_1=null; 25 | 26 | /** 27 | * Launch the application. 28 | */ 29 | public static void main(String[] args) { 30 | EventQueue.invokeLater(new Runnable() { 31 | public void run() { 32 | try { 33 | MianFrm frame = new MianFrm(); 34 | frame.setVisible(true); 35 | } catch (Exception e) { 36 | e.printStackTrace(); 37 | } 38 | } 39 | }); 40 | } 41 | 42 | /** 43 | * Create the frame. 44 | */ 45 | public MianFrm() { 46 | setTitle("图书管理系统主界面"); 47 | setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 48 | setBounds(100, 100, 640, 437); 49 | 50 | JMenuBar menuBar = new JMenuBar(); 51 | setJMenuBar(menuBar); 52 | 53 | JMenu menu = new JMenu("基本数据维护"); 54 | menu.setIcon(new ImageIcon(MianFrm.class.getResource("/images/base.png"))); 55 | menuBar.add(menu); 56 | 57 | JMenu menu_2 = new JMenu("图书类别管理"); 58 | menu_2.setIcon(new ImageIcon(MianFrm.class.getResource("/images/bookTypeManager.png"))); 59 | menu.add(menu_2); 60 | 61 | JMenuItem menuItem = new JMenuItem("图书类别添加"); 62 | menuItem.addActionListener(new ActionListener() { 63 | public void actionPerformed(ActionEvent e) { 64 | BookTypeAddInterFrm bookTypeAddInterFrm=new BookTypeAddInterFrm(); 65 | bookTypeAddInterFrm.setVisible(true); 66 | table_1.add(bookTypeAddInterFrm); 67 | } 68 | }); 69 | menuItem.setIcon(new ImageIcon(MianFrm.class.getResource("/images/add.png"))); 70 | menu_2.add(menuItem); 71 | 72 | JMenuItem menuItem_1 = new JMenuItem("图书类别维护"); 73 | menuItem_1.addActionListener(new ActionListener() { 74 | public void actionPerformed(ActionEvent arg0) { 75 | BookTypeManagerInterFrm bookTypeManagerInterFrm=new BookTypeManagerInterFrm(); 76 | bookTypeManagerInterFrm.setVisible(true); 77 | table_1.add(bookTypeManagerInterFrm); 78 | } 79 | }); 80 | menuItem_1.setIcon(new ImageIcon(MianFrm.class.getResource("/images/edit.png"))); 81 | menu_2.add(menuItem_1); 82 | 83 | JMenu menu_3 = new JMenu("图书管理"); 84 | menu_3.setIcon(new ImageIcon(MianFrm.class.getResource("/images/bookManager.png"))); 85 | menu.add(menu_3); 86 | 87 | JMenuItem menuItem_2 = new JMenuItem("图书添加"); 88 | menuItem_2.addActionListener(new ActionListener() { 89 | public void actionPerformed(ActionEvent e) { 90 | BookAddInterFrm bookAddInterFrm=new BookAddInterFrm(); 91 | bookAddInterFrm.setVisible(true); 92 | table_1.add(bookAddInterFrm); 93 | } 94 | }); 95 | menuItem_2.setIcon(new ImageIcon(MianFrm.class.getResource("/images/add.png"))); 96 | menu_3.add(menuItem_2); 97 | 98 | JMenuItem menuItem_3 = new JMenuItem("图书维护"); 99 | menuItem_3.addActionListener(new ActionListener() { 100 | public void actionPerformed(ActionEvent e) { 101 | BookManagerInterFrm bookManagerInterFrm=new BookManagerInterFrm(); 102 | bookManagerInterFrm.setVisible(true); 103 | table_1.add(bookManagerInterFrm); 104 | } 105 | }); 106 | menuItem_3.setIcon(new ImageIcon(MianFrm.class.getResource("/images/edit.png"))); 107 | menu_3.add(menuItem_3); 108 | 109 | JMenuItem menuItem_4 = new JMenuItem("安全退出"); 110 | menuItem_4.addActionListener(new ActionListener() { 111 | @SuppressWarnings("unused") 112 | public void actionPerformed(ActionEvent e) { 113 | int result=JOptionPane.showConfirmDialog(null, "是否退出系统"); 114 | //System.out.println(result); 115 | if(result==0) { 116 | dispose(); 117 | } 118 | } 119 | }); 120 | menuItem_4.setIcon(new ImageIcon(MianFrm.class.getResource("/images/exit.png"))); 121 | menu.add(menuItem_4); 122 | 123 | JMenu menu_1 = new JMenu("关于我们"); 124 | menu_1.setIcon(new ImageIcon(MianFrm.class.getResource("/images/about.png"))); 125 | menuBar.add(menu_1); 126 | 127 | JMenuItem mntmccx = new JMenuItem("关于ccx"); 128 | mntmccx.addActionListener(new ActionListener() { 129 | public void actionPerformed(ActionEvent arg0) { 130 | Java javainter=new Java(); 131 | javainter.setVisible(true); 132 | table_1.add(javainter); 133 | } 134 | }); 135 | mntmccx.setIcon(new ImageIcon(MianFrm.class.getResource("/images/about.png"))); 136 | menu_1.add(mntmccx); 137 | contentPane = new JPanel(); 138 | contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); 139 | setContentPane(contentPane); 140 | contentPane.setLayout(new BorderLayout(0, 0)); 141 | 142 | table_1 = new JDesktopPane(); 143 | table_1.setBackground(Color.WHITE); 144 | contentPane.add(table_1, BorderLayout.CENTER); 145 | 146 | //设置JFrame最大化 147 | this.setExtendedState(JFrame.MAXIMIZED_BOTH); 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /src/images/about.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/src/images/about.png -------------------------------------------------------------------------------- /src/images/add.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/src/images/add.png -------------------------------------------------------------------------------- /src/images/base.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/src/images/base.png -------------------------------------------------------------------------------- /src/images/bookManager.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/src/images/bookManager.png -------------------------------------------------------------------------------- /src/images/bookTypeManager.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/src/images/bookTypeManager.png -------------------------------------------------------------------------------- /src/images/ccx.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/src/images/ccx.png -------------------------------------------------------------------------------- /src/images/delete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/src/images/delete.png -------------------------------------------------------------------------------- /src/images/edit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/src/images/edit.png -------------------------------------------------------------------------------- /src/images/exit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/src/images/exit.png -------------------------------------------------------------------------------- /src/images/login.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/src/images/login.png -------------------------------------------------------------------------------- /src/images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/src/images/logo.png -------------------------------------------------------------------------------- /src/images/me.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/src/images/me.png -------------------------------------------------------------------------------- /src/images/modify.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/src/images/modify.png -------------------------------------------------------------------------------- /src/images/password.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/src/images/password.png -------------------------------------------------------------------------------- /src/images/reset.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/src/images/reset.png -------------------------------------------------------------------------------- /src/images/search.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/src/images/search.png -------------------------------------------------------------------------------- /src/images/userName.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/src/images/userName.png -------------------------------------------------------------------------------- /项目截图/Mysql8数据库三张表.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/项目截图/Mysql8数据库三张表.PNG -------------------------------------------------------------------------------- /项目截图/t_booktype表设计.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/项目截图/t_booktype表设计.PNG -------------------------------------------------------------------------------- /项目截图/t_book表设计.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/项目截图/t_book表设计.PNG -------------------------------------------------------------------------------- /项目截图/t_user表设计.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/项目截图/t_user表设计.PNG -------------------------------------------------------------------------------- /项目截图/主界面1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/项目截图/主界面1.png -------------------------------------------------------------------------------- /项目截图/主界面2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/项目截图/主界面2.png -------------------------------------------------------------------------------- /项目截图/图书添加.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/项目截图/图书添加.PNG -------------------------------------------------------------------------------- /项目截图/图书类别添加.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/项目截图/图书类别添加.PNG -------------------------------------------------------------------------------- /项目截图/图书类别管理.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/项目截图/图书类别管理.PNG -------------------------------------------------------------------------------- /项目截图/图书维护.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/项目截图/图书维护.PNG -------------------------------------------------------------------------------- /项目截图/管理员登陆.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ccxcui/BookManager/ebd91d9eb0bfdb9aca8102e5a84cef485cd3b82b/项目截图/管理员登陆.PNG --------------------------------------------------------------------------------