Eclipse+Java+Swing实现图书管理系统(下)

简介: Eclipse+Java+Swing实现图书管理系统

BookInfoFrm.java

package com.sjsq.view;
import java.sql.Connection;
import java.sql.ResultSet;
import java.util.Vector;
import javax.swing.GroupLayout;
import javax.swing.JButton;
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;
import javax.swing.table.DefaultTableModel;
import com.sjsq.dao.BookDao;
import com.sjsq.dao.BorrowDetailDao;
import com.sjsq.model.Book;
import com.sjsq.model.BorrowDetail;
import com.sjsq.util.DbUtil;
import com.sjsq.util.StringUtil;
import com.sjsq.util.TimeUtil;
public class BookInfoFrm extends JInternalFrame {
  private JTextField bookIdText;
  private JTextField bookName;
  private JTextField bookNameText;
  private JTable bookTable;
  private JButton jB_borrow;
  private JButton jButton1;
  private JLabel jLabel1;
  private JLabel jLabel2;
  private JLabel jLabel3;
  private JPanel jPanel1;
  private JScrollPane jScrollPane1;
  DbUtil dbUtil = new DbUtil();
  BookDao bookDao = new BookDao();
  BorrowDetailDao borrowDetailDao = new BorrowDetailDao();
  public BookInfoFrm() {
    initComponents();
    fillTable(new Book());
    setTitle("书籍信息");
    this.setLocation(200, 50);
  }
  private void fillTable(Book book) {
    DefaultTableModel model = (DefaultTableModel) bookTable.getModel();
    model.setRowCount(0);
    Connection con = null;
    try {
      con = dbUtil.getCon();
      book.setStatus(1);
      ResultSet list = bookDao.list(con, book);
      while (list.next()) {
        Vector rowData = new Vector();
        rowData.add(list.getInt("id"));
        rowData.add(list.getString("book_name"));
        rowData.add(list.getString("type_name"));
        rowData.add(list.getString("author"));
        rowData.add(list.getString("remark"));
        model.addRow(rowData);
      }
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      try {
        dbUtil.closeCon(con);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
  private void initComponents() {
    jScrollPane1 = new JScrollPane();
    bookTable = new JTable();
    jPanel1 = new JPanel();
    jLabel1 = new JLabel();
    bookNameText = new JTextField();
    jButton1 = new JButton();
    jB_borrow = new JButton();
    jLabel2 = new JLabel();
    bookIdText = new JTextField();
    jLabel3 = new JLabel();
    bookName = new JTextField();
    setClosable(true);
    bookTable.setModel(new DefaultTableModel(new Object[][] {
    }, new String[] { "编号", "书名", "类型", "作者", "描述" }) {
      boolean[] canEdit = new boolean[] { false, false, false, false, false };
      public boolean isCellEditable(int rowIndex, int columnIndex) {
        return canEdit[columnIndex];
      }
    });
    bookTable.addMouseListener(new java.awt.event.MouseAdapter() {
      public void mousePressed(java.awt.event.MouseEvent evt) {
        bookTableMousePressed(evt);
      }
    });
    jScrollPane1.setViewportView(bookTable);
    jLabel1.setText("书籍名称:");
    bookNameText.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        bookNameTextActionPerformed(evt);
      }
    });
    jButton1.setText("查询");
    jButton1.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jButton1ActionPerformed(evt);
      }
    });
    GroupLayout jPanel1Layout = new GroupLayout(jPanel1);
    jPanel1.setLayout(jPanel1Layout);
    jPanel1Layout.setHorizontalGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.LEADING)
        .addGroup(GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
            .addGap(42, 42, 42).addComponent(jLabel1).addGap(36, 36, 36)
            .addComponent(bookNameText, GroupLayout.PREFERRED_SIZE, 130,
                GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 149, Short.MAX_VALUE)
            .addComponent(jButton1).addGap(45, 45, 45)));
    jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.LEADING)
        .addGroup(jPanel1Layout.createSequentialGroup().addGap(23, 23, 23)
            .addGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                .addComponent(jButton1).addComponent(jLabel1).addComponent(bookNameText,
                    GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                    GroupLayout.PREFERRED_SIZE))
            .addContainerGap(30, Short.MAX_VALUE)));
    jB_borrow.setText("借书");
    jB_borrow.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jB_borrowActionPerformed(evt);
      }
    });
    jLabel2.setText("编号:");
    bookIdText.setEditable(false);
    jLabel3.setText("书名:");
    bookName.setEditable(false);
    GroupLayout layout = new GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout
        .createSequentialGroup().addGap(22, 22, 22)
        .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout
            .createSequentialGroup().addComponent(jLabel2)
            .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(bookIdText, GroupLayout.PREFERRED_SIZE, 95,
                GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(jLabel3)
            .addGap(18, 18, 18)
            .addComponent(bookName, GroupLayout.PREFERRED_SIZE, 127,
                GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 102, Short.MAX_VALUE)
            .addComponent(jB_borrow).addGap(88, 88, 88))
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel1, GroupLayout.Alignment.TRAILING,
                        GroupLayout.DEFAULT_SIZE,
                        GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jScrollPane1, GroupLayout.Alignment.TRAILING,
                        GroupLayout.DEFAULT_SIZE, 507, Short.MAX_VALUE))
                .addContainerGap(38, Short.MAX_VALUE)))));
    layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addComponent(jPanel1, GroupLayout.PREFERRED_SIZE,
                GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(jScrollPane1, GroupLayout.PREFERRED_SIZE, 225,
                GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 35, Short.MAX_VALUE)
            .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel2).addComponent(jLabel3)
                .addComponent(bookIdText, GroupLayout.PREFERRED_SIZE,
                    GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                .addComponent(bookName, GroupLayout.PREFERRED_SIZE,
                    GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                .addComponent(jB_borrow))
            .addGap(27, 27, 27)));
    pack();
  }
  private void jB_borrowActionPerformed(java.awt.event.ActionEvent evt) {
    String bookId = this.bookIdText.getText();
    String bookName = this.bookName.getText();
    if (StringUtil.isEmpty(bookId) || StringUtil.isEmpty(bookName)) {
      JOptionPane.showMessageDialog(null, "请选择相关书籍");
      return;
    }
    BorrowDetail borrowDetail = new BorrowDetail();
    borrowDetail.setUserId(LoginFrm.currentUser.getUserId());
    borrowDetail.setBookId(Integer.parseInt(bookId));
    borrowDetail.setStatus(1);
    borrowDetail.setBorrowTime(TimeUtil.getTime());
    Connection con = null;
    try {
      con = dbUtil.getCon();
      // 先查询是否有该书在借
      ResultSet list = borrowDetailDao.list(con, borrowDetail);
      while (list.next()) {
        JOptionPane.showMessageDialog(null, "该书已在借,请先还再借");
        return;
      }
      int i = borrowDetailDao.add(con, borrowDetail);
      if (i == 1) {
        JOptionPane.showMessageDialog(null, "借书成功");
      } else {
        JOptionPane.showMessageDialog(null, "借书失败");
      }
    } catch (Exception e) {
      e.printStackTrace();
      JOptionPane.showMessageDialog(null, "借书异常");
    } finally {
      try {
        dbUtil.closeCon(con);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
  private void bookTableMousePressed(java.awt.event.MouseEvent evt) {
    int row = this.bookTable.getSelectedRow();
    Object bookId = this.bookTable.getValueAt(row, 0);
    Object bookName = this.bookTable.getValueAt(row, 1);
    this.bookIdText.setText(bookId.toString());
    this.bookName.setText(bookName.toString());
  }
  private void bookNameTextActionPerformed(java.awt.event.ActionEvent evt) {
  }
  private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
    String bookName = this.bookNameText.getText();
    Book book = new Book();
    book.setBookName(bookName);
    fillTable(book);
  }
}

BookTypeAddFrm.java

package com.sjsq.view;
import java.sql.Connection;
import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import com.sjsq.dao.BookTypeDao;
import com.sjsq.model.BookType;
import com.sjsq.util.DbUtil;
import com.sjsq.util.StringUtil;
public class BookTypeAddFrm extends JInternalFrame {
  private JButton jButton1;
  private JButton jButton2;
  private JLabel jLabel1;
  private JLabel jLabel2;
  private JScrollPane jScrollPane1;
  private JTextField typeNameText;
  private JTextArea typeRemarkTtext;
  DbUtil dbUtil = new DbUtil();
  BookTypeDao bookTypeDao = new BookTypeDao();
  public BookTypeAddFrm() {
    initComponents();
    setTitle("图书类别添加");
    this.setLocation(200, 50);
  }
  private void initComponents() {
    jLabel1 = new JLabel();
    jLabel2 = new JLabel();
    jButton1 = new JButton();
    typeNameText = new JTextField();
    jScrollPane1 = new JScrollPane();
    typeRemarkTtext = new JTextArea();
    jButton2 = new JButton();
    setClosable(true);
    jLabel1.setText("图书类别名称:");
    jLabel2.setText("类别说明:");
    jButton1.setText("添加");
    jButton1.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jButton1ActionPerformed(evt);
      }
    });
    typeRemarkTtext.setColumns(20);
    typeRemarkTtext.setRows(5);
    jScrollPane1.setViewportView(typeRemarkTtext);
    jButton2.setText("重置");
    jButton2.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jButton2ActionPerformed(evt);
      }
    });
    GroupLayout layout = new GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup().addGap(49, 49, 49)
            .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING, false)
                .addGroup(layout.createSequentialGroup().addComponent(jLabel2).addGap(18, 18, 18)
                    .addComponent(jScrollPane1))
                .addGroup(layout.createSequentialGroup().addComponent(jLabel1).addGap(18, 18, 18)
                    .addComponent(typeNameText, GroupLayout.PREFERRED_SIZE, 241,
                        GroupLayout.PREFERRED_SIZE))
                .addGroup(layout.createSequentialGroup().addComponent(jButton1).addGap(53, 53, 53)
                    .addComponent(jButton2)))
            .addGap(179, 179, 179)));
    layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout
        .createSequentialGroup().addGap(35, 35, 35)
        .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(jLabel1)
            .addComponent(typeNameText, GroupLayout.PREFERRED_SIZE,
                GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
        .addGap(43, 43, 43)
        .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(jLabel2)
            .addComponent(jScrollPane1, GroupLayout.PREFERRED_SIZE, 134,
                GroupLayout.PREFERRED_SIZE))
        .addGap(41, 41, 41).addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
            .addComponent(jButton1).addComponent(jButton2))
        .addContainerGap(62, Short.MAX_VALUE)));
    pack();
  }
  private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
    String typeName = this.typeNameText.getText();
    String typeRemark = this.typeRemarkTtext.getText();
    if (StringUtil.isEmpty(typeName) || StringUtil.isEmpty(typeRemark)) {
      JOptionPane.showMessageDialog(null, "请输入相关信息");
      return;
    }
    BookType bookType = new BookType();
    bookType.setTypeName(typeName);
    bookType.setRemark(typeRemark);
    Connection con = null;
    try {
      con = dbUtil.getCon();
      int i = bookTypeDao.add(con, bookType);
      if (i == 1) {
        JOptionPane.showMessageDialog(null, "添加成功");
        reset();
      } else if (i == 2) {
        JOptionPane.showMessageDialog(null, "添加失败,类别已存在");
      } else {
        JOptionPane.showMessageDialog(null, "添加失败");
      }
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      try {
        dbUtil.closeCon(con);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
  private void reset() {
    this.typeNameText.setText("");
    this.typeRemarkTtext.setText("");
  }
  private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
    reset();
  }
}

