本專案為Java swing專案,在作業環境中基本使用不到,但是很多學校把這個當做編程入門的專案來做,故分享出本專案供初學者參考,
CSDN贊助下載:https://download.csdn.net/download/weixin_44893902/20367467
白嫖:加QQ68872185
一、效果演示:
主要功能:
①基本資料維護:
圖書類別管理 >> 圖書類別添加、圖書類別維護
圖書管理 >> 圖書添加、圖書維護
②關于我們

1、登錄界面

2、主界面:

3、圖書類別維護

4、圖書類別添加

5、圖書維護

6、圖書添加

7、關于我們

可全部縮小到左下角

二、核心代碼:
1、Util包 【存放資料庫連接工具】
① DBTool(資料庫連接工具類)
package cn.ac.azure.util;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;
/**
* 資料庫連接工具類
* @author 明金同學
*
*/
public class DBTool {
private static String driver; //資料庫驅動
private static String url; //資料庫連接地址
private static String user; //資料庫連接用戶
private static String password; //資料庫連接密碼
static{
//新建一個properties,用于讀取db.properties組態檔
Properties p=new Properties();
//新建一個字串,保存組態檔的路徑
String path="cn//ac//azure//util//db.properties";
try {
//呼叫Properties.load通過類加載獲得組態檔的輸入流
p.load(DBTool.class.getClassLoader().getResourceAsStream(path));
//讀取組態檔中的配置引數
driver=p.getProperty("driver"); //獲取驅動
url=p.getProperty("url"); //獲取資料庫連接地址
user=p.getProperty("user"); //獲取資料庫用戶
password=p.getProperty("password"); //獲取資料庫密碼
try {
//加載資料庫驅動類到程式中
Class.forName(driver);
} catch (ClassNotFoundException e) {
e.printStackTrace();
throw new RuntimeException("加載驅動失敗",e);
}
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("找不到組態檔",e);
}
}
/**
* 獲取資料庫連接
* @return 資料庫連接物件
* @throws SQLException 提醒呼叫者捕獲例外,并在finally中關閉關閉例外
*/
public static Connection getConnetion() throws SQLException{
//通過DriverManager獲得資料庫連接
return DriverManager.getConnection(url, user, password);
}
/**
* 關閉資料庫連接
* @param con
*/
public static void close(Connection con){
if(con!=null){ //如果資料連接不為空
try {
//關閉資料庫連接
con.close();
} catch (SQLException e) {
e.printStackTrace();
throw new RuntimeException("資料庫關閉失敗",e);
}
}
}
// /**
// * 測驗資料庫連接工具是否可用
// * @param args
// */
// public static void main(String[] args) {
// Connection con=null;
// try {
// con=DBTool.getConnetion();
// System.out.println("資料庫連接成功!");
// } catch (SQLException e) {
// System.out.println("資料庫連接失敗!");
// e.printStackTrace();
// }finally{
// DBTool.close(con);
// }
// }
}
② db.properties(組態檔)
2、model包 【存放物體類】
① Book(圖書物體類)
package cn.ac.azure.model;
/**
* 圖書物體
* @author 明金同學
*
*/
public class Book {
private Integer id; //圖書id
private String bookName; //圖書名稱
private String author; //圖書作者
private String sex; //作者性別
private Float price; //圖書價格
private Integer bookTypeId; //圖書類別ID
private String bookTypeName; //圖書類別名稱
private String bookDesc; //圖書描述
public Book() {
super();
}
public Book(Integer id, String bookName, String author, String sex, Float price, Integer bookTypeId,
String bookTypeName, String bookDesc) {
super();
this.id = id;
this.bookName = bookName;
this.author = author;
this.sex = sex;
this.price = price;
this.bookTypeId = bookTypeId;
this.bookTypeName = bookTypeName;
this.bookDesc = bookDesc;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getBookName() {
return bookName;
}
public void setBookName(String bookName) {
this.bookName = bookName;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public Float getPrice() {
return price;
}
public void setPrice(Float price) {
this.price = price;
}
public Integer getBookTypeId() {
return bookTypeId;
}
public void setBookTypeId(Integer bookTypeId) {
this.bookTypeId = bookTypeId;
}
public String getBookTypeName() {
return bookTypeName;
}
public void setBookTypeName(String bookTypeName) {
this.bookTypeName = bookTypeName;
}
public String getBookDesc() {
return bookDesc;
}
public void setBookDesc(String bookDesc) {
this.bookDesc = bookDesc;
}
@Override
public String toString() {
return "Book [測驗=" + id + ", bookName=" + bookName + ", author=" + author + ", sex=" + sex + ", price=" + price
+ ", bookTypeId=" + bookTypeId + ", bookTypeName=" + bookTypeName + ", bookDesc=" + bookDesc + "]";
}
}
② BookType(圖書類別物體類)
package cn.ac.azure.model;
/**
* 圖書類別物體
* @author 明金同學
*
*/
public class BookType {
private int id; //定義ID
private String bookTypeName; //定義圖書類別名稱
private String bookTypeDesc; //定義圖書類別描述
//無參構造器
public BookType() {
}
//有參建構式
public BookType(String bookTypeName, String bookTypeDesc) {
super();
this.bookTypeName = bookTypeName;
this.bookTypeDesc = bookTypeDesc;
}
public BookType(int id, String bookTypeName, String bookTypeDesc) {
super();
this.id = id;
this.bookTypeName = bookTypeName;
this.bookTypeDesc = bookTypeDesc;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getBookTypeName() {
return bookTypeName;
}
public void setBookTypeName(String bookTypeName) {
this.bookTypeName = bookTypeName;
}
public String getBookTypeDesc() {
return bookTypeDesc;
}
public void setBookTypeDesc(String bookTypeDesc) {
this.bookTypeDesc = bookTypeDesc;
}
@Override
public String toString() {
return "BookType [id=" + id + ", bookTypeName=" + bookTypeName + ", bookTypeDesc=" + bookTypeDesc + "]";
}
}
③ User(用戶物體類)
package cn.ac.azure.model;
/**
* 用戶物體
* @author 明金同學
*
*/
public class User {
private int id; //用戶id
private String username; //用戶名稱
private String password; //用戶密碼
public User() {
}
@Override
public String toString() {
return "User [id=" + id + ", username=" + username + ", password=" + password + "]";
}
public User(String username, String password) {
super();
this.username = username;
this.password = password;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
3、Dao包 【資料庫訪問層】
① BookDao(圖書dao類)
package cn.ac.azure.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import cn.ac.azure.model.Book;
/**
* 圖書dao類
* @author 明金同學
*
*/
public class BookDao {
/**
* 圖書添加
* @param con 資料庫庫連接物件
* @param book 添加的圖書物件
* @return 回傳添加操作的資料庫記錄數
* @throws SQLException 拋出資料庫例外
*/
public int add(Connection con,Book book) throws SQLException{
//拼寫sql插入陳述句
String sql="insert into t_book values(null,'"+book.getBookName()+"','"+book.getAuthor()+"','"+book.getSex()+"','"+book.getPrice()+"','"+book.getBookTypeId()+"','"+book.getBookTypeName()+"','"+book.getBookDesc()+"')";
System.out.println(sql);
//獲得預編譯物件ps
PreparedStatement ps=con.prepareStatement(sql);
//設定ps引數
/*ps.setString(1,book.getBookName()); //設定圖書名稱
ps.setString(2,book.getAuthor()); //設定圖書作者
ps.setString(3, book.getSex()); //設定作者性別
ps.setFloat(4, book.getPrice()); //設定圖書價格
ps.setInt(5, book.getBookTypeId()); //設定圖書類別ID
ps.setString(6, book.getBookDesc()); //設定圖書描述
*/ //執行sql陳述句,并回傳插入的記錄數
return ps.executeUpdate();
}
/**
* 圖書查詢
* @param con 資料庫連接物件
* @param book 圖書物件
* @return 查詢的結果集
* @throws SQLException 拋出資料庫例外
*/
public ResultSet search(Connection con,Book book) throws SQLException{
//定義圖書名稱
String bookName=null;
//定義圖書作者
String author=null;
//定義圖書類別名稱
String bookTypeName=null;
//如果圖書不為空的話,就為前三個欄位賦值,按照條件查詢
if(book!=null){
bookName=book.getBookName();
author=book.getAuthor();
bookTypeName=book.getBookTypeName();
}
//定義一個字串緩沖物件類存盤查詢添加
StringBuilder sb=new StringBuilder("select * from t_book b , t_bookType bt where b.bookTypeId=bt.id ");
//查詢條件有圖書名稱
if(!(bookName==null || "".equals(bookName.trim()))){
sb.append("and b.bookName like '%"+bookName+"%' ");
}
//查詢條件有圖書作者
if(!(author==null || "".equals(author.trim()))){
sb.append("and b.author like '%"+author+"%' ");
}
//查詢條件有圖書類別名稱
if(!(bookTypeName==null || "".equals(bookTypeName.trim()))){
sb.append("and bt.bookTypeName like '%"+bookTypeName+"%' ");
}
//從sb生成sql陳述句
String sql=sb.toString();
//獲取預處理物件
PreparedStatement ps=con.prepareStatement(sql);
//執行查詢,并回傳結果集
return ps.executeQuery();
}
/**
* 圖書修改
* @param con 資料庫連接物件
* @param book 修改的圖書物件
* @return 回傳修改改變的記錄數
* @throws SQLException 拋出資料庫例外,同時提醒呼叫者關閉資料庫
*/
public int update(Connection con,Book book) throws SQLException{
//撰寫sql陳述句
String sql="update t_book set bookName=?,author=?,sex=?,"
+ "price=?,bookTypeId=?,bookDesc=? where id=?";
//獲取預編譯物件ps
PreparedStatement ps=con.prepareStatement(sql);
//設定ps物件
ps.setString(1, book.getBookName()); //圖書名稱
ps.setString(2, book.getAuthor()); //圖書作者
ps.setString(3,book.getSex()); //作者性別
ps.setFloat(4, book.getPrice()); //圖書價格
ps.setInt(5, book.getBookTypeId()); //圖書型別Id
ps.setString(6, book.getBookDesc()); //圖書描述
ps.setInt(7, book.getId());
//執行修改并回傳改變的記錄數
return ps.executeUpdate();
}
/**
* 圖書洗掉
* @param con 資料庫連接物件
* @param id 洗掉圖書的id
* @return 回傳洗掉的記錄數
* @throws SQLException 拋出資料庫例外,同時提醒呼叫者關閉資料庫
*/
public int delete(Connection con,int id) throws SQLException{
//撰寫sql陳述句
String sql="delete from t_book where id=?";
//獲取預編譯物件ps
PreparedStatement ps=con.prepareStatement(sql);
//設定ps引數
ps.setInt(1, id);
//執行DML洗掉陳述句并回傳洗掉的記錄數
return ps.executeUpdate();
}
}
② BookTypeDao(圖書類別dao類)
package cn.ac.azure.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import cn.ac.azure.model.BookType;
/**
* 圖書類別dao類
* @author 明金同學
*
*/
public class BookTypeDao {
/**
* 圖書類別添加
* @param con 資料庫連接物件
* @param bookType 要添加的圖書類別
* @return 回傳資料庫操作的記錄數
* @throws SQLException
*/
public int add(Connection con,BookType bookType) throws SQLException{
//拼寫sql插入陳述句
String sql="insert into t_bookType values(null,?,?)";
//創建預編譯物件ps
PreparedStatement ps=con.prepareStatement(sql);
//設定ps引數
ps.setString(1, bookType.getBookTypeName()); //設定bookTypeName
ps.setString(2, bookType.getBookTypeDesc()); //設定bookTypeDesc
//回傳資料庫操作的記錄數
return ps.executeUpdate();
}
/**
* 圖書類別查詢
* @param con 資料庫連接物件
* @param bookType 查詢的圖書類別
* @return 回傳查詢的結果集
* @throws SQLException 拋出資料庫例外
*/
public ResultSet search(Connection con,BookType bookType) throws SQLException{
/*
* 思路:當jdbc查詢資料庫有多個條件從外部輸入時,這是最好創建一個字串緩沖類來添加條件到sql陳述句中,
* 同時,不知道有哪些條件是第一條件,無法確定where關鍵字的所在,于是添加條件都用(and 條件)
* 最后字串轉換成字串時在將第一個and替換成where
*/
//定義一個圖書類別名稱
String bookTypeName=null;
if(bookType!=null){ //如果類別物件不為空的話,就獲取它的類別名稱
bookTypeName=bookType.getBookTypeName();
}
//創建一個字串緩沖類
StringBuilder sb=new StringBuilder("select * from t_bookType");
//添加查詢陳述句的條件(and + 條件)
if(!(bookTypeName==null || "".equals(bookTypeName.trim()))){
//jdbc中,資料庫字串要用單引號括起來
sb.append(" and bookTypeName like '%"+bookType.getBookTypeName()+"%'");
}
//將字串緩沖物件轉換成字串,同時把第一個and替換成where
String sql=sb.toString().replaceFirst("and", "where");
//獲取預編譯物件
PreparedStatement ps=con.prepareStatement(sql);
//回傳ps執行查詢之后的結果集
return ps.executeQuery();
}
/**
* 圖書類別修改
* @param con 資料路連接物件
* @param bookType 要修改的圖書類別
* @return 回傳資料庫更新的記錄數
* @throws SQLException 拋出資料庫例外
*/
public int update(Connection con,BookType bookType) throws SQLException{
//拼寫sql更新陳述句
String sql="update t_bookType set bookTypeName=? , bookTypeDesc=? where id=?";
//獲取預編譯物件ps
PreparedStatement ps=con.prepareStatement(sql);
//設定ps引數
ps.setString(1,bookType.getBookTypeName());
ps.setString(2,bookType.getBookTypeDesc());
ps.setInt(3, bookType.getId());
//趕回ps更新資料庫的記錄數
return ps.executeUpdate();
}
/**
* 洗掉資料庫記錄
* @param con 資料庫連接物件
* @param id 傳入洗掉記錄的id
* @return 回傳洗掉的記錄數
* @throws SQLException 拋出資料庫例外
*/
public int delete(Connection con,String id) throws SQLException{
//拼寫sql洗掉陳述句
String sql="delete from t_bookType where id=?";
//獲取預編譯物件ps
PreparedStatement ps=con.prepareStatement(sql);
//設定ps引數
ps.setString(1, id);
//執行ps更行操作,并回傳改變的資料記錄條數
return ps.executeUpdate();
}
}
③ UserDao(用戶資料訪問物件)
package cn.ac.azure.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import cn.ac.azure.model.User;
/**
* 用戶資料訪問物件
* @author 明金同學
*
*/
public class UserDao {
/**
* 登錄驗證
* @param con 資料庫連接物件
* @param user 登錄的賬戶
* @return 回傳一個用戶物件,為null,則登錄失敗;反之,則登錄成功
* @throws Exception 讓呼叫者處理例外
*/
public User login(Connection con,User user) throws SQLException{
//定義一個回傳用戶物件
User resultUser=null;
//拼寫sql查詢陳述句
String sql="select * from t_user where username=? and password=?";
//獲取sql陳述句預編譯物件
PreparedStatement ps=con.prepareStatement(sql);
//設定ps引數
ps.setString(1, user.getUsername());
ps.setString(2, user.getPassword());
//ps執行sql查詢陳述句回傳結果集
ResultSet rs=ps.executeQuery();
//遍歷結果集
while(rs.next()){
//初始化回傳用戶物件
resultUser=new User();
resultUser.setId(rs.getInt("id")); //設定用戶id
resultUser.setUsername(rs.getString("username")); //設定用戶名稱
resultUser.setPassword(rs.getString("password")); //設定用戶密碼
}
//回傳用戶物件
return resultUser;
}
}
4、View包 【視圖層】
① LoginFrame(登錄界面)
package cn.ac.azure.view;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.SQLException;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.border.EmptyBorder;
import cn.ac.azure.dao.UserDao;
import cn.ac.azure.model.User;
import cn.ac.azure.util.DBTool;
public class LoginFrame extends JFrame {
static {
try {
// 這里是皮膚包可以隨意切換
// javax.swing.UIManager.setLookAndFeel("com.jtattoo.plaf.mcwin.McWinLookAndFeel");
javax.swing.UIManager.setLookAndFeel("com.jtattoo.plaf.smart.SmartLookAndFeel");
// javax.swing.UIManager.setLookAndFeel("com.jtattoo.plaf.luna.LunaLookAndFeel");
// javax.swing.UIManager.setLookAndFeel("com.jtattoo.plaf.aluminium.AluminiumLookAndFeel");
// javax.swing.UIManager.setLookAndFeel("com.jtattoo.plaf.bernstein.BernsteinLookAndFeel");
// javax.swing.UIManager.setLookAndFeel("com.jtattoo.plaf.hifi.HiFiLookAndFeel");
// javax.swing.UIManager.setLookAndFeel("com.jtattoo.plaf.aero.AeroLookAndFeel");
// javax.swing.UIManager.setLookAndFeel("com.jtattoo.plaf.mint.MintLookAndFeel");
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException
| UnsupportedLookAndFeelException e) {
e.printStackTrace();
}
}
private JPanel contentPane;
private JTextField usernameText;
private JPasswordField passwordText;
private JButton loginBtn;
private JButton resetBtn;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
LoginFrame frame = new LoginFrame();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public LoginFrame() {
//改變系統默認字體
Font font = new Font("Dialog", Font.PLAIN, 12);
java.util.Enumeration<Object> keys = UIManager.getDefaults().keys();
while (keys.hasMoreElements()) {
Object key = keys.nextElement();
Object value = UIManager.get(key);
if (value instanceof javax.swing.plaf.FontUIResource) {
UIManager.put(key, font);
}
}
setIconImage(Toolkit.getDefaultToolkit().getImage(LoginFrame.class.getResource("/images/logo.png")));
setResizable(false);
setTitle("管理員登錄");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
JLabel lblNewLabel = new JLabel("\u56FE\u4E66\u7BA1\u7406\u7CFB\u7EDF");
lblNewLabel.setFont(new Font("宋體", Font.BOLD, 22));
lblNewLabel.setIcon(new ImageIcon(LoginFrame.class.getResource("/images/logo.png")));
JLabel lblNewLabel_1 = new JLabel("用戶名 :");
lblNewLabel_1.setIcon(new ImageIcon(LoginFrame.class.getResource("/images/userName.png")));
usernameText = new JTextField();
usernameText.setColumns(10);
JLabel lblNewLabel_2 = new JLabel("密 碼 :");
lblNewLabel_2.setIcon(new ImageIcon(LoginFrame.class.getResource("/images/password.png")));
passwordText = new JPasswordField();
//添加登陸按鈕
loginBtn = new JButton("登錄");
loginBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
loginActionPerformed(e);
}
});
loginBtn.setIcon(new ImageIcon(LoginFrame.class.getResource("/images/login.png")));
//添加重置按鈕
resetBtn = new JButton("重置");
resetBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
resetActionPerformed(e);
}
});
resetBtn.setIcon(new ImageIcon(LoginFrame.class.getResource("/images/reset.png")));
GroupLayout gl_contentPane = new GroupLayout(contentPane);
gl_contentPane.setHorizontalGroup(
gl_contentPane.createParallelGroup(Alignment.LEADING)
.addGroup(gl_contentPane.createSequentialGroup()
.addGap(106)
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
.addComponent(lblNewLabel)
.addGroup(gl_contentPane.createSequentialGroup()
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
.addGroup(gl_contentPane.createSequentialGroup()
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(lblNewLabel_1)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(usernameText, GroupLayout.PREFERRED_SIZE, 142, GroupLayout.PREFERRED_SIZE))
.addGroup(gl_contentPane.createSequentialGroup()
.addComponent(lblNewLabel_2)
.addPreferredGap(ComponentPlacement.UNRELATED)
.addComponent(passwordText, GroupLayout.PREFERRED_SIZE, 144, GroupLayout.PREFERRED_SIZE))
.addGroup(Alignment.TRAILING, gl_contentPane.createSequentialGroup()
.addGap(16)
.addComponent(loginBtn)
.addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(resetBtn)))
.addPreferredGap(ComponentPlacement.RELATED)))
.addContainerGap(105, GroupLayout.PREFERRED_SIZE))
);
gl_contentPane.setVerticalGroup(
gl_contentPane.createParallelGroup(Alignment.LEADING)
.addGroup(gl_contentPane.createSequentialGroup()
.addGap(25)
.addComponent(lblNewLabel)
.addGap(18)
.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
.addComponent(lblNewLabel_1)
.addComponent(usernameText, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGap(18)
.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
.addComponent(lblNewLabel_2)
.addComponent(passwordText, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGap(29)
.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
.addComponent(loginBtn)
.addComponent(resetBtn))
.addContainerGap())
);
contentPane.setLayout(gl_contentPane);
//設定視窗居中
this.setLocationRelativeTo(null);
}
/**
* 登錄事件處理
* @param evt
*/
private void loginActionPerformed(ActionEvent evt) {
//從輸入框獲取用戶名
String username=usernameText.getText().trim();
//從輸入框獲取密碼
String password=passwordText.getText().trim();
//用戶名不能為慷訓空字串,否則結束事件處理
if(username==null || "".equals(username)){
JOptionPane.showMessageDialog(null, "用戶名不能為空");
return;
}
//用戶名不能為慷訓空字串否則結束事件處理
if(password==null || "".equals(password)){
JOptionPane.showMessageDialog(null, "密碼不能為空");
return;
}
//將從輸入框獲得資訊新建一個物件
User user=new User(username, password);
//定義資料庫連接
Connection con=null;
try {
//利用資料庫工具類獲取資料庫連接
con=DBTool.getConnetion();
//新建一個用戶資料訪問物件
UserDao userDao=new UserDao();
//呼叫其登錄驗證方法獲取一個用戶物件
User currUser=userDao.login(con, user);
//判斷回傳的用戶物件
if(currUser!=null){//不為空,表示登錄成功
//進入主界面,并設定可見
new MainFrame().setVisible(true);
//釋放當前視窗資源
dispose();
}else{ //為空,表示登錄不成功
JOptionPane.showMessageDialog(null, "登錄失敗(u_u)");
}
} catch (SQLException e) {
e.printStackTrace();
throw new RuntimeException("登錄失敗",e);
}finally{
//關閉資料庫連接
DBTool.close(con);
}
}
/**
* 重置事件處理
* @param evt
*/
private void resetActionPerformed(ActionEvent evt) {
usernameText.setText("");
passwordText.setText("");
}
}
② MainFrame(主界面)
package cn.ac.azure.view;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Font;
import javax.swing.ImageIcon;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.border.EmptyBorder;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class MainFrame extends JFrame {
static {
try {
// 這里是皮膚包可以隨意切換
// javax.swing.UIManager.setLookAndFeel("com.jtattoo.plaf.mcwin.McWinLookAndFeel");
javax.swing.UIManager.setLookAndFeel("com.jtattoo.plaf.smart.SmartLookAndFeel");
// javax.swing.UIManager.setLookAndFeel("com.jtattoo.plaf.luna.LunaLookAndFeel");
// javax.swing.UIManager.setLookAndFeel("com.jtattoo.plaf.aluminium.AluminiumLookAndFeel");
// javax.swing.UIManager.setLookAndFeel("com.jtattoo.plaf.bernstein.BernsteinLookAndFeel");
// javax.swing.UIManager.setLookAndFeel("com.jtattoo.plaf.hifi.HiFiLookAndFeel");
// javax.swing.UIManager.setLookAndFeel("com.jtattoo.plaf.aero.AeroLookAndFeel");
// javax.swing.UIManager.setLookAndFeel("com.jtattoo.plaf.mint.MintLookAndFeel");
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException
| UnsupportedLookAndFeelException e) {
e.printStackTrace();
}
}
private static final long serialVersionUID = 1L;
//定義內容窗格
private JPanel contentPane;
//定義桌面窗格
private JDesktopPane table;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
MainFrame frame = new MainFrame();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public MainFrame() {
//改變系統默認字體
Font font = new Font("Dialog", Font.PLAIN, 12);
java.util.Enumeration<Object> keys = UIManager.getDefaults().keys();
while (keys.hasMoreElements()) {
Object key = keys.nextElement();
Object value = UIManager.get(key);
if (value instanceof javax.swing.plaf.FontUIResource) {
UIManager.put(key, font);
}
}
setTitle("\u56FE\u4E66\u7BA1\u7406\u7CFB\u7EDF\u4E3B\u754C\u9762");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
JMenuBar menuBar = new JMenuBar();
menuBar.setToolTipText("");
setJMenuBar(menuBar);
JMenu menu = new JMenu("\u57FA\u672C\u6570\u636E\u7EF4\u62A4 ");
menu.setIcon(new ImageIcon(MainFrame.class.getResource("/images/base.png")));
menuBar.add(menu);
JMenu mnNewMenu = new JMenu("\u56FE\u4E66\u7C7B\u522B\u7BA1\u7406 ");
mnNewMenu.setIcon(new ImageIcon(MainFrame.class.getResource("/images/bookTypeManager.png")));
menu.add(mnNewMenu);
//圖書類別添加
JMenuItem menuItem = new JMenuItem("\u56FE\u4E66\u7C7B\u522B\u6DFB\u52A0");
menuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
BookTypeAddInterFrame bookTypeAddInterFrame=new BookTypeAddInterFrame();
bookTypeAddInterFrame.setVisible(true);
table.add(bookTypeAddInterFrame);
}
});
menuItem.setIcon(new ImageIcon(MainFrame.class.getResource("/images/add.png")));
mnNewMenu.add(menuItem);
//圖書類別維護
JMenuItem menuItem_1 = new JMenuItem("\u56FE\u4E66\u7C7B\u522B\u7EF4\u62A4");
menuItem_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
BookTypeManageInterFrame bookTypeManageInterFrame=new BookTypeManageInterFrame();
bookTypeManageInterFrame.setVisible(true);
table.add(bookTypeManageInterFrame);
}
});
menuItem_1.setIcon(new ImageIcon(MainFrame.class.getResource("/images/edit.png")));
mnNewMenu.add(menuItem_1);
JMenu menu_1 = new JMenu("\u56FE\u4E66\u7BA1\u7406");
menu_1.setIcon(new ImageIcon(MainFrame.class.getResource("/images/bookManager.png")));
menu.add(menu_1);
//圖書添加
JMenuItem menuItem_2 = new JMenuItem("\u56FE\u4E66\u6DFB\u52A0");
menuItem_2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
BookAddInterFrame bookAddInterFrame=new BookAddInterFrame();
bookAddInterFrame.setVisible(true);
table.add(bookAddInterFrame);
}
});
menuItem_2.setIcon(new ImageIcon(MainFrame.class.getResource("/images/add.png")));
menu_1.add(menuItem_2);
//圖書維護
JMenuItem menuItem_3 = new JMenuItem("\u56FE\u4E66\u7EF4\u62A4");
menuItem_3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
BookManageInterFrame bookManageInterFrame=new BookManageInterFrame();
bookManageInterFrame.setVisible(true);
table.add(bookManageInterFrame);
}
});
menuItem_3.setIcon(new ImageIcon(MainFrame.class.getResource("/images/edit.png")));
menu_1.add(menuItem_3);
//安全退出
JMenuItem menuItem_4 = new JMenuItem("\u5B89\u5168\u9000\u51FA");
menuItem_4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//彈出退出確認提示框
int res=JOptionPane.showConfirmDialog(null, "確定要退出嗎?");
//確定退出
if(res==JOptionPane.OK_OPTION){
dispose();
}
//否則繼續留在該界面
}
});
menuItem_4.setIcon(new ImageIcon(MainFrame.class.getResource("/images/exit.png")));
menu.add(menuItem_4);
JMenu menu_2 = new JMenu("\u5173\u4E8E\u6211\u4EEC");
menu_2.setIcon(new ImageIcon(MainFrame.class.getResource("/images/about.png")));
menuBar.add(menu_2);
//關于我們
JMenuItem menuItem_5 = new JMenuItem("\u5173\u4E8E\u6211\u4EEC");
menuItem_5.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//新建一個圖書內部表單
LibraryInterFrame libraryInnerFrame=new LibraryInterFrame();
//顯示圖書內部表單
libraryInnerFrame.setVisible(true);
//將圖書內部表單顯示到主界面桌面窗格中
table.add(libraryInnerFrame);
}
});
menuItem_5.setIcon(new ImageIcon(MainFrame.class.getResource("/images/about.png")));
menu_2.add(menuItem_5);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setLayout(new BorderLayout(0, 0));
setContentPane(contentPane);
//定義主界面桌面窗格界面,用于裝載內部表單
table = new JDesktopPane();
table.setBackground(Color.LIGHT_GRAY);
contentPane.add(table, BorderLayout.CENTER);
//設定視窗最大化
setExtendedState(JFrame.MAXIMIZED_BOTH);
}
}
③ BookTypeManageInterFrame(圖書類別管理界面)
package cn.ac.azure.view;
import java.awt.EventQueue;
import java.awt.Font;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.table.DefaultTableModel;
import cn.ac.azure.dao.BookTypeDao;
import cn.ac.azure.model.BookType;
import cn.ac.azure.util.DBTool;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JPanel;
import javax.swing.border.LineBorder;
import javax.swing.border.TitledBorder;
import javax.swing.JTextArea;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class BookTypeManageInterFrame extends JInternalFrame {
private JTextField s_bookTypeNameText;
private JTable bookTypeTable;
private BookTypeDao bookTypeDao=new BookTypeDao();
private JTextField idText;
private JTextField bookTypeNameText;
private JTextArea bookTypeDescText;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
BookTypeManageInterFrame frame = new BookTypeManageInterFrame();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public BookTypeManageInterFrame() {
//改變系統默認字體
Font font = new Font("Dialog", Font.PLAIN, 12);
java.util.Enumeration keys = UIManager.getDefaults().keys();
while (keys.hasMoreElements()) {
Object key = keys.nextElement();
Object value = UIManager.get(key);
if (value instanceof javax.swing.plaf.FontUIResource) {
UIManager.put(key, font);
}
}
setIconifiable(true);
setClosable(true);
setTitle("圖書類別管理");
setBounds(400, 100, 535, 489);
JScrollPane scrollPane = new JScrollPane();
JLabel label = new JLabel("圖書類別名稱:");
s_bookTypeNameText = new JTextField();
s_bookTypeNameText.setColumns(10);
//查詢按鈕
JButton searchBtn = new JButton("查詢");
searchBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
searchActionPerformed(e);
}
});
searchBtn.setIcon(new ImageIcon(BookTypeManageInterFrame.class.getResource("/images/search.png")));
JPanel panel = new JPanel();
panel.setBorder(new TitledBorder(null, "\u8868\u5355\u64CD\u4F5C", TitledBorder.LEADING, TitledBorder.TOP, null, null));
GroupLayout groupLayout = new GroupLayout(getContentPane());
groupLayout.setHorizontalGroup(
groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addGap(56)
.addComponent(label)
.addPreferredGap(ComponentPlacement.UNRELATED)
.addComponent(s_bookTypeNameText, GroupLayout.PREFERRED_SIZE, 167, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(ComponentPlacement.RELATED, 54, Short.MAX_VALUE)
.addComponent(searchBtn)
.addGap(71))
.addGroup(groupLayout.createSequentialGroup()
.addGap(36)
.addGroup(groupLayout.createParallelGroup(Alignment.TRAILING, false)
.addComponent(panel, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(scrollPane, Alignment.LEADING))
.addContainerGap(31, Short.MAX_VALUE))
);
groupLayout.setVerticalGroup(
groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addGap(27)
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
.addComponent(searchBtn)
.addComponent(label)
.addComponent(s_bookTypeNameText, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGap(18)
.addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, 167, GroupLayout.PREFERRED_SIZE)
.addGap(18)
.addComponent(panel, GroupLayout.DEFAULT_SIZE, 194, Short.MAX_VALUE)
.addContainerGap())
);
JLabel label_1 = new JLabel("編號:");
idText = new JTextField();
idText.setEditable(false);
idText.setColumns(10);
JLabel label_2 = new JLabel("圖書類別名稱:");
bookTypeNameText = new JTextField();
bookTypeNameText.setColumns(10);
JLabel label_3 = new JLabel("描述:");
bookTypeDescText = new JTextArea();
//修改按鈕
JButton modifyBtn = new JButton("修改");
modifyBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
bookTypeUpdateActionPerformed(e);
}
});
modifyBtn.setIcon(new ImageIcon(BookTypeManageInterFrame.class.getResource("/images/modify.png")));
//洗掉按鈕
JButton deleteBtn = new JButton("洗掉");
deleteBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
bookTypeDeleteActionPerformed(e);
}
});
deleteBtn.setIcon(new ImageIcon(BookTypeManageInterFrame.class.getResource("/images/delete.png")));
GroupLayout gl_panel = new GroupLayout(panel);
gl_panel.setHorizontalGroup(
gl_panel.createParallelGroup(Alignment.LEADING)
.addGroup(gl_panel.createSequentialGroup()
.addGap(19)
.addGroup(gl_panel.createParallelGroup(Alignment.TRAILING)
.addGroup(Alignment.LEADING, gl_panel.createSequentialGroup()
.addComponent(label_1)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(idText, GroupLayout.PREFERRED_SIZE, 47, GroupLayout.PREFERRED_SIZE)
.addGap(18)
.addComponent(label_2)
.addPreferredGap(ComponentPlacement.UNRELATED)
.addComponent(bookTypeNameText, GroupLayout.PREFERRED_SIZE, 166, GroupLayout.PREFERRED_SIZE))
.addGroup(Alignment.LEADING, gl_panel.createSequentialGroup()
.addComponent(label_3)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(bookTypeDescText))
.addGroup(gl_panel.createSequentialGroup()
.addComponent(modifyBtn)
.addGap(54)
.addComponent(deleteBtn)
.addGap(64)))
.addContainerGap(56, GroupLayout.PREFERRED_SIZE))
);
gl_panel.setVerticalGroup(
gl_panel.createParallelGroup(Alignment.LEADING)
.addGroup(gl_panel.createSequentialGroup()
.addContainerGap()
.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
.addComponent(label_1)
.addComponent(idText, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(label_2)
.addComponent(bookTypeNameText, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGap(27)
.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
.addComponent(label_3)
.addComponent(bookTypeDescText, GroupLayout.PREFERRED_SIZE, 51, GroupLayout.PREFERRED_SIZE))
.addGap(18)
.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
.addComponent(deleteBtn)
.addComponent(modifyBtn))
.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
panel.setLayout(gl_panel);
//表格
bookTypeTable = new JTable();
//表格滑鼠點擊事件
bookTypeTable.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
bookTypeTableMousePressed(e);
}
});
bookTypeTable.setModel(new DefaultTableModel(
new Object[][] {
},
new String[] {
"編號", "圖書類別名稱", "圖書類別描述"
}
) {
boolean[] columnEditables = new boolean[] {
false, false, false
};
public boolean isCellEditable(int row, int column) {
return columnEditables[column];
}
});
bookTypeTable.getColumnModel().getColumn(1).setPreferredWidth(96);
bookTypeTable.getColumnModel().getColumn(2).setPreferredWidth(185);
scrollPane.setViewportView(bookTypeTable);
getContentPane().setLayout(groupLayout);
//設定文本域邊框
bookTypeDescText.setBorder(new LineBorder(new java.awt.Color(127,157,185), 1, false));
//建構式中呼叫填充表格資料函式,全部圖書類別顯示在表格中
fillTable(new BookType());
}
/**
* 圖書類別洗掉事件處理
* @param evt
*/
private void bookTypeDeleteActionPerformed(ActionEvent evt) {
//獲得表單中編號的值id
String id=idText.getText();
//判斷表單有沒有選中的圖書類別記錄
if(id==null || "".equals(id.trim())){
JOptionPane.showMessageDialog(null, "請選擇要修改的記錄!");
return;
}
//彈出確認框,是否要洗掉圖書類別記錄
int res=JOptionPane.showConfirmDialog(null, "你確定要洗掉該條記錄嗎?");
if(res!=0){ //否
return; //結束該事件處理函式
}
//定義資料庫連接
Connection con=null;
try {
//獲取資料路連接
con=DBTool.getConnetion();
int row=bookTypeDao.delete(con, id);
if(row==1){//洗掉成功,彈出提示框
JOptionPane.showMessageDialog(null, "修改資料成功(n_n)");
//清空表單資料
resetValue();
//重繪表格記錄顯示
fillTable(new BookType());
}else{//洗掉失敗,彈出提示框
JOptionPane.showMessageDialog(null, "修改資料失敗(u_u)");
}
} catch (SQLException e) {
//記錄日志
e.printStackTrace();
throw new RuntimeException("洗掉記錄失敗!",e);
}finally{
//關閉資料庫
DBTool.close(con);
}
}
/**
* 圖書類別修改事件處理
* @param evt
*/
private void bookTypeUpdateActionPerformed(ActionEvent evt) {
//獲取表單操作各個文本框的值
String id=idText.getText();
String bookTypeName=bookTypeNameText.getText();
String bookTypeDesc=bookTypeDescText.getText();
//判斷表單有沒有選中的圖書類別記錄
if(id==null || "".equals(id.trim())){
JOptionPane.showMessageDialog(null, "請選擇要修改的記錄!");
return;
}
//圖書類別名稱不能為空
if(bookTypeName==null || "".equals(bookTypeName.trim())){
JOptionPane.showMessageDialog(null, "圖書類別名稱不能為空!");
return;
}
//利用表單的資料新建一個圖書類別物件
BookType bookType=new BookType(Integer.parseInt(id), bookTypeName, bookTypeDesc);
//定義資料庫連接物件
Connection con=null;
try {
//獲取資料庫連接
con=DBTool.getConnetion();
//執行圖書類別dao類的修改記錄方法
int res=bookTypeDao.update(con, bookType);
if(res==1){//修改成功,彈出提示框
JOptionPane.showMessageDialog(null, "修改資料成功(n_n)");
//清空表單資料
resetValue();
//重繪表格記錄顯示
fillTable(new BookType());
}else{//修改失敗,彈出提示框
JOptionPane.showMessageDialog(null, "修改資料失敗(u_u)");
}
} catch (SQLException e) {
//記錄日志
e.printStackTrace();
throw new RuntimeException("修改圖書類別失敗",e);
}finally{
//關閉資料路連接
DBTool.close(con);
}
}
/**
* 表格滑鼠點擊事件處理
* @param e
*/
private void bookTypeTableMousePressed(MouseEvent e) {
//獲取表格選中的行
int row=bookTypeTable.getSelectedRow();
//獲取表中選中行的第一列的值并顯示在idText框中
idText.setText(String.valueOf(bookTypeTable.getValueAt(row, 0)));
//獲取表中選中行的第二列的值并顯示在bookTypeNameText框中
bookTypeNameText.setText((String)bookTypeTable.getValueAt(row, 1));
//獲取表中選中行的第三列的值并顯示在bookTypeDescText框中
bookTypeDescText.setText((String)bookTypeTable.getValueAt(row, 2));
}
/**
* 圖書類別查詢事件處理
* @param evt
*/
private void searchActionPerformed(ActionEvent evt) {
//獲取圖書類別輸入框里的內容
String s_bookTypeName=s_bookTypeNameText.getText();
//新建一個圖書類別并初始化
BookType bookType=new BookType();
//將輸入框的內容設定成新建圖書類別的圖書類別名稱
bookType.setBookTypeName(s_bookTypeName);
//根據圖書類別查詢圖書類別
fillTable(bookType);
}
/**
* 在表格中填充資料
* @param bookType 傳入bookType物件
*/
private void fillTable(BookType bookType){
//獲取表格的模型
DefaultTableModel dtm=(DefaultTableModel) bookTypeTable.getModel();
//清空表格
dtm.setRowCount(0);
//定義資料庫連接
Connection con=null;
try {
//獲取資料庫連接
con=DBTool.getConnetion();
//呼叫BookTyPeDao的查詢方法,并獲得其查詢的結果集
ResultSet rs=bookTypeDao.search(con, bookType);
//遍歷結果集
while(rs.next()){
//新建一個vector并初始化
Vector v=new Vector();
v.add(rs.getInt("id")); //向vector中添加id
v.add(rs.getString("bookTypeName")); //向vector中添加bookTypeName
v.add(rs.getString("bookTypeDesc")); //向vector中添加bookTypeDesc
//將vector中的資料顯示到表格中
dtm.addRow(v);
}
} catch (SQLException e) {
//記錄日志
e.printStackTrace();
throw new RuntimeException("查詢失敗");
}finally{
//關閉資料庫
DBTool.close(con);
}
}
/**
* 清空表單資料
*/
private void resetValue(){
idText.setText("");
bookTypeNameText.setText("");
bookTypeDescText.setText("");
s_bookTypeNameText.setText("");
}
}
④ BookTypeAddInterFrame(圖書類別添加界面)
package cn.ac.azure.view;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.SQLException;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.border.LineBorder;
import cn.ac.azure.dao.BookTypeDao;
import cn.ac.azure.model.BookType;
import cn.ac.azure.util.DBTool;
/**
* 圖書類別內部添加表單
* @author green
*
*/
public class BookTypeAddInterFrame extends JInternalFrame {
//圖書類別名稱輸入框
private JTextField bookTypeNameText;
//圖書類別描述輸入框
private JTextArea bookTypeDescText;
//重置按鈕
private JButton resetBtn;
//添加按鈕
private JButton addBtn;
//圖書類別資料庫訪問物件
private BookTypeDao bookTypeDao;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
BookTypeAddInterFrame frame = new BookTypeAddInterFrame();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public BookTypeAddInterFrame() {
//改變系統默認字體
Font font = new Font("Dialog", Font.PLAIN, 12);
java.util.Enumeration keys = UIManager.getDefaults().keys();
while (keys.hasMoreElements()) {
Object key = keys.nextElement();
Object value = UIManager.get(key);
if (value instanceof javax.swing.plaf.FontUIResource) {
UIManager.put(key, font);
}
}
setClosable(true);
setIconifiable(true);
setTitle("圖書類別添加");
setBounds(100, 100, 487, 342);
JLabel label = new JLabel("圖書類別名稱:");
bookTypeNameText = new JTextField();
bookTypeNameText.setColumns(10);
JLabel label_1 = new JLabel("圖書類別描述:");
bookTypeDescText = new JTextArea();
//添加按鈕
addBtn = new JButton("添加");
addBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
addActionPerformed(e);
}
});
//重置按鈕
resetBtn = new JButton("重置");
resetBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
resetActionPerformed(e);
}
});
GroupLayout groupLayout = new GroupLayout(getContentPane());
groupLayout.setHorizontalGroup(
groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addGap(128)
.addComponent(addBtn)
.addGap(91)
.addComponent(resetBtn))
.addGroup(groupLayout.createSequentialGroup()
.addGap(89)
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
.addComponent(bookTypeDescText)
.addGroup(groupLayout.createSequentialGroup()
.addComponent(label)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(bookTypeNameText, GroupLayout.PREFERRED_SIZE, 189, GroupLayout.PREFERRED_SIZE))
.addComponent(label_1))))
.addContainerGap(105, Short.MAX_VALUE))
);
groupLayout.setVerticalGroup(
groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addGap(49)
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
.addComponent(label)
.addComponent(bookTypeNameText, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGap(18)
.addComponent(label_1)
.addGap(10)
.addComponent(bookTypeDescText, GroupLayout.PREFERRED_SIZE, 87, GroupLayout.PREFERRED_SIZE)
.addGap(41)
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
.addComponent(resetBtn)
.addComponent(addBtn))
.addContainerGap())
);
getContentPane().setLayout(groupLayout);
//設定文本域邊框
bookTypeDescText.setBorder(new LineBorder(new java.awt.Color(127,157,185), 1, false));
}
/**
* 添加事件處理
* @param evt
*/
private void addActionPerformed(ActionEvent evt) {
//獲取輸入框的值
String bookTypeName=bookTypeNameText.getText();
String bookTypeDesc=bookTypeDescText.getText();
if(bookTypeName==null || "".equals(bookTypeName.trim())){
JOptionPane.showMessageDialog(null,"圖書類別不能為空!");
return;
}
//新建圖書類別物體物件
BookType bookType=new BookType(bookTypeName, bookTypeDesc);
//定義資料庫連接
Connection con=null;
try {
//獲取資料庫連接
con=DBTool.getConnetion();
//初始化圖書類別物件BookTypeDao
bookTypeDao=new BookTypeDao();
//呼叫圖書類別dao物件的添加方法
int res=bookTypeDao.add(con, bookType);
if(res!=0){
//提示添加成功
JOptionPane.showMessageDialog(null, "圖書添加成功(n_n)");
//清空輸入框
bookTypeNameText.setText("");
bookTypeDescText.setText("");
}else{
//提示添加失敗
JOptionPane.showMessageDialog(null,"圖書添加失敗(u_u)");
}
} catch (SQLException e) {
//記錄日志
e.printStackTrace();
throw new RuntimeException("添加圖書失敗",e);
}finally{
//關閉資料庫
DBTool.close(con);
}
}
/**
* 重置事件處理
* @param evt
*/
private void resetActionPerformed(ActionEvent evt) {
//置空圖書類別名稱輸入框
bookTypeNameText.setText("");
//置空圖書類別描述輸入框
bookTypeDescText.setText("");
}
}
⑤ BookManageInterFrame(圖書管理界面)
package cn.ac.azure.view;
import java.awt.EventQueue;
import java.awt.Font;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.UIManager;
import javax.swing.border.TitledBorder;
import javax.swing.table.DefaultTableModel;
import cn.ac.azure.dao.BookDao;
import cn.ac.azure.dao.BookTypeDao;
import cn.ac.azure.model.Book;
import cn.ac.azure.model.BookType;
import cn.ac.azure.util.DBTool;
import javax.swing.JRadioButton;
import javax.swing.ButtonGroup;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class BookManageInterFrame extends JInternalFrame {
private JTextField s_bookNameText;
private JTextField s_authorText;
private JTable bookTable;
private JComboBox s_bookTypecomboBox;
private BookTypeDao bookTypeDao;
private BookDao bookDao;
private JTextField idText;
private JTextField bookNameText;
private JTextField priceText;
private JTextField authorText;
private JTextField bookDescText;
private final ButtonGroup buttonGroup = new ButtonGroup();
private JComboBox bookTypeComboBox;
private JRadioButton maleBtn;
private JRadioButton femaleBtn;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
BookManageInterFrame frame = new BookManageInterFrame();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public BookManageInterFrame() {
//改變系統默認字體
Font font = new Font("Dialog", Font.PLAIN, 12);
java.util.Enumeration keys = UIManager.getDefaults().keys();
while (keys.hasMoreElements()) {
Object key = keys.nextElement();
Object value = UIManager.get(key);
if (value instanceof javax.swing.plaf.FontUIResource) {
UIManager.put(key, font);
}
}
setIconifiable(true);
setClosable(true);
setTitle("圖書管理 ");
setBounds(100, 100, 767, 528);
JPanel panel = new JPanel();
panel.setBorder(new TitledBorder(null, "搜索條件", TitledBorder.LEADING, TitledBorder.TOP, null, null));
JScrollPane scrollPane = new JScrollPane();
JPanel panel_1 = new JPanel();
panel_1.setBorder(new TitledBorder(null, "表單操作", TitledBorder.LEADING, TitledBorder.TOP, null, null));
GroupLayout groupLayout = new GroupLayout(getContentPane());
groupLayout.setHorizontalGroup(
groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(Alignment.TRAILING, groupLayout.createSequentialGroup()
.addGap(29)
.addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
.addComponent(panel_1, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(scrollPane, GroupLayout.DEFAULT_SIZE, 661, Short.MAX_VALUE)
.addComponent(panel, GroupLayout.DEFAULT_SIZE, 661, Short.MAX_VALUE))
.addGap(38))
);
groupLayout.setVerticalGroup(
groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addGap(29)
.addComponent(panel, GroupLayout.PREFERRED_SIZE, 75, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(ComponentPlacement.UNRELATED)
.addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, 137, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(ComponentPlacement.UNRELATED)
.addComponent(panel_1, GroupLayout.PREFERRED_SIZE, 217, GroupLayout.PREFERRED_SIZE)
.addContainerGap(20, Short.MAX_VALUE))
);
JLabel label_2 = new JLabel("編號:");
idText = new JTextField();
idText.setColumns(10);
JLabel label_3 = new JLabel("圖書名稱:");
bookNameText = new JTextField();
bookNameText.setColumns(10);
JLabel label_4 = new JLabel("作者性別:");
maleBtn = new JRadioButton("男");
buttonGroup.add(maleBtn);
femaleBtn = new JRadioButton("女");
buttonGroup.add(femaleBtn);
JLabel label_5 = new JLabel("價格:");
priceText = new JTextField();
priceText.setColumns(10);
JLabel label_6 = new JLabel("圖書作者:");
authorText = new JTextField();
authorText.setColumns(10);
JLabel label_7 = new JLabel("圖書類別:");
bookTypeComboBox = new JComboBox();
JLabel label_8 = new JLabel("圖書描述:");
bookDescText = new JTextField();
bookDescText.setColumns(10);
//修改按鈕
JButton modifyBtn = new JButton("修改");
modifyBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
modifyBookActionPerformed(e);
}
});
modifyBtn.setIcon(new ImageIcon(BookManageInterFrame.class.getResource("/images/modify.png")));
//洗掉按鈕
JButton deleteBtn = new JButton("洗掉");
deleteBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
deleteBookActionPerformed(e);
}
});
deleteBtn.setIcon(new ImageIcon(BookManageInterFrame.class.getResource("/images/delete.png")));
GroupLayout gl_panel_1 = new GroupLayout(panel_1);
gl_panel_1.setHorizontalGroup(
gl_panel_1.createParallelGroup(Alignment.TRAILING)
.addGroup(gl_panel_1.createSequentialGroup()
.addGap(44)
.addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING, false)
.addGroup(gl_panel_1.createSequentialGroup()
.addComponent(label_8)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(bookDescText))
.addGroup(gl_panel_1.createSequentialGroup()
.addGroup(gl_panel_1.createParallelGroup(Alignment.TRAILING)
.addComponent(label_2)
.addComponent(label_5))
.addPreferredGap(ComponentPlacement.UNRELATED)
.addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING, false)
.addComponent(priceText)
.addComponent(idText, GroupLayout.DEFAULT_SIZE, 86, Short.MAX_VALUE))
.addGap(37)
.addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING, false)
.addGroup(gl_panel_1.createSequentialGroup()
.addComponent(label_3)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(bookNameText, GroupLayout.PREFERRED_SIZE, 136, GroupLayout.PREFERRED_SIZE))
.addGroup(gl_panel_1.createSequentialGroup()
.addComponent(label_6)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(authorText)))
.addGap(35)
.addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING)
.addGroup(gl_panel_1.createSequentialGroup()
.addComponent(label_4)
.addPreferredGap(ComponentPlacement.UNRELATED)
.addComponent(maleBtn)
.addGap(18)
.addComponent(femaleBtn))
.addGroup(gl_panel_1.createSequentialGroup()
.addComponent(label_7)
.addPreferredGap(ComponentPlacement.UNRELATED)
.addComponent(bookTypeComboBox, GroupLayout.PREFERRED_SIZE, 97, GroupLayout.PREFERRED_SIZE)))))
.addContainerGap(34, Short.MAX_VALUE))
.addGroup(gl_panel_1.createSequentialGroup()
.addContainerGap(201, Short.MAX_VALUE)
.addComponent(modifyBtn)
.addGap(104)
.addComponent(deleteBtn)
.addGap(190))
);
gl_panel_1.setVerticalGroup(
gl_panel_1.createParallelGroup(Alignment.LEADING)
.addGroup(gl_panel_1.createSequentialGroup()
.addContainerGap()
.addGroup(gl_panel_1.createParallelGroup(Alignment.BASELINE)
.addComponent(maleBtn)
.addComponent(bookNameText, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(label_3)
.addComponent(label_2)
.addComponent(idText, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(femaleBtn)
.addComponent(label_4))
.addGap(18)
.addGroup(gl_panel_1.createParallelGroup(Alignment.BASELINE)
.addComponent(priceText, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(label_5)
.addComponent(label_6)
.addComponent(authorText, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(bookTypeComboBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(label_7))
.addGap(18)
.addGroup(gl_panel_1.createParallelGroup(Alignment.BASELINE)
.addComponent(label_8)
.addComponent(bookDescText, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGap(27)
.addGroup(gl_panel_1.createParallelGroup(Alignment.BASELINE)
.addComponent(modifyBtn)
.addComponent(deleteBtn))
.addContainerGap())
);
panel_1.setLayout(gl_panel_1);
//表格
bookTable = new JTable();
//表格滑鼠按下事件
bookTable.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
tableMousePressed(e);
}
});
bookTable.setModel(new DefaultTableModel(
new Object[][] {
},
new String[] {
"編號", "圖書名稱", "圖書作者", "圖書性別", "圖書價格", "圖書類別", "圖書描述"
}
) {
boolean[] columnEditables = new boolean[] {
false, false, false, false, false, false, false
};
public boolean isCellEditable(int row, int column) {
return columnEditables[column];
}
});
bookTable.getColumnModel().getColumn(0).setPreferredWidth(56);
bookTable.getColumnModel().getColumn(1).setPreferredWidth(100);
bookTable.getColumnModel().getColumn(2).setPreferredWidth(63);
bookTable.getColumnModel().getColumn(3).setPreferredWidth(63);
bookTable.getColumnModel().getColumn(4).setPreferredWidth(61);
bookTable.getColumnModel().getColumn(5).setPreferredWidth(94);
bookTable.getColumnModel().getColumn(6).setPreferredWidth(163);
scrollPane.setViewportView(bookTable);
JLabel lblL = new JLabel("圖書名稱:");
s_bookNameText = new JTextField();
s_bookNameText.setColumns(10);
JLabel label = new JLabel("圖書作者:");
s_authorText = new JTextField();
s_authorText.setColumns(10);
JLabel label_1 = new JLabel("圖書類別:");
s_bookTypecomboBox = new JComboBox();
//圖書查詢按鈕
JButton s_searchBtn = new JButton("查詢");
s_searchBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
searchActionPerformed(e);
}
});
s_searchBtn.setIcon(new ImageIcon(BookManageInterFrame.class.getResource("/images/search.png")));
GroupLayout gl_panel = new GroupLayout(panel);
gl_panel.setHorizontalGroup(
gl_panel.createParallelGroup(Alignment.LEADING)
.addGroup(gl_panel.createSequentialGroup()
.addGap(20)
.addComponent(lblL)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(s_bookNameText, GroupLayout.PREFERRED_SIZE, 88, GroupLayout.PREFERRED_SIZE)
.addGap(18)
.addComponent(label)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(s_authorText, GroupLayout.DEFAULT_SIZE, 89, Short.MAX_VALUE)
.addGap(18)
.addComponent(label_1)
.addPreferredGap(ComponentPlacement.UNRELATED)
.addComponent(s_bookTypecomboBox, GroupLayout.PREFERRED_SIZE, 94, GroupLayout.PREFERRED_SIZE)
.addGap(18)
.addComponent(s_searchBtn)
.addGap(29))
);
gl_panel.setVerticalGroup(
gl_panel.createParallelGroup(Alignment.LEADING)
.addGroup(gl_panel.createSequentialGroup()
.addContainerGap()
.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
.addComponent(lblL)
.addComponent(s_bookNameText, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(label)
.addComponent(s_authorText, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(label_1)
.addComponent(s_bookTypecomboBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(s_searchBtn))
.addContainerGap(19, Short.MAX_VALUE))
);
panel.setLayout(gl_panel);
getContentPane().setLayout(groupLayout);
//初始化搜索欄圖書類別下拉框
fillBookTypeComboBox("search");
//初始化操作欄圖書類別下拉框
fillBookTypeComboBox("modify");
//初始化表格顯示,顯示所有的書籍
fillBookTable(new Book());
}
/**
* 圖書修改事件
* @param evt
*/
private void modifyBookActionPerformed(ActionEvent evt) {
//獲取圖書id
String id=idText.getText();
//獲取圖書名稱
String bookName=bookNameText.getText();
//獲取圖書作者
String author=authorText.getText();
//或者作者性別
String sex="男";
if(femaleBtn.isSelected()){
sex="女";
}
//獲取圖書價格
String price=priceText.getText();
//獲取圖書id
BookType bookType=(BookType)bookTypeComboBox.getSelectedItem();
Integer bookTypeId=bookType.getId();
//獲取圖書描述
String bookDesc=bookDescText.getText();
//判斷是否id是否為空
if(id==null || "".equals(id)){ //為空
JOptionPane.showMessageDialog(null, "請選中要洗掉的行!"); //給用戶提示
return;
}
//判斷圖書名稱是否為空
if(bookName==null || "".equals(bookName)){ //為空
JOptionPane.showMessageDialog(null, "圖書名稱不能為空!"); //給用戶提示
return;
}
//判斷圖書作者是否為空
if(author==null || "".equals(author)){ //為空
JOptionPane.showMessageDialog(null, "圖書作者不能為空!"); //給用戶提示
return;
}
//判斷圖書價格是否為空
if(price==null || "".equals(price)){ //為空
JOptionPane.showMessageDialog(null, "圖書價格不能為空!"); //給用戶提示
return;
}
//從獲取的圖書資訊創建圖書物件
Book book=new Book(Integer.parseInt(id),bookName, author, sex, Float.parseFloat(price), bookTypeId, bookDesc, null);
System.out.println("從獲取的圖書資訊創建圖書物件:"+book);
//定義資料庫連接
Connection con=null;
try {
//獲取資料庫連接
con=DBTool.getConnetion();
//初始化圖書資料訪問物件
bookDao=new BookDao();
//執行圖書訪問物件的修改方法,并獲得修改的記錄數
int res=bookDao.update(con, book);
if(res==1){ //為1
JOptionPane.showMessageDialog(null,"圖書修改成功n_n");
//重繪圖書表格顯示
fillBookTable(new Book());
//重置操作欄
resetValue();
}else{ //為0
JOptionPane.showMessageDialog(null,"圖書修改失敗u_u");
}
} catch (SQLException e) {
//記錄日志
e.printStackTrace();
throw new RuntimeException("修改圖書失敗",e);
}finally{
//關閉資料庫連接
DBTool.close(con);
}
}
/**
* 圖書洗掉事件
* @param evt
*/
private void deleteBookActionPerformed(ActionEvent evt) {
//獲取圖書id
String id=idText.getText();
//判斷是否id是否為空
if(id==null || "".equals(id)){ //為空
JOptionPane.showMessageDialog(null, "請選中要洗掉的行!"); //給用戶提示
return;
}
//定義資料庫連接物件
Connection con=null;
try {
//初始化資料庫連接物件
con=DBTool.getConnetion();
//初始化圖書資料訪問物件
bookDao=new BookDao();
//執行圖書訪問物件的洗掉方法并回傳洗掉的記錄數
int res=bookDao.delete(con, Integer.parseInt(id));
if(res==1){ //為1
JOptionPane.showMessageDialog(null, "圖書洗掉成功n_n");
//重繪圖書表格顯示
fillBookTable(new Book());
//重置操作欄
resetValue();
}else{ //為其他
JOptionPane.showMessageDialog(null, "圖書洗掉失敗u_u");
}
} catch (SQLException e) {
//記錄日志
e.printStackTrace();
throw new RuntimeException("洗掉圖書失敗",e);
}finally{
//記得關閉資料庫(******)
DBTool.close(con);
}
}
/**
* 重置操作欄的所有值
*/
private void resetValue(){
idText.setText("");
bookNameText.setText("");
authorText.setText("");
maleBtn.setSelected(true);
priceText.setText("");
fillBookTypeComboBox("modify");
bookDescText.setText("");
}
/**
* 表格滑鼠按下事件處理
* @param evt
*/
private void tableMousePressed(MouseEvent evt) {
//獲取圖書表格選中的行的行號
int row=bookTable.getSelectedRow();
//獲取選中行第一個資料并設定顯示在操作欄的id框
idText.setText((Integer)bookTable.getValueAt(row,0)+"");
//獲取選中行第二個資料并設定顯示在操作欄的圖書名稱框
bookNameText.setText((String)bookTable.getValueAt(row, 1));
//獲取選中行第三個資料并設定顯示在操作欄的圖書作者框
authorText.setText((String)bookTable.getValueAt(row, 2));
//獲取選中行第四個資料并設定顯示在操作欄的作者性別單選框
String sex=(String)bookTable.getValueAt(row, 3);
if("男".equals(sex)){
maleBtn.setSelected(true);
}else{
femaleBtn.setSelected(true);
}
//獲取選中行第五個資料并設定顯示在操作欄的圖書價格框
priceText.setText((Float)bookTable.getValueAt(row, 4)+"");
//獲取選中行第六個資料并設定顯示在操作欄的圖書類別下拉框中
String bookTypeName=(String)bookTable.getValueAt(row, 5);
int rows=bookTypeComboBox.getItemCount(); //獲取下拉框總共的選項
for(int i=0;i<rows;i++){ //遍歷下拉框
BookType item=(BookType) bookTypeComboBox.getItemAt(i); //獲取每一個選項并強轉圖書類別物件
if(item.getBookTypeName().equals(bookTypeName)){ //將獲取的圖書類別和下拉框中的圖書類別比較,若相同
bookTypeComboBox.setSelectedIndex(i); //則該下拉框選項被選中
}
}
//獲取選中行第七個資料并設定顯示在操作欄的圖書描述框
bookDescText.setText((String)bookTable.getValueAt(row, 6));
}
/**
* 圖書查詢事件處理
* @param evt 事件物件
*/
private void searchActionPerformed(ActionEvent evt) {
//獲取查詢的條件
String bookName=s_bookNameText.getText(); //圖書名稱
String author=s_authorText.getText(); //圖書作者
String bookTypeName=s_bookTypecomboBox.getSelectedItem().toString(); //圖書類別
//對圖書類別"請選擇..."換成""
if("請選擇...".equals(bookTypeName)){
bookTypeName="";
}
//生成帶有條件的圖書物件
Book book=new Book();
book.setBookName(bookName); //設定圖書名稱條件
book.setAuthor(author); //設定圖書作者條件
book.setBookTypeName(bookTypeName); //設定圖書類別條件
//呼叫table填充函式,根據查詢結果重新填充表格
fillBookTable(book);
}
/**
* 初始化圖書類別下拉框
* @param type 根據不同的引數填充不同的下拉框
*/
private void fillBookTypeComboBox(String type){
//定義一個圖書類別,用于存盤查詢的圖書類別
BookType s_bookType=null;
//定義一個資料庫連接
Connection con=null;
try {
//獲取資料庫連接
con=DBTool.getConnetion();
//初始化圖書類別訪問資料物件
bookTypeDao=new BookTypeDao();
//查詢圖書類別,得到結果集
ResultSet rs=bookTypeDao.search(con, new BookType());
if("search".equals(type)){
BookType bookType=new BookType();
bookType.setBookTypeName("請選擇...");
bookType.setId(-1);
s_bookTypecomboBox.addItem(bookType);
}
//遍歷結果集
while(rs.next()){ //如果有資料的話
//初始化接受查詢的圖書類別
s_bookType=new BookType();
//根據查詢結果設定id
s_bookType.setId(rs.getInt("id"));
//根據查詢結果設定圖書類別名稱
s_bookType.setBookTypeName(rs.getString("bookTypeName"));
if("search".equals(type)){
//將查詢的圖書類別添加到下拉框中
s_bookTypecomboBox.addItem(s_bookType);
}
if("modify".equals(type)){
//將查詢的圖書類別添加到表單操作下拉框中
bookTypeComboBox.addItem(s_bookType);
}
}
} catch (SQLException e) {
//記錄日志
e.printStackTrace();
throw new RuntimeException("初始化下拉框失敗",e);
}finally{
//關閉資料庫連接
DBTool.close(con);
}
}
/**
* 初始化表格,列出所有的書籍
* @param book
*/
private void fillBookTable(Book book){
//獲取表格的模型
DefaultTableModel dtm=(DefaultTableModel) bookTable.getModel();
//填充表格時設定成0行(相當于歸零處理)
dtm.setRowCount(0);
//定義資料庫連接
Connection con=null;
try {
//獲取資料庫連接
con=DBTool.getConnetion();
//初始化圖書資料訪問物件
bookDao=new BookDao();
//按條件查詢圖書(這里沒有條件,查出所有書籍)
ResultSet rs=bookDao.search(con, book);
//遍歷查詢結果
while(rs.next()){
//定義一個集合,由于存盤圖書資訊
Vector v=new Vector();
v.add(rs.getInt("id")); //添加編號
v.add(rs.getString("bookName")); //添加圖書名稱
v.add(rs.getString("author")); //添加圖書作者
v.add(rs.getString("sex")); //添加作者性別
v.add(rs.getFloat("price")); //添加圖書價格
v.add(rs.getString("bookTypeName")); //添加圖書類別
v.add(rs.getString("bookDesc"));
//添加表格新行
dtm.addRow(v);
}
} catch (SQLException e) {
//記錄日志
e.printStackTrace();
throw new RuntimeException("初始化表格失敗",e);
}finally{
//關閉資料庫連接
DBTool.close(con);
}
}
}
⑥ BookAddInterFrame(圖書添加界面)
package cn.ac.azure.view;
import java.awt.EventQueue;
import java.awt.Font;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.ButtonGroup;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JRadioButton;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.border.LineBorder;
import cn.ac.azure.dao.BookDao;
import cn.ac.azure.dao.BookTypeDao;
import cn.ac.azure.model.Book;
import cn.ac.azure.model.BookType;
import cn.ac.azure.util.DBTool;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class BookAddInterFrame extends JInternalFrame {
private JTextField bookNameText;
private JTextField authorText;
private final ButtonGroup buttonGroup = new ButtonGroup();
private JTextField priceText;
private JComboBox bookTypeComboBox;
private JRadioButton maleBtn;
private JRadioButton femaleBtn;
private JTextArea bookDescText;
private BookTypeDao bookTypeDao;
private BookDao bookDao;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
BookAddInterFrame frame = new BookAddInterFrame();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public BookAddInterFrame() {
setIconifiable(true);
setClosable(true);
// 改變系統默認字體
Font font = new Font("Dialog", Font.PLAIN, 12);
java.util.Enumeration keys = UIManager.getDefaults().keys();
while (keys.hasMoreElements()) {
Object key = keys.nextElement();
Object value = UIManager.get(key);
if (value instanceof javax.swing.plaf.FontUIResource) {
UIManager.put(key, font);
}
}
setTitle("圖書添加 ");
setBounds(100, 100, 699, 449);
JLabel label = new JLabel("圖書名稱:");
bookNameText = new JTextField();
bookNameText.setColumns(10);
JLabel label_1 = new JLabel("圖書作者:");
authorText = new JTextField();
authorText.setColumns(10);
JLabel label_2 = new JLabel("作者性別:");
maleBtn = new JRadioButton("男");
buttonGroup.add(maleBtn);
femaleBtn = new JRadioButton("女");
buttonGroup.add(femaleBtn);
JLabel label_3 = new JLabel("圖書價格:");
priceText = new JTextField();
priceText.setColumns(10);
JLabel label_4 = new JLabel("圖書類別:");
// 圖書類別下拉框
bookTypeComboBox = new JComboBox();
JLabel label_5 = new JLabel("圖書描述:");
bookDescText = new JTextArea();
// 圖書添加按鈕
JButton addBtn = new JButton("添加");
addBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// 圖書添加按鈕事件處理
bookAddActionPerformed(e);
}
});
addBtn.setIcon(new ImageIcon(BookAddInterFrame.class.getResource("/images/add.png")));
// 圖書重置按鈕
JButton resetBtn = new JButton("重置");
resetBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
bookResetActionPerformed(e);
}
});
resetBtn.setIcon(new ImageIcon(BookAddInterFrame.class.getResource("/images/reset.png")));
GroupLayout groupLayout = new GroupLayout(getContentPane());
groupLayout
.setHorizontalGroup(groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup().addGap(38).addGroup(groupLayout
.createParallelGroup(
Alignment.LEADING)
.addGroup(
groupLayout.createSequentialGroup().addGap(6).addGroup(groupLayout
.createParallelGroup(Alignment.LEADING, false)
.addGroup(groupLayout.createSequentialGroup().addGroup(groupLayout
.createParallelGroup(Alignment.LEADING, false)
.addGroup(groupLayout.createSequentialGroup()
.addComponent(label_4).addPreferredGap(
ComponentPlacement.RELATED)
.addComponent(bookTypeComboBox, 0,
GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(groupLayout.createSequentialGroup()
.addComponent(label)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(bookNameText, GroupLayout.PREFERRED_SIZE,
116, GroupLayout.PREFERRED_SIZE))
.addGroup(groupLayout.createSequentialGroup()
.addComponent(label_2)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(maleBtn)
.addPreferredGap(ComponentPlacement.UNRELATED)
.addComponent(femaleBtn)))
.addGap(44)
.addGroup(groupLayout
.createParallelGroup(Alignment.LEADING, false)
.addGroup(groupLayout.createSequentialGroup()
.addComponent(label_3)
.addPreferredGap(ComponentPlacement.UNRELATED)
.addComponent(priceText))
.addGroup(groupLayout.createSequentialGroup()
.addComponent(label_1)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(authorText,
GroupLayout.PREFERRED_SIZE, 128,
GroupLayout.PREFERRED_SIZE))))
.addGroup(groupLayout.createSequentialGroup().addComponent(label_5)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(bookDescText)))
.addPreferredGap(ComponentPlacement.RELATED, 164, Short.MAX_VALUE))
.addGroup(groupLayout.createSequentialGroup().addGap(94).addComponent(addBtn).addGap(96)
.addComponent(resetBtn)))
.addContainerGap()));
groupLayout.setVerticalGroup(groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup().addGap(32)
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE).addComponent(label)
.addComponent(bookNameText, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
GroupLayout.PREFERRED_SIZE)
.addComponent(label_1).addComponent(authorText, GroupLayout.PREFERRED_SIZE,
GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGap(31)
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE).addComponent(label_2)
.addComponent(maleBtn).addComponent(femaleBtn).addComponent(label_3).addComponent(
priceText, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
GroupLayout.PREFERRED_SIZE))
.addGap(37)
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
.addComponent(label_4).addComponent(bookTypeComboBox, GroupLayout.PREFERRED_SIZE,
GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGap(30)
.addGroup(
groupLayout.createParallelGroup(Alignment.BASELINE).addComponent(label_5).addComponent(
bookDescText, GroupLayout.PREFERRED_SIZE, 102, GroupLayout.PREFERRED_SIZE))
.addGap(38).addGroup(groupLayout.createParallelGroup(Alignment.BASELINE).addComponent(addBtn)
.addComponent(resetBtn))
.addContainerGap(45, Short.MAX_VALUE)));
getContentPane().setLayout(groupLayout);
// 設定文本域邊框
bookDescText.setBorder(new LineBorder(new java.awt.Color(127, 157, 185), 1, false));
// 在建構式中呼叫圖書類別下拉框初始化方法
fillBookTypeName();
// 在建構式中初始化性別,默認為男
maleBtn.setSelected(true);
}
/**
* 重置按鈕事件處理
*
* @param evt
* 重置按鈕事件物件
*/
private void bookResetActionPerformed(ActionEvent evt) {
reset();
}
/**
* 圖書添加界面資訊重置
*/
private void reset() {
bookNameText.setText("");
authorText.setText("");
maleBtn.setSelected(true);
priceText.setText("");
bookTypeComboBox.setSelectedIndex(0);
bookDescText.setText("");
}
/**
* 圖書添加按鈕事件處理
*
* @param evt
* 添加事件物件
*/
private void bookAddActionPerformed(ActionEvent evt) {
String bookName = bookNameText.getText(); // 獲取圖書名稱
if (bookName == null || "".equals(bookName.trim())) {
JOptionPane.showMessageDialog(null, "圖書名稱不能為空!");
return;
}
String author = authorText.getText(); // 獲取圖書作者
String sex = null; // 獲取圖書作者性別
if (maleBtn.isSelected()) {
sex = "男";
} else {
sex = "女";
}
String prices = priceText.getText(); // 獲取圖書價格
if (prices == null || "".equals(prices.trim())) {
JOptionPane.showMessageDialog(null, "圖書價格不能為空!");
return;
}
float price = Float.parseFloat(prices);
BookType bookType = (BookType) bookTypeComboBox.getSelectedItem(); // 獲取圖書類別
int bookTypeId = bookType.getId(); // 獲取圖書類別id
System.out.println("ID="+bookTypeId);
String bookDesc = bookDescText.getText(); // 獲取圖書描述
// 根據獲取的添加圖書界面獲取的資訊創建圖書物件
Book book = new Book(null, bookName, author, sex, price, bookTypeId, bookName, bookDesc);
System.out.println("物體類:"+book);
// 定義資料庫連接
Connection con = null;
try {
// 獲取資料庫連接
con = DBTool.getConnetion();
// 初始化圖書資料訪問物件
bookDao = new BookDao();
// 呼叫添加方法,向資料庫添加書籍
System.out.println("5555"+book);
int num = bookDao.add(con, book);
// 根據回傳值判斷圖書是否添加成功
if (num > 0) {
JOptionPane.showMessageDialog(null, "圖書添加成功n_n");
// 添加成功之后重置界面
reset();
} else {
JOptionPane.showMessageDialog(null, "圖書添加成功u_u");
}
} catch (SQLException e) {
// 記錄日志
e.printStackTrace();
throw new RuntimeException("添加圖書失敗", e);
} finally {
// 關閉資料庫連接
DBTool.close(con);
}
}
// 填充圖書類別名稱
private void fillBookTypeName() {
// 定義資料庫連接物件
Connection con = null;
// 定義圖書類別,用于查詢和儲存查詢的書籍
BookType bookType = null;
try {
// 獲取資料庫連接
con = DBTool.getConnetion();
// 初始化圖書類別訪問物件
bookTypeDao = new BookTypeDao();
// 查詢t_bookType中含有的圖書類別
ResultSet rs = bookTypeDao.search(con, bookType);
// 遍歷查詢結果
while (rs.next()) {
// 出事化圖書類別
bookType = new BookType();
// 設定圖書的id
bookType.setId(rs.getInt("id"));
// 設定圖書的名稱
bookType.setBookTypeName(rs.getString("bookTypeName"));
// 將圖書類別物件添加到下拉框中(這里添加物件,便于獲得id)
bookTypeComboBox.addItem(bookType.getBookTypeName());
}
} catch (SQLException e) {
// 記錄日志
e.printStackTrace();
throw new RuntimeException("初始化串列失敗", e);
} finally {
// 關閉資料路連接
DBTool.close(con);
}
}
}
⑦ LibraryInterFrame(關于我們界面)
package cn.ac.azure.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.UIManager;
import javax.swing.ImageIcon;
import java.awt.Font;
import java.awt.Color;
public class LibraryInterFrame extends JInternalFrame {
private static final long serialVersionUID = 1L;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
LibraryInterFrame frame = new LibraryInterFrame();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public LibraryInterFrame() {
//改變系統默認字體
Font font = new Font("Dialog", Font.PLAIN, 12);
java.util.Enumeration<Object> keys = UIManager.getDefaults().keys();
while (keys.hasMoreElements()) {
Object key = keys.nextElement();
Object value = UIManager.get(key);
if (value instanceof javax.swing.plaf.FontUIResource) {
UIManager.put(key, font);
}
}
setClosable(true);
setIconifiable(true);
setBounds(450, 150, 503, 300);
JLabel label = new JLabel("");
label.setIcon(new ImageIcon(LibraryInterFrame.class.getResource("/images/library.png")));
JLabel label_1 = new JLabel("歡迎使用圖書管理系統");
label_1.setForeground(Color.GREEN);
label_1.setBackground(Color.GREEN);
label_1.setFont(new Font("宋體", Font.PLAIN, 20));
GroupLayout groupLayout = new GroupLayout(getContentPane());
groupLayout.setHorizontalGroup(
groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addContainerGap(140, Short.MAX_VALUE)
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(Alignment.TRAILING, groupLayout.createSequentialGroup()
.addComponent(label)
.addGap(175))
.addGroup(Alignment.TRAILING, groupLayout.createSequentialGroup()
.addComponent(label_1)
.addGap(137))))
);
groupLayout.setVerticalGroup(
groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addGap(39)
.addComponent(label)
.addGap(28)
.addComponent(label_1)
.addContainerGap(51, Short.MAX_VALUE))
);
getContentPane().setLayout(groupLayout);
}
}
5、資料庫【db_book】
/*
Navicat Premium Data Transfer
Source Server : 127.0.0.1
Source Server Type : MySQL
Source Server Version : 50733
Source Host : localhost:3306
Source Schema : db_book
Target Server Type : MySQL
Target Server Version : 50733
File Encoding : 65001
Date: 19/07/2021 17:34:44
*/
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for t_book
-- ----------------------------
DROP TABLE IF EXISTS `t_book`;
CREATE TABLE `t_book` (
`id` int(50) NOT NULL AUTO_INCREMENT,
`bookName` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`author` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`sex` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`price` double(50, 2) NULL DEFAULT NULL,
`bookTypeId` int(50) NULL DEFAULT NULL,
`bookTypeName` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`bookDesc` varchar(5000) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE,
INDEX `fk_booktype`(`bookTypeId`) USING BTREE,
CONSTRAINT `fk_booktype` FOREIGN KEY (`bookTypeId`) REFERENCES `t_booktype` (`id`) ON DELETE SET NULL ON UPDATE SET NULL
) ENGINE = InnoDB AUTO_INCREMENT = 6 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of t_book
-- ----------------------------
INSERT INTO `t_book` VALUES (1, '《人間失格》', '(日)太宰治', '男', 66.00, 1, '小說', '(日本小說家太宰治代表作,一個對村上春樹影響至深的絕望凄美故事)');
INSERT INTO `t_book` VALUES (2, '《三體》', '劉慈欣', '女', 55.80, 1, '小說', '劉慈欣代表作,亞洲首部“雨果獎”獲獎作品!\r\n《三體》第73屆世界科幻雨果獎獲獎作品,銀河獎特別獎,《三體3》軌跡獎長篇科幻小說!2017年世界雨果獎提名作品,');
INSERT INTO `t_book` VALUES (3, '《人生海海》', '麥家', '男', 55.00, 2, '文化科學', '麥家重磅力作,莫言、董卿盛贊,連續兩年高居各大暢銷榜,發行量超180萬冊,羅一舟同款書)\r\n上校贏了所有的仗,卻敗給一個不足道的秘密,茅盾文學獎得主麥家暌違8年,打磨5年,挑戰常人不敢落筆之處,解密人性的荒唐與高尚,人生海海,何必在意一時沉浮!');
INSERT INTO `t_book` VALUES (4, '《大國崛起》', '唐晉', '男', 50.40, 2, '歷史', '以歷史的眼光和全球的視野解讀15世紀以來9個世界性大國崛起的歷史,中國能否成為第十個崛起的大國?');
INSERT INTO `t_book` VALUES (5, '《中華人民共和國民法典》', '法律出版社', '男', 8.10, 2, '哲學、社會', '民法典是新中國首部以“法典”命名的法律,是新時代我國社會主義法治建設的重大成果,是為百姓生活量身定制的權利寶典,自2021年1月1日起施行,');
-- ----------------------------
-- Table structure for t_booktype
-- ----------------------------
DROP TABLE IF EXISTS `t_booktype`;
CREATE TABLE `t_booktype` (
`id` int(50) NOT NULL AUTO_INCREMENT,
`bookTypeName` varchar(500) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`bookTypeDesc` varchar(500) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 25 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of t_booktype
-- ----------------------------
INSERT INTO `t_booktype` VALUES (1, 'A 馬克思主義、列寧主義、毛澤東思想、鄧小平理論', 'A 馬克思主義、列寧主義、毛澤東思想、鄧小平理論');
INSERT INTO `t_booktype` VALUES (2, 'B 哲學、宗教', 'B 哲學、宗教');
INSERT INTO `t_booktype` VALUES (3, 'C 社會科學總論', 'C 社會科學總論');
INSERT INTO `t_booktype` VALUES (4, 'D 政治、法律', 'D 政治、法律');
INSERT INTO `t_booktype` VALUES (5, 'F 經濟', 'F 經濟');
INSERT INTO `t_booktype` VALUES (6, 'G 文化、科學、教育、體育', 'G 文化、科學、教育、體育');
INSERT INTO `t_booktype` VALUES (7, 'H 語言、文字', 'H 語言、文字');
INSERT INTO `t_booktype` VALUES (8, 'I 文學', 'I 文學');
INSERT INTO `t_booktype` VALUES (9, 'J 藝術', 'J 藝術');
INSERT INTO `t_booktype` VALUES (10, 'K 歷史、地理', 'K 歷史、地理');
INSERT INTO `t_booktype` VALUES (11, 'N 自然科學總論', 'N 自然科學總論');
INSERT INTO `t_booktype` VALUES (12, 'O 數理科學和化學', 'O 數理科學和化學');
INSERT INTO `t_booktype` VALUES (13, 'Q 生物科學', 'Q 生物科學');
INSERT INTO `t_booktype` VALUES (14, 'R 醫藥、衛生 ', 'R 醫藥、衛生');
INSERT INTO `t_booktype` VALUES (15, 'S 農業科學', 'S 農業科學');
INSERT INTO `t_booktype` VALUES (16, 'T-TN 工業技術', 'T-TN 工業技術');
INSERT INTO `t_booktype` VALUES (17, 'TP 自動化技術、計算機技術', 'TP 自動化技術、計算機技術');
INSERT INTO `t_booktype` VALUES (18, 'TQ 化學工業', 'TQ 化學工業');
INSERT INTO `t_booktype` VALUES (19, 'TU 建筑科學', 'TU 建筑科學');
INSERT INTO `t_booktype` VALUES (20, 'TV 水利工程', 'TV 水利工程');
INSERT INTO `t_booktype` VALUES (21, 'U 交通運輸', 'U 交通運輸');
INSERT INTO `t_booktype` VALUES (22, 'V 航空、航天', 'V 航空、航天');
INSERT INTO `t_booktype` VALUES (23, 'X 環境科學、安全科學', 'X 環境科學、安全科學');
INSERT INTO `t_booktype` VALUES (24, 'Z 綜合性圖書', 'Z 綜合性圖書');
-- ----------------------------
-- Table structure for t_user
-- ----------------------------
DROP TABLE IF EXISTS `t_user`;
CREATE TABLE `t_user` (
`id` int(50) NOT NULL AUTO_INCREMENT,
`username` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`password` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 2 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of t_user
-- ----------------------------
INSERT INTO `t_user` VALUES (1, '11', '123456');
SET FOREIGN_KEY_CHECKS = 1;
三、專案地址:
CSDN贊助下載:
https://download.csdn.net/download/weixin_44893902/20367467
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/289263.html
標籤:java