BookTypeManagerFrm.java

package com.sjsq.view;
import java.sql.Connection;
import java.sql.ResultSet;
import java.util.Vector;
import javax.swing.BorderFactory;
import javax.swing.GroupLayout;
import javax.swing.JButton;
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;
import javax.swing.table.DefaultTableModel;
import com.sjsq.dao.BookTypeDao;
import com.sjsq.model.BookType;
import com.sjsq.util.DbUtil;
import com.sjsq.util.StringUtil;
public class BookTypeManagerFrm extends JInternalFrame {
  private JButton jButton1;
  private JButton jButton2;
  private JLabel jLabel1;
  private JLabel jLabel2;
  private JLabel jLabel3;
  private JPanel jPanel1;
  private JScrollPane jScrollPane1;
  private JTextField typeIdText;
  private JTextField typeNameText;
  private JTextField typeRemarkText;
  private JTable typeTable;
  DbUtil dbUtil = new DbUtil();
  BookTypeDao bookTypeDao = new BookTypeDao();
  public BookTypeManagerFrm() {
    initComponents();
    fillTable();
    setTitle("图书类别修改");
    this.setLocation(200, 30);
  }
  private void fillTable() {
    DefaultTableModel model = (DefaultTableModel) typeTable.getModel();
    model.setRowCount(0);
    Connection con = null;
    try {
      con = dbUtil.getCon();
      ResultSet list = bookTypeDao.list(con, new BookType());
      while (list.next()) {
        Vector rowData = new Vector();
        rowData.add(list.getInt("id"));
        rowData.add(list.getString("type_name"));
        rowData.add(list.getString("remark"));
        model.addRow(rowData);
      }
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      try {
        dbUtil.closeCon(con);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
  private void initComponents() {
    jScrollPane1 = new JScrollPane();
    typeTable = new JTable();
    jPanel1 = new JPanel();
    jLabel1 = new JLabel();
    jLabel2 = new JLabel();
    jLabel3 = new JLabel();
    typeIdText = new JTextField();
    typeNameText = new JTextField();
    typeRemarkText = new JTextField();
    jButton1 = new JButton();
    jButton2 = new JButton();
    setClosable(true);
    typeTable.setModel(new DefaultTableModel(new Object[][] {
    }, new String[] { "编号", "类别名称", "类别描述" }) {
      boolean[] canEdit = new boolean[] { false, false, false };
      public boolean isCellEditable(int rowIndex, int columnIndex) {
        return canEdit[columnIndex];
      }
    });
    typeTable.addMouseListener(new java.awt.event.MouseAdapter() {
      public void mousePressed(java.awt.event.MouseEvent evt) {
        typeTableMousePressed(evt);
      }
    });
    jScrollPane1.setViewportView(typeTable);
    jPanel1.setBorder(BorderFactory.createTitledBorder("表单操作"));
    jPanel1.setToolTipText("");
    jLabel1.setText("编号:");
    jLabel2.setText("类别名称:");
    jLabel3.setText("描述:");
    typeIdText.setEditable(false);
    jButton1.setText("修改");
    jButton1.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jButton1ActionPerformed(evt);
      }
    });
    jButton2.setText("删除");
    jButton2.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jButton2ActionPerformed(evt);
      }
    });
    GroupLayout jPanel1Layout = new GroupLayout(jPanel1);
    jPanel1.setLayout(jPanel1Layout);
    jPanel1Layout.setHorizontalGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.LEADING)
        .addGroup(jPanel1Layout.createSequentialGroup().addGroup(jPanel1Layout
            .createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup().addGap(22, 22, 22).addGroup(jPanel1Layout
                .createParallelGroup(GroupLayout.Alignment.LEADING, false)
                .addGroup(jPanel1Layout.createSequentialGroup().addComponent(jLabel3).addGap(18, 18, 18)
                    .addComponent(typeRemarkText))
                .addGroup(jPanel1Layout.createSequentialGroup().addComponent(jLabel1).addGap(18, 18, 18)
                    .addComponent(typeIdText, GroupLayout.PREFERRED_SIZE, 123,
                        GroupLayout.PREFERRED_SIZE)
                    .addGap(18, 18, 18)
                    .addGroup(jPanel1Layout
                        .createParallelGroup(GroupLayout.Alignment.LEADING)
                        .addComponent(jButton2)
                        .addGroup(jPanel1Layout.createSequentialGroup().addComponent(jLabel2)
                            .addGap(18, 18, 18).addComponent(typeNameText,
                                GroupLayout.PREFERRED_SIZE, 133,
                                GroupLayout.PREFERRED_SIZE))))))
            .addGroup(jPanel1Layout.createSequentialGroup().addGap(41, 41, 41).addComponent(jButton1)))
            .addContainerGap(43, Short.MAX_VALUE)));
    jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.LEADING)
        .addGroup(jPanel1Layout.createSequentialGroup().addGroup(jPanel1Layout
            .createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel1).addComponent(jLabel2).addComponent(typeNameText,
                    GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                    GroupLayout.PREFERRED_SIZE))
            .addComponent(typeIdText, GroupLayout.PREFERRED_SIZE,
                GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
            .addGap(27, 27, 27)
            .addGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel3).addComponent(typeRemarkText,
                    GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                    GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 41, Short.MAX_VALUE)
            .addGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                .addComponent(jButton1).addComponent(jButton2))
            .addContainerGap()));
    GroupLayout layout = new GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout
        .createSequentialGroup().addGap(42, 42, 42)
        .addGroup(layout.createParallelGroup(GroupLayout.Alignment.TRAILING)
            .addComponent(jPanel1, GroupLayout.Alignment.LEADING,
                GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE,
                Short.MAX_VALUE)
            .addComponent(jScrollPane1, GroupLayout.Alignment.LEADING,
                GroupLayout.PREFERRED_SIZE, 452, GroupLayout.PREFERRED_SIZE))
        .addContainerGap(49, Short.MAX_VALUE)));
    layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup().addContainerGap()
            .addComponent(jScrollPane1, GroupLayout.PREFERRED_SIZE, 137,
                GroupLayout.PREFERRED_SIZE)
            .addGap(51, 51, 51)
            .addComponent(jPanel1, GroupLayout.PREFERRED_SIZE,
                GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
            .addContainerGap(30, Short.MAX_VALUE)));
    pack();
  }
  private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
    String typeId = this.typeIdText.getText();
    if (StringUtil.isEmpty(typeId)) {
      JOptionPane.showMessageDialog(null, "请选择相关信息");
      return;
    }
    Connection con = null;
    try {
      con = dbUtil.getCon();
      int i = bookTypeDao.delete(con, typeId);
      if (i == 1) {
        JOptionPane.showMessageDialog(null, "删除成功");
        fillTable();
      } else if (i == 2) {
        JOptionPane.showMessageDialog(null, "删除失败-类别最少保留一个");
      } else if (i == 3) {
        JOptionPane.showMessageDialog(null, "删除失败-该类别下有书籍");
      } else {
        JOptionPane.showMessageDialog(null, "删除失败");
      }
    } catch (Exception e) {
      e.printStackTrace();
      JOptionPane.showMessageDialog(null, "删除异常");
    } finally {
      try {
        dbUtil.closeCon(con);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
  private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
    String typeId = this.typeIdText.getText();
    String typeName = this.typeNameText.getText();
    String typeRemark = this.typeRemarkText.getText();
    if (StringUtil.isEmpty(typeName) || StringUtil.isEmpty(typeRemark)) {
      JOptionPane.showMessageDialog(null, "请输入相关信息");
      return;
    }
    BookType bookType = new BookType();
    bookType.setTypeId(Integer.parseInt(typeId));
    bookType.setTypeName(typeName);
    bookType.setRemark(typeRemark);
    Connection con = null;
    try {
      con = dbUtil.getCon();
      int i = bookTypeDao.update(con, bookType);
      if (i == 1) {
        JOptionPane.showMessageDialog(null, "修改成功");
        fillTable();
      } else {
        JOptionPane.showMessageDialog(null, "修改失败");
      }
    } catch (Exception e) {
      e.printStackTrace();
      JOptionPane.showMessageDialog(null, "修改异常");
    } finally {
      try {
        dbUtil.closeCon(con);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
  private void typeTableMousePressed(java.awt.event.MouseEvent evt) {
    int row = this.typeTable.getSelectedRow();
    this.typeIdText.setText(typeTable.getValueAt(row, 0).toString());
    this.typeNameText.setText(typeTable.getValueAt(row, 1).toString());
    this.typeRemarkText.setText(typeTable.getValueAt(row, 2).toString());
  }
}

BorrowDetailFrm.java

package com.sjsq.view;
import java.sql.Connection;
import java.sql.ResultSet;
import java.util.Vector;
import javax.swing.GroupLayout;
import javax.swing.JInternalFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import com.sjsq.dao.BorrowDetailDao;
import com.sjsq.model.BorrowDetail;
import com.sjsq.util.DbUtil;
import com.sjsq.util.TimeUtil;
public class BorrowDetailFrm extends JInternalFrame {
  private JTable detailTable;
  private JScrollPane jScrollPane1;
  DbUtil dbUtil = new DbUtil();
  BorrowDetailDao borrowDetailDao = new BorrowDetailDao();
  public BorrowDetailFrm() {
    initComponents();
    fillTable(new BorrowDetail());
    setTitle("借还信息");
    this.setLocation(200, 50);
  }
  private void fillTable(BorrowDetail borrowDetail) {
    DefaultTableModel model = (DefaultTableModel) detailTable.getModel();
    model.setRowCount(0);
    Connection con = null;
    try {
      con = dbUtil.getCon();
      ResultSet list = borrowDetailDao.list(con, borrowDetail);
      while (list.next()) {
        Vector rowData = new Vector();
        rowData.add(list.getString("username"));
        rowData.add(list.getString("book_name"));
        int status = list.getInt("status");
        if (status == 1) {
          rowData.add("在借");
        } else {
          rowData.add("已还");
        }
        rowData.add(TimeUtil.getDateByTime(list.getLong("borrow_time")));
        if (status == 2) {
          rowData.add(TimeUtil.getDateByTime(list.getLong("return_time")));
        }
        model.addRow(rowData);
      }
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      try {
        dbUtil.closeCon(con);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
  private void initComponents() {
    jScrollPane1 = new JScrollPane();
    detailTable = new JTable();
    setClosable(true);
    detailTable.setModel(new DefaultTableModel(new Object[][] {
    }, new String[] { "借书人", "书名", "状态", "借书时间", "还书时间" }) {
      boolean[] canEdit = new boolean[] { false, false, false, false, false };
      public boolean isCellEditable(int rowIndex, int columnIndex) {
        return canEdit[columnIndex];
      }
    });
    jScrollPane1.setViewportView(detailTable);
    GroupLayout layout = new GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup().addContainerGap()
            .addComponent(jScrollPane1, GroupLayout.DEFAULT_SIZE, 700, Short.MAX_VALUE)
            .addContainerGap()));
    layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
        .addGroup(layout
            .createSequentialGroup().addContainerGap().addComponent(jScrollPane1,
                GroupLayout.PREFERRED_SIZE, 366, GroupLayout.PREFERRED_SIZE)
            .addContainerGap(25, Short.MAX_VALUE)));
    pack();
  }
}

LoginFrm.java

package com.sjsq.view;
import java.sql.Connection;
import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.LayoutStyle;
import javax.swing.WindowConstants;
import com.sjsq.dao.UserDao;
import com.sjsq.model.User;
import com.sjsq.util.DbUtil;
import com.sjsq.util.StringUtil;
public class LoginFrm extends JFrame {
  public static User currentUser;
  private JButton jB_login;
  private JButton jB_reset;
  private JLabel jLabel1;
  private JLabel jLabel2;
  private JLabel jLabel3;
  private JTextField passwordText;
  private JComboBox role;
  private JTextField userNameText;
  UserDao userDao = new UserDao();
  DbUtil dbUtil = new DbUtil();
  public LoginFrm() {
    initComponents();
    this.role.addItem("学生");
    this.role.addItem("管理员");
    this.setLocationRelativeTo(null);
  }
  private void initComponents() {
    jLabel1 = new JLabel();
    jLabel2 = new JLabel();
    jLabel3 = new JLabel();
    jB_login = new JButton();
    jB_reset = new JButton();
    userNameText = new JTextField();
    passwordText = new JTextField();
    role = new JComboBox();
    setTitle("用户登录");
    setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    setResizable(false);
    jLabel1.setText("账号:");
    jLabel2.setText("密码:");
    jLabel3.setText("角色:");
    jB_login.setText("登录");
    jB_login.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jB_loginActionPerformed(evt);
      }
    });
    jB_reset.setText("重置");
    jB_reset.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jB_resetActionPerformed(evt);
      }
    });
    GroupLayout layout = new GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout
        .createSequentialGroup().addGap(59, 59, 59)
        .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup().addComponent(jB_login).addGap(87, 87, 87)
                .addComponent(jB_reset))
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel3).addComponent(jLabel2).addComponent(jLabel1))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING, false)
                    .addComponent(userNameText, GroupLayout.DEFAULT_SIZE, 150,
                        Short.MAX_VALUE)
                    .addComponent(passwordText)
                    .addComponent(role, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
        .addContainerGap(137, Short.MAX_VALUE)));
    layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout
        .createSequentialGroup().addGap(49, 49, 49)
        .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(jLabel1)
            .addComponent(userNameText, GroupLayout.PREFERRED_SIZE,
                GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
        .addGap(45, 45, 45)
        .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(jLabel2)
            .addComponent(passwordText, GroupLayout.PREFERRED_SIZE,
                GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
        .addGap(33, 33, 33)
        .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(jLabel3)
            .addComponent(role, GroupLayout.PREFERRED_SIZE,
                GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 42, Short.MAX_VALUE)
        .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(jB_login)
            .addComponent(jB_reset))
        .addGap(37, 37, 37)));
    pack();
  }
  private void jB_loginActionPerformed(java.awt.event.ActionEvent evt) {
    String userName = this.userNameText.getText();
    String password = this.passwordText.getText();
    int index = this.role.getSelectedIndex();
    if (StringUtil.isEmpty(userName) || StringUtil.isEmpty(password)) {
      JOptionPane.showMessageDialog(null, "请输入相关信息");
      return;
    }
    User user = new User();
    user.setUserName(userName);
    user.setPassword(password);
    if (index == 0) {
      user.setRole(1);
    } else {
      user.setRole(2);
    }
    Connection con = null;
    try {
      con = dbUtil.getCon();
      User login = userDao.login(con, user);
      currentUser = login;
      if (login == null) {
        JOptionPane.showMessageDialog(null, "登录失败");
      } else {
        // 角色 1普通 2管理员
        if (index == 0) {
          // 学生
          this.dispose();
          new UserMainFrm().setVisible(true);
        } else {
          // 管理员
          this.dispose();
          new AdminMainFrm().setVisible(true);
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
      JOptionPane.showMessageDialog(null, "登录异常");
    } finally {
      try {
        dbUtil.closeCon(con);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
  private void reset() {
    this.userNameText.setText("");
    this.passwordText.setText("");
  }
  private void jB_resetActionPerformed(java.awt.event.ActionEvent evt) {
    reset();
  }
  public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
      public void run() {
        new LoginFrm().setVisible(true);
      }
    });
  }
}

RegisterFrm.java

package com.sjsq.view;
import java.sql.Connection;
import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.LayoutStyle;
import javax.swing.WindowConstants;
import com.sjsq.dao.UserDao;
import com.sjsq.model.User;
import com.sjsq.util.DbUtil;
import com.sjsq.util.StringUtil;
public class RegisterFrm extends JFrame {
  private JButton jButton1;
  private JButton jButton2;
  private JLabel jLabel1;
  private JLabel jLabel2;
  private JTextField passwordText;
  private JTextField userNameText;
  DbUtil dbUtil = new DbUtil();
  UserDao userDao = new UserDao();
  public RegisterFrm() {
    initComponents();
    this.setLocationRelativeTo(null);
  }
  private void initComponents() {
    jLabel1 = new JLabel();
    jLabel2 = new JLabel();
    jButton1 = new JButton();
    jButton2 = new JButton();
    userNameText = new JTextField();
    passwordText = new JTextField();
    setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    setTitle("用户注册");
    setResizable(false);
    jLabel1.setText("账号:");
    jLabel2.setText("密码:");
    jButton1.setText("注册");
    jButton1.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jButton1ActionPerformed(evt);
      }
    });
    jButton2.setText("重置");
    jButton2.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jButton2ActionPerformed(evt);
      }
    });
    GroupLayout layout = new GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout
        .createSequentialGroup().addGap(60, 60, 60)
        .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup().addComponent(jButton1).addGap(77, 77, 77)
                .addComponent(jButton2))
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1).addComponent(jLabel2))
                .addGap(37, 37, 37)
                .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING, false)
                    .addComponent(passwordText).addComponent(userNameText,
                        GroupLayout.DEFAULT_SIZE, 144, Short.MAX_VALUE))))
        .addContainerGap(123, Short.MAX_VALUE)));
    layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout
        .createSequentialGroup().addGap(49, 49, 49)
        .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(jLabel1)
            .addComponent(userNameText, GroupLayout.PREFERRED_SIZE,
                GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
        .addGap(48, 48, 48)
        .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(jLabel2)
            .addComponent(passwordText, GroupLayout.PREFERRED_SIZE,
                GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 68, Short.MAX_VALUE)
        .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(jButton1)
            .addComponent(jButton2))
        .addGap(64, 64, 64)));
    pack();
  }
  private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
    String userName = this.userNameText.getText();
    String password = this.passwordText.getText();
    if (StringUtil.isEmpty(userName) || StringUtil.isEmpty(password)) {
      JOptionPane.showMessageDialog(null, "请输入相关信息");
      return;
    }
    User user = new User();
    user.setUserName(userName);
    user.setPassword(password);
    user.setRole(1);
    Connection con = null;
    try {
      con = dbUtil.getCon();
      int i = userDao.addUser(con, user);
      if (i == 2) {
        JOptionPane.showMessageDialog(null, "该用户名已存在,请重新注册");
      } else if (i == 0) {
        JOptionPane.showMessageDialog(null, "注册失败");
      } else {
        JOptionPane.showMessageDialog(null, "注册成功");
        this.dispose();
        new LoginFrm().setVisible(true);
      }
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      try {
        dbUtil.closeCon(con);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
  private void reset() {
    this.userNameText.setText("");
    this.passwordText.setText("");
  }
  private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
    reset();
  }
  public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
      public void run() {
        new RegisterFrm().setVisible(true);
      }
    });
  }
}

UserBorrowDetail.java

package com.sjsq.view;
import java.sql.Connection;
import java.sql.ResultSet;
import java.util.Vector;
import javax.swing.GroupLayout;
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.LayoutStyle;
import javax.swing.table.DefaultTableModel;
import com.sjsq.dao.BorrowDetailDao;
import com.sjsq.model.BorrowDetail;
import com.sjsq.util.DbUtil;
import com.sjsq.util.StringUtil;
import com.sjsq.util.TimeUtil;
public class UserBorrowDetail extends JInternalFrame {
  private JTextField borrowIdText;
  private JTable borrowTbale;
  private JButton jB_return;
  private JLabel jLabel1;
  private JScrollPane jScrollPane1;
  DbUtil dbUtil = new DbUtil();
  BorrowDetailDao borrowDetailDao = new BorrowDetailDao();
  public UserBorrowDetail() {
    initComponents();
    fillTable(new BorrowDetail());
    this.jB_return.setVisible(false);
    setTitle("借还信息");
    this.setLocation(200, 50);
  }
  private void fillTable(BorrowDetail borrowDetail) {
    DefaultTableModel model = (DefaultTableModel) borrowTbale.getModel();
    model.setRowCount(0);
    Integer userId = LoginFrm.currentUser.getUserId();
    Connection con = null;
    try {
      con = dbUtil.getCon();
      borrowDetail.setUserId(userId);
      ResultSet list = borrowDetailDao.list(con, borrowDetail);
      while (list.next()) {
        Vector rowData = new Vector();
        rowData.add(list.getInt("id"));
        rowData.add(list.getString("book_name"));
        int status = list.getInt("status");
        if (status == 1) {
          rowData.add("在借");
        }
        if (status == 2) {
          rowData.add("已还");
        }
        rowData.add(TimeUtil.getDateByTime(list.getLong("borrow_time")));
        if (status == 2) {
          rowData.add(TimeUtil.getDateByTime(list.getLong("return_time")));
        }
        model.addRow(rowData);
      }
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      try {
        dbUtil.closeCon(con);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
  private void initComponents() {
    jScrollPane1 = new JScrollPane();
    borrowTbale = new JTable();
    jLabel1 = new JLabel();
    borrowIdText = new JTextField();
    jB_return = new JButton();
    setClosable(true);
    borrowTbale.setModel(new DefaultTableModel(new Object[][] {
    }, new String[] { "编号", "书名", "状态", "借书时间", "还书时间" }) {
      boolean[] canEdit = new boolean[] { false, false, false, false, false };
      public boolean isCellEditable(int rowIndex, int columnIndex) {
        return canEdit[columnIndex];
      }
    });
    borrowTbale.addMouseListener(new java.awt.event.MouseAdapter() {
      public void mousePressed(java.awt.event.MouseEvent evt) {
        borrowTbaleMousePressed(evt);
      }
    });
    jScrollPane1.setViewportView(borrowTbale);
    jLabel1.setText("编号:");
    borrowIdText.setEditable(false);
    jB_return.setText("还书");
    jB_return.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jB_returnActionPerformed(evt);
      }
    });
    GroupLayout layout = new GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup().addGap(35, 35, 35).addComponent(jLabel1).addGap(38, 38, 38)
            .addComponent(borrowIdText, GroupLayout.PREFERRED_SIZE, 114,
                GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 282, Short.MAX_VALUE)
            .addComponent(jB_return).addGap(44, 44, 44))
        .addGroup(layout.createSequentialGroup().addContainerGap()
            .addComponent(jScrollPane1, GroupLayout.DEFAULT_SIZE, 700, Short.MAX_VALUE)
            .addContainerGap()));
    layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout
        .createSequentialGroup()
        .addComponent(jScrollPane1, GroupLayout.PREFERRED_SIZE, 239,
            GroupLayout.PREFERRED_SIZE)
        .addGap(18, 18, 18)
        .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(jLabel1)
            .addComponent(borrowIdText, GroupLayout.PREFERRED_SIZE,
                GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
            .addComponent(jB_return))
        .addContainerGap(26, Short.MAX_VALUE)));
    pack();
  }
  private void jB_returnActionPerformed(java.awt.event.ActionEvent evt) {
    String BorrowStr = this.borrowIdText.getText();
    if (StringUtil.isEmpty(BorrowStr)) {
      JOptionPane.showMessageDialog(null, "请选择未还的书籍");
      return;
    }
    BorrowDetail detail = new BorrowDetail();
    detail.setBorrowId(Integer.parseInt(BorrowStr));
    detail.setStatus(2);
    detail.setReturnTime(TimeUtil.getTime());
    Connection con = null;
    try {
      con = dbUtil.getCon();
      int i = borrowDetailDao.returnBook(con, detail);
      if (i == 1) {
        JOptionPane.showMessageDialog(null, "还书成功");
      } else {
        JOptionPane.showMessageDialog(null, "还书失败");
      }
    } catch (Exception e) {
      e.printStackTrace();
      JOptionPane.showMessageDialog(null, "还书异常");
    } finally {
      try {
        dbUtil.closeCon(con);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
    fillTable(new BorrowDetail());
  }
  private void borrowTbaleMousePressed(java.awt.event.MouseEvent evt) {
    int row = borrowTbale.getSelectedRow();
    Integer borrowId = (Integer) borrowTbale.getValueAt(row, 0);
    String status = (String) borrowTbale.getValueAt(row, 2);
    this.borrowIdText.setText(borrowId.toString());
    if (status.equals("在借")) {
      this.jB_return.setVisible(true);
    } else {
      this.jB_return.setVisible(false);
    }
  }
}

UserInfoFrm.java

package com.sjsq.view;
import java.sql.Connection;
import java.sql.ResultSet;
import java.util.Vector;
import javax.swing.BorderFactory;
import javax.swing.GroupLayout;
import javax.swing.JButton;
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;
import javax.swing.table.DefaultTableModel;
import com.sjsq.dao.UserDao;
import com.sjsq.model.User;
import com.sjsq.util.DbUtil;
import com.sjsq.util.StringUtil;
public class UserInfoFrm extends JInternalFrame {
  private JButton jButton1;
  private JButton jButton2;
  private JLabel jLabel1;
  private JLabel jLabel2;
  private JLabel jLabel3;
  private JLabel jLabel4;
  private JLabel jLabel5;
  private JPanel jPanel1;
  private JPanel jPanel2;
  private JScrollPane jScrollPane1;
  private JTextField passwordText;
  private JTextField userIdText;
  private JTextField userNameText;
  private JTextField userNaneSelectText;
  private JTable userTable;
  DbUtil dbUtil = new DbUtil();
  UserDao userDao = new UserDao();
  public UserInfoFrm() {
    initComponents();
    fillTable(new User());
    setTitle("用户信息");
    this.setLocation(200, 50);
  }
  private void fillTable(User user) {
    DefaultTableModel model = (DefaultTableModel) userTable.getModel();
    model.setRowCount(0);
    Connection con = null;
    try {
      con = dbUtil.getCon();
      ResultSet list = userDao.list(con, user);
      while (list.next()) {
        Vector rowData = new Vector();
        rowData.add(list.getInt("id"));
        rowData.add(list.getString("username"));
        rowData.add(list.getString("password"));
        model.addRow(rowData);
      }
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      try {
        dbUtil.closeCon(con);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
  private void initComponents() {
    jLabel2 = new JLabel();
    jScrollPane1 = new JScrollPane();
    userTable = new JTable();
    jPanel1 = new JPanel();
    jLabel1 = new JLabel();
    jButton1 = new JButton();
    userNaneSelectText = new JTextField();
    jPanel2 = new JPanel();
    jLabel3 = new JLabel();
    userIdText = new JTextField();
    jLabel4 = new JLabel();
    userNameText = new JTextField();
    jLabel5 = new JLabel();
    passwordText = new JTextField();
    jButton2 = new JButton();
    jLabel2.setText("jLabel2");
    setClosable(true);
    userTable.setModel(new DefaultTableModel(new Object[][] {
    }, new String[] { "编号", "账号", "密码" }) {
      boolean[] canEdit = new boolean[] { false, false, false };
      public boolean isCellEditable(int rowIndex, int columnIndex) {
        return canEdit[columnIndex];
      }
    });
    userTable.addMouseListener(new java.awt.event.MouseAdapter() {
      public void mousePressed(java.awt.event.MouseEvent evt) {
        userTableMousePressed(evt);
      }
    });
    jScrollPane1.setViewportView(userTable);
    jPanel1.setBorder(BorderFactory.createTitledBorder("表单操作"));
    jLabel1.setText("账号:");
    jButton1.setText("查询");
    jButton1.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jButton1ActionPerformed(evt);
      }
    });
    GroupLayout jPanel1Layout = new GroupLayout(jPanel1);
    jPanel1.setLayout(jPanel1Layout);
    jPanel1Layout.setHorizontalGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.LEADING)
        .addGroup(jPanel1Layout.createSequentialGroup().addContainerGap().addComponent(jLabel1)
            .addGap(18, 18, 18)
            .addComponent(userNaneSelectText, GroupLayout.DEFAULT_SIZE, 184, Short.MAX_VALUE)
            .addGap(18, 18, 18).addComponent(jButton1).addContainerGap()));
    jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.LEADING)
        .addGroup(jPanel1Layout.createSequentialGroup().addGroup(jPanel1Layout
            .createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel1).addComponent(userNaneSelectText,
                    GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                    GroupLayout.PREFERRED_SIZE))
            .addComponent(jButton1))
            .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
    jPanel2.setBorder(BorderFactory.createTitledBorder("用户操作"));
    jLabel3.setText("编号:");
    userIdText.setEditable(false);
    jLabel4.setText("账号:");
    jLabel5.setText("密码:");
    jButton2.setText("修改");
    jButton2.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jButton2ActionPerformed(evt);
      }
    });
    GroupLayout jPanel2Layout = new GroupLayout(jPanel2);
    jPanel2.setLayout(jPanel2Layout);
    jPanel2Layout.setHorizontalGroup(jPanel2Layout.createParallelGroup(GroupLayout.Alignment.LEADING)
        .addGroup(jPanel2Layout.createSequentialGroup().addContainerGap()
            .addGroup(jPanel2Layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup().addComponent(jLabel3)
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(userIdText, GroupLayout.PREFERRED_SIZE, 85,
                        GroupLayout.PREFERRED_SIZE)
                    .addGap(18, 18, 18).addComponent(jLabel4))
                .addGroup(jPanel2Layout.createSequentialGroup().addComponent(jLabel5)
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(passwordText, GroupLayout.PREFERRED_SIZE, 88,
                        GroupLayout.PREFERRED_SIZE)))
            .addGroup(jPanel2Layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup().addGap(37, 37, 37).addComponent(
                    userNameText, GroupLayout.PREFERRED_SIZE, 94,
                    GroupLayout.PREFERRED_SIZE))
                .addGroup(jPanel2Layout.createSequentialGroup().addGap(8, 8, 8).addComponent(jButton2)))
            .addContainerGap(26, Short.MAX_VALUE)));
    jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(GroupLayout.Alignment.LEADING)
        .addGroup(jPanel2Layout.createSequentialGroup()
            .addGroup(jPanel2Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel3).addComponent(jLabel4)
                .addComponent(userIdText, GroupLayout.PREFERRED_SIZE,
                    GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                .addComponent(userNameText, GroupLayout.PREFERRED_SIZE,
                    GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
            .addGap(29, 29, 29)
            .addGroup(jPanel2Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel5)
                .addComponent(passwordText, GroupLayout.PREFERRED_SIZE,
                    GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                .addComponent(jButton2))
            .addContainerGap(37, Short.MAX_VALUE)));
    GroupLayout layout = new GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout
        .createSequentialGroup().addGap(24, 24, 24)
        .addGroup(layout.createParallelGroup(GroupLayout.Alignment.TRAILING)
            .addComponent(jPanel2, GroupLayout.Alignment.LEADING,
                GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE,
                Short.MAX_VALUE)
            .addComponent(jScrollPane1, GroupLayout.Alignment.LEADING, 0, 0, Short.MAX_VALUE)
            .addComponent(jPanel1, GroupLayout.Alignment.LEADING,
                GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE,
                Short.MAX_VALUE))
        .addGap(226, 226, 226)));
    layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addComponent(jPanel1, GroupLayout.PREFERRED_SIZE,
                GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
            .addGap(28, 28, 28)
            .addComponent(jScrollPane1, GroupLayout.PREFERRED_SIZE, 136,
                GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
            .addComponent(jPanel2, GroupLayout.PREFERRED_SIZE,
                GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
            .addContainerGap(16, Short.MAX_VALUE)));
    pack();
  }
  private void userTableMousePressed(java.awt.event.MouseEvent evt) {
    int row = this.userTable.getSelectedRow();
    this.userIdText.setText(userTable.getValueAt(row, 0).toString());
    this.userNameText.setText(userTable.getValueAt(row, 1).toString());
    this.passwordText.setText(userTable.getValueAt(row, 2).toString());
  }
  private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
    String userId = this.userIdText.getText();
    String userName = this.userNameText.getText();
    String password = this.passwordText.getText();
    if (StringUtil.isEmpty(userName) || StringUtil.isEmpty(password)) {
      JOptionPane.showMessageDialog(null, "请输入相关信息");
      return;
    }
    User user = new User();
    user.setUserId(Integer.parseInt(userId));
    user.setUserName(userName);
    user.setPassword(password);
    Connection con = null;
    try {
      con = dbUtil.getCon();
      int i = userDao.update(con, user);
      if (i == 1) {
        JOptionPane.showMessageDialog(null, "修改成功");
        fillTable(new User());
      } else {
        JOptionPane.showMessageDialog(null, "修改失败");
      }
    } catch (Exception e) {
      e.printStackTrace();
      JOptionPane.showMessageDialog(null, "修改异常");
    } finally {
      try {
        dbUtil.closeCon(con);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
  private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
    String userName = this.userNaneSelectText.getText();
    User user = new User();
    user.setUserName(userName);
    fillTable(user);
  }
}

UserMainFrm.java

package com.sjsq.view;
import javax.swing.GroupLayout;
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.WindowConstants;
public class UserMainFrm extends JFrame {
  private JMenu jMenu1;
  private JMenuBar jMenuBar1;
  private JMenuItem jMenuItem1;
  private JMenuItem jMenuItem2;
  private JMenuItem jMenuItem3;
  private JDesktopPane userMainjdp;
  public UserMainFrm() {
    initComponents();
    // 设置位置
    setBounds(100, 200, 1050, 650);
    // 居中显示
    this.setLocationRelativeTo(null);
  }
  private void initComponents() {
    userMainjdp = new JDesktopPane();
    jMenuBar1 = new JMenuBar();
    jMenu1 = new JMenu();
    jMenuItem1 = new JMenuItem();
    jMenuItem2 = new JMenuItem();
    jMenuItem3 = new JMenuItem();
    setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    setTitle("图书者主界面");
    jMenu1.setText("基本信息");
    jMenuItem1.setText("书籍信息");
    jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jMenuItem1ActionPerformed(evt);
      }
    });
    jMenu1.add(jMenuItem1);
    jMenuItem2.setText("借书记录");
    jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jMenuItem2ActionPerformed(evt);
      }
    });
    jMenu1.add(jMenuItem2);
    jMenuItem3.setText("退出系统");
    jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jMenuItem3ActionPerformed(evt);
      }
    });
    jMenu1.add(jMenuItem3);
    jMenuBar1.add(jMenu1);
    setJMenuBar(jMenuBar1);
    GroupLayout layout = new GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(userMainjdp,
        GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE));
    layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(userMainjdp,
        GroupLayout.DEFAULT_SIZE, 279, Short.MAX_VALUE));
    pack();
  }
  private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {
    int i = JOptionPane.showConfirmDialog(null, "确认退出系统");
    if (i == 0) {
      this.dispose();
    }
  }
  private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {
    UserBorrowDetail userBorrowDetail = new UserBorrowDetail();
    userBorrowDetail.setVisible(true);
    this.userMainjdp.add(userBorrowDetail);
  }
  private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {
    BookInfoFrm infoFrm = new BookInfoFrm();
    infoFrm.setVisible(true);
    this.userMainjdp.add(infoFrm);
  }
  public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
      public void run() {
        new UserMainFrm().setVisible(true);
      }
    });
  }
}

UserManagerFrm.java

package com.sjsq.view;
import javax.swing.GroupLayout;
import javax.swing.JInternalFrame;
public class UserManagerFrm extends JInternalFrame {
  public UserManagerFrm() {
    initComponents();
  }
  private void initComponents() {
    setClosable(true);
    GroupLayout layout = new GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGap(0, 394, Short.MAX_VALUE));
    layout.setVerticalGroup(
        layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGap(0, 278, Short.MAX_VALUE));
    pack();
  }
}


四、其他


1.其他系统实现


JavaWeb系统系列实现

Java+JSP实现学生图书管理系统

Java+JSP实现学生信息管理系统

Java+JSP实现用户信息管理系统

Java+Servlet+JSP实现航空订票系统

Java+Servlet+JSP实现房屋租赁管理系统

Java+Servlet+JSP实现学生选课管理系统

Java+Servlet+JSP实现学生成绩管理系统

Java+Servlet+JSP实现宠物诊所管理系统

Java+SSM+Easyui实现网上考试系统

Java+Springboot+H-ui实现营销管理系统

Java+Springboot+Mybatis+Bootstrap实现网上商城系统


JavaSwing系统系列实现

Java+Swing实现斗地主游戏

Java+Swing实现图书管理系统

Java+Swing实现医院管理系统

Java+Swing实现仓库管理系统

Java+Swing实现考试管理系统

Java+Swing实现通讯录管理系统

Java+Swing实现停车场管理系统

Java+Swing实现学生信息管理系统

Java+Swing实现学生宿舍管理系统

Java+Swing实现学生选课管理系统

Java+Swing实现学生成绩管理系统

Java+Swing实现学校教材管理系统

Java+Swing实现学校教务管理系统

Java+Swing实现企业人事管理系统

Java+Swing实现电子相册管理系统

Java+Swing实现自助取款机(ATM)系统

Java+Swing实现超市管理系统-TXT存储信息

Java+Swing实现宠物商店管理系统-TXT存储信息


相关文章
|
1月前
|
存储 Java 关系型数据库
农产品管理系统【GUI/Swing+MySQL】(Java课设)
农产品管理系统【GUI/Swing+MySQL】(Java课设)
18 1
|
1月前
|
存储 Java 关系型数据库
个人成绩信息管理系统【GUI/Swing+MySQL】(Java课设)
个人成绩信息管理系统【GUI/Swing+MySQL】(Java课设)
20 0
|
1月前
|
存储 Java 关系型数据库
酒店管理系统【GUI/Swing+MySQL】(Java课设)
酒店管理系统【GUI/Swing+MySQL】(Java课设)
22 1
|
1月前
|
存储 Java 关系型数据库
社区医院管理服务系统【GUI/Swing+MySQL】(Java课设)
社区医院管理服务系统【GUI/Swing+MySQL】(Java课设)
25 1
|
1月前
|
存储 Java 关系型数据库
仓库管理系统【GUI/Swing+MySQL】(Java课设)
仓库管理系统【GUI/Swing+MySQL】(Java课设)
19 0
|
1月前
|
存储 Java 关系型数据库
游乐场管理系统【GUI/Swing+MySQL】(Java课设)
游乐场管理系统【GUI/Swing+MySQL】(Java课设)
17 0
|
1月前
|
存储 Java 关系型数据库
影碟出租管理系统【GUI/Swing+MySQL】(Java课设)
影碟出租管理系统【GUI/Swing+MySQL】(Java课设)
17 0
|
1月前
|
存储 Java 关系型数据库
实验室设备管理系统【GUI/Swing+MySQL】(Java课设)
实验室设备管理系统【GUI/Swing+MySQL】(Java课设)
19 0
|
1月前
|
存储 Java 关系型数据库
请销假管理系统【GUI/Swing+MySQL】(Java课设)
请销假管理系统【GUI/Swing+MySQL】(Java课设)
15 0
|
1月前
|
存储 Java 关系型数据库
某电力公司收费管理系统【GUI/Swing+MySQL】(Java课设)
某电力公司收费管理系统【GUI/Swing+MySQL】(Java课设)
16 0

推荐镜像

更多