11.25
C/S结构用户界面设计
【实验编号】
10003809547j 图形用户界面设计
【实验学时】
8学时
【实验环境】
l 所需硬件环境为微机;
l 所需软件环境为Microsoft Visual Studio 2013
【实验内容】
- 登录代码
package cn.itcast.bookmanager.jframe;
import cn.itcast.bookmanager.dao.UserDao;
import cn.itcast.bookmanager.model.User;
import cn.itcast.bookmanager.util.JdbcUtils;
import cn.itcast.bookmanager.util.ToolUtils;
import org.jb2011.lnf.beautyeye.BeautyEyeLNFHelper;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
public class LoginFrame extends JFrame {
public static User currentUser;
private JFrame jf;
private JTextField userNameText;
private JTextField passwordText;
private JComboBox<String> comboBox;
UserDao userDao = new UserDao();
JdbcUtils dbUtil = new JdbcUtils();
public LoginFrame(){
jf=new JFrame("图书管理");
jf.getContentPane().setFont(new Font("幼圆", Font.BOLD, 14));
jf.setBounds(600, 250, 500, 467);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.getContentPane().setLayout(null);
JLabel lblNewLabel = new JLabel(new ImageIcon(LoginFrame.class.getResource("/tupian/bg2.png")));
lblNewLabel.setBounds(24, 10, 430, 218);
jf.getContentPane().add(lblNewLabel);
JLabel label = new JLabel("用户名:");
label.setFont(new Font("幼圆", Font.BOLD, 14));
label.setBounds(129, 250, 60, 29);
jf.getContentPane().add(label);
userNameText = new JTextField();
userNameText.setBounds(199, 252, 127, 25);
jf.getContentPane().add(userNameText);
userNameText.setColumns(10);
JLabel label_1 = new JLabel("密码:");
label_1.setFont(new Font("幼圆", Font.BOLD, 14));
label_1.setBounds(144, 289, 45, 29);
jf.getContentPane().add(label_1);
passwordText = new JPasswordField();
passwordText.setColumns(10);
passwordText.setBounds(199, 291, 127, 25);
jf.getContentPane().add(passwordText);
JButton button = new JButton("登录");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
checkLogin(e);
}
});
button.setBounds(153, 377, 65, 29);
jf.getContentPane().add(button);
JButton button_1 = new JButton("注册");
button_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
regUser(e);
}
});
button_1.setBounds(263, 377, 65, 29);
jf.getContentPane().add(button_1);
JLabel lblNewLabel_1 = new JLabel("");
lblNewLabel_1.setIcon(new ImageIcon(LoginFrame.class.getResource("/tupian/adBG3.png")));
lblNewLabel_1.setBounds(0, 0, 484, 429);
jf.getContentPane().add(lblNewLabel_1);
jf.setVisible(true);
jf.setResizable(true);
}
protected void regUser(ActionEvent e) {
jf.setVisible(false);
new RegFrame();
}
protected void checkLogin(ActionEvent e) {
String userName = userNameText.getText();
String password = passwordText.getText();
int index = 1; //缺省设置为普通用户
if (ToolUtils.isEmpty(userName) || ToolUtils.isEmpty(password)) {
JOptionPane.showMessageDialog(null, "用户名和密码不能为空");
return;
}
User user = new User();
user.setUserName(userName);
user.setPassword(password);
//System.out.println(user);
Connection con = null;
try {
con = dbUtil.getConnection();
User loginUser = userDao.login(con, user);
System.out.println("login :"+loginUser);
currentUser = loginUser;
if (loginUser == null) {
JOptionPane.showMessageDialog(null, "登录失败");
} else {
jf.dispose();
new UserFrame();
}
} catch (Exception e21) {
e21.printStackTrace();
JOptionPane.showMessageDialog(null, "登录异常");
} finally {
try {
dbUtil.closeCon(con);
} catch (Exception e31) {
e31.printStackTrace();
}
}
}
public static void main(String[] args) {
try {
BeautyEyeLNFHelper.frameBorderStyle = BeautyEyeLNFHelper.FrameBorderStyle.generalNoTranslucencyShadow;
org.jb2011.lnf.beautyeye.BeautyEyeLNFHelper.launchBeautyEyeLNF();
} catch (Exception e) {
e.printStackTrace();
}
new LoginFrame();
}
}
- 主界面
package cn.itcast.bookmanager.jframe;
import cn.itcast.bookmanager.dao.UserDao;
import cn.itcast.bookmanager.model.User;
import cn.itcast.bookmanager.util.JdbcUtils;
import cn.itcast.bookmanager.util.ToolUtils;
import org.jb2011.lnf.beautyeye.BeautyEyeLNFHelper;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.sql.Connection;
public class RegFrame extends JFrame {
private JFrame jf;
private JTextField textField;
private JTextField textField_1;
private JLabel label_2;
private JTextField textField_2;
private JLabel label_3;
private JRadioButton rdbtnNewRadioButton_1;
private JLabel usernameMes;
private JLabel passwordMes;
private JLabel phoneMes;
private JLabel label_4;
private JTextField textField_3;
private JButton button;
private JButton button_1;
private JRadioButton rdbtnNewRadioButton;
JdbcUtils dbUtil=new JdbcUtils();
UserDao userDao=new UserDao();
private JLabel lblNewLabel;
private JLabel lblNewLabel_1;
public RegFrame() {
jf=new JFrame("用户注册");
jf.getContentPane().setFont(new Font("幼圆", Font.BOLD, 16));
jf.setBounds(600, 250,510, 410);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.getContentPane().setLayout(null);
JLabel label = new JLabel("用户名:");
label.setForeground(Color.BLACK);
label.setFont(new Font("幼圆", Font.BOLD, 16));
label.setBounds(110, 65, 75, 40);
jf.getContentPane().add(label);
textField = new JTextField();
textField.setFont(new Font("幼圆", Font.BOLD, 14));
textField.setForeground(Color.BLACK);
textField.setColumns(10);
textField.setBounds(198, 71, 164, 30);
jf.getContentPane().add(textField);
textField.addFocusListener(new FocusListener() {
@Override
public void focusGained(FocusEvent e) {
}
@Override
public void focusLost(FocusEvent e) {
String text = textField.getText();
if(ToolUtils.isEmpty(text)){
usernameMes.setText("用户名不能为空");
usernameMes.setForeground(Color.RED);
}else{
usernameMes.setText("√");
usernameMes.setForeground(Color.GREEN);
}
}
});
JLabel label_1 = new JLabel("密码:");
label_1.setForeground(Color.BLACK);
label_1.setFont(new Font("幼圆", Font.BOLD, 16));
label_1.setBounds(120, 108, 65, 40);
jf.getContentPane().add(label_1);
textField_1 = new JTextField();
textField_1.setFont(new Font("Dialog", Font.BOLD, 14));
textField_1.setToolTipText("");
textField_1.setColumns(10);
textField_1.setBounds(198, 114, 164, 30);
jf.getContentPane().add(textField_1);
textField_1.addFocusListener(new FocusListener() {
@Override
public void focusLost(FocusEvent e) {
String pwd=textField_1.getText();
if(ToolUtils.isEmpty(pwd)){
passwordMes.setText("密码不能为空");
passwordMes.setForeground(Color.RED);
}else{
boolean flag=pwd.matches("^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$");
if(flag){
passwordMes.setText("√");
passwordMes.setForeground(Color.GREEN);
}else{
JOptionPane.showMessageDialog(null, "密码需为6-16位数字和字母的组合");
passwordMes.setText("");
}
}
}
@Override
public void focusGained(FocusEvent e) {
}
});
label_2 = new JLabel("手机号:");
label_2.setForeground(Color.BLACK);
label_2.setFont(new Font("幼圆", Font.BOLD, 16));
label_2.setBounds(110, 150, 75, 40);
jf.getContentPane().add(label_2);
textField_2 = new JTextField();
textField_2.setFont(new Font("Dialog", Font.BOLD, 14));
textField_2.setColumns(10);
textField_2.setBounds(198, 156, 164, 30);
jf.getContentPane().add(textField_2);
textField_2.addFocusListener(new FocusListener() {
@Override
public void focusLost(FocusEvent e) {
String phone=textField_2.getText();
if(ToolUtils.isEmpty(phone)){
phoneMes.setText("手机号不能为空");
phoneMes.setForeground(Color.RED);
}else{
boolean flag=phone.matches("^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(18[0,5-9]))\\d{8}$");
if(flag){
phoneMes.setText("√");
phoneMes.setForeground(Color.GREEN);
}else{
JOptionPane.showMessageDialog(null, "请输入正确的手机号格式");
phoneMes.setText("");
}
}
}
@Override
public void focusGained(FocusEvent e) {
}
});
label_3 = new JLabel("性别:");
label_3.setForeground(Color.BLACK);
label_3.setFont(new Font("幼圆", Font.BOLD, 16));
label_3.setBounds(123, 184, 65, 40);
jf.getContentPane().add(label_3);
rdbtnNewRadioButton = new JRadioButton("男");
rdbtnNewRadioButton.setFont(new Font("幼圆", Font.BOLD, 16));
rdbtnNewRadioButton.setBounds(198, 192, 58, 23);
jf.getContentPane().add(rdbtnNewRadioButton);
rdbtnNewRadioButton_1 = new JRadioButton("女");
rdbtnNewRadioButton_1.setFont(new Font("幼圆", Font.BOLD, 16));
rdbtnNewRadioButton_1.setBounds(287, 192, 65, 23);
jf.getContentPane().add(rdbtnNewRadioButton_1);
ButtonGroup bg=new ButtonGroup();
bg.add(rdbtnNewRadioButton_1);
bg.add(rdbtnNewRadioButton);
usernameMes = new JLabel("");
usernameMes.setFont(new Font("Dialog", Font.BOLD, 15));
usernameMes.setBounds(372, 57, 122, 27);
jf.getContentPane().add(usernameMes);
passwordMes = new JLabel("");
passwordMes.setFont(new Font("Dialog", Font.BOLD, 15));
passwordMes.setBounds(372, 100, 122, 27);
jf.getContentPane().add(passwordMes);
phoneMes = new JLabel("");
phoneMes.setFont(new Font("Dialog", Font.BOLD, 15));
phoneMes.setBounds(372, 142, 122, 30);
jf.getContentPane().add(phoneMes);
button = new JButton("注册");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
RegCheck(e);
}
});
button.setFont(new Font("幼圆", Font.BOLD, 15));
button.setBounds(120, 299, 75, 30);
jf.getContentPane().add(button);
button_1 = new JButton("前往登录页面");
button_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jf.setVisible(false);
new LoginFrame();
}
});
button_1.setFont(new Font("幼圆", Font.BOLD, 15));
button_1.setBounds(245, 299, 132, 30);
jf.getContentPane().add(button_1);
lblNewLabel_1 = new JLabel("用户注册");
lblNewLabel_1.setFont(new Font("Dialog", Font.BOLD, 22));
lblNewLabel_1.setBounds(184, 10, 122, 51);
jf.getContentPane().add(lblNewLabel_1);
lblNewLabel = new JLabel("");
lblNewLabel.setForeground(Color.BLACK);
lblNewLabel.setIcon(new ImageIcon(RegFrame.class.getResource("/tupian/regBG.png")));
lblNewLabel.setBounds(0, 0, 494, 372);
jf.getContentPane().add(lblNewLabel);
jf.setVisible(true);
jf.setResizable(true);
}
protected void RegCheck(ActionEvent e) {
String username=textField.getText();
String password=textField_1.getText();
String phone=textField_2.getText();
String sex="";
if(rdbtnNewRadioButton.isSelected()){
sex=rdbtnNewRadioButton.getText();
}else{
sex=rdbtnNewRadioButton_1.getText();
}
if (ToolUtils.isEmpty(username) || ToolUtils.isEmpty(password)|| ToolUtils.isEmpty(phone)) {
JOptionPane.showMessageDialog(null, "请输入相关信息");
return;
}
User user = new User();
user.setUserName(username);
user.setPassword(password);
user.setSex(sex);
user.setPhone(phone);
user.setRole(1);
Connection con = null;
try {
con = dbUtil.getConnection();
int i = userDao.addUser(con, user);
if (i == 2) {
JOptionPane.showMessageDialog(null, "该用户名已存在,请重新注册");
} else if (i == 0) {
JOptionPane.showMessageDialog(null, "注册失败");
} else {
JOptionPane.showMessageDialog(null, "注册成功");
jf.dispose();
new LoginFrame();
}
} catch (Exception e1) {
e1.printStackTrace();
} finally {
try {
dbUtil.closeCon(con);
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
public static void main(String[] args) {
try {
BeautyEyeLNFHelper.frameBorderStyle = BeautyEyeLNFHelper.FrameBorderStyle.generalNoTranslucencyShadow;
org.jb2011.lnf.beautyeye.BeautyEyeLNFHelper.launchBeautyEyeLNF();
} catch (Exception e) {
e.printStackTrace();
}
new RegFrame();
}
}
- 角色相关操作
package cn.itcast.bookmanager.jframe;
import cn.itcast.bookmanager.dao.BookDao;
import cn.itcast.bookmanager.dao.BorrowDetailDao;
import cn.itcast.bookmanager.dao.impl.BookDaoMySQLImpl;
import cn.itcast.bookmanager.dao.impl.BorrowDetailMySQLDaoImpl;
import cn.itcast.bookmanager.model.Book;
import cn.itcast.bookmanager.model.BorrowDetail;
import cn.itcast.bookmanager.util.JdbcUtils;
import cn.itcast.bookmanager.util.ToolUtils;
import org.jb2011.lnf.beautyeye.BeautyEyeLNFHelper;
import javax.swing.*;
import javax.swing.border.TitledBorder;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.sql.Connection;
import java.sql.ResultSet;
import java.util.Vector;
public class UserFrame extends JFrame {
private JFrame jf;
private JTextField textField;
private JTable table;
private DefaultTableModel model;
private JTable BookTable;
private DefaultTableModel BookModel;
private JButton btnBackBook;
JdbcUtils dbUtil=new JdbcUtils();
BorrowDetailDao bdetailDao=new BorrowDetailMySQLDaoImpl();
BookDao bookDao=new BookDaoMySQLImpl();
private JLabel lblNewLabel_1;
private JLabel lblNewLabel_2;
private JButton button;
private JPanel panel_2;
private JTextField textField_1;
private JButton button_1;
private JComboBox comboBox;
private JTextField textField_2;
private JTextField textField_3;
private JLabel lblNewLabel_3;
public UserFrame() {
jf=new JFrame();
jf.setTitle("用户页面");
jf.setBounds(250,100,700,902);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.getContentPane().setLayout(null);
JPanel panel_1 = new JPanel();
panel_1.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "\u501F\u9605\u4FE1\u606F", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(255, 0, 0)));
panel_1.setBounds(23, 48, 651, 239);
/*做一个表头栏数据 一位数组
* */
String[] title={"编号", "书名", "状态", "借书时间", "还书时间"};
/*具体的各栏行记录 先用空的二位数组占位*/
String[][] dates={};
/*然后实例化 上面2个控件对象*/
model=new DefaultTableModel(dates,title);
table=new JTable();
table.setModel(model);
putDates(new BorrowDetail());//获取数据库数据放置table中
panel_1.setLayout(null);
JScrollPane jscrollpane = new JScrollPane();
jscrollpane.setBounds(20, 22, 607, 188);
jscrollpane.setViewportView(table);
panel_1.add(jscrollpane);
jf.getContentPane().add(panel_1);
lblNewLabel_1 = new JLabel("New label");
lblNewLabel_1.setForeground(Color.RED);
lblNewLabel_1.setFont(new Font("Dialog", Font.BOLD, 18));
lblNewLabel_1.setBounds(315, 10, 197, 28);
jf.getContentPane().add(lblNewLabel_1);
lblNewLabel_1.setText(LoginFrame.currentUser.getUserName());
lblNewLabel_2 = new JLabel("欢迎您,");
lblNewLabel_2.setFont(new Font("Dialog", Font.BOLD, 18));
lblNewLabel_2.setBounds(254, 11, 258, 28);
jf.getContentPane().add(lblNewLabel_2);
JPanel panel = new JPanel();
panel.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "\u8FD8\u4E66", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(255, 0, 0)));
panel.setBounds(23, 294, 651, 70);
jf.getContentPane().add(panel);
panel.setLayout(null);
JLabel lblNewLabel = new JLabel("编号:");
lblNewLabel.setBounds(90, 25, 51, 27);
panel.add(lblNewLabel);
lblNewLabel.setFont(new Font("幼圆", Font.BOLD, 16));
textField = new JTextField();
textField.setBounds(145, 28, 116, 24);
panel.add(textField);
textField.setColumns(10);
btnBackBook = new JButton("还书");
btnBackBook.setFont(new Font("Dialog", Font.BOLD, 15));
btnBackBook.setBounds(299, 25, 85, 31);
panel.add(btnBackBook);
button = new JButton("退出系统");
button.setFont(new Font("Dialog", Font.BOLD, 15));
button.setBounds(407, 25, 103, 31);
panel.add(button);
panel_2 = new JPanel();
panel_2.setBorder(new TitledBorder(null, "借阅信息", TitledBorder.LEADING, TitledBorder.TOP, null, Color.RED));
panel_2.setBounds(23, 374, 651, 346);
jf.getContentPane().add(panel_2);
panel_2.setLayout(null);
textField_1 = new JTextField();
textField_1.setColumns(10);
textField_1.setBounds(252, 23, 135, 27);
panel_2.add(textField_1);
button_1 = new JButton("查询");
button_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int index = comboBox.getSelectedIndex();
if(index==0){
String bookName = textField_1.getText();
Book book = new Book();
book.setBookName(bookName);
putDates(book);
}else{
String authoerName = textField_1.getText();
Book book = new Book();
book.setAuthor(authoerName);
putDates(book);
}
}
});
button_1.setFont(new Font("幼圆", Font.BOLD, 16));
button_1.setBounds(408, 20, 93, 33);
panel_2.add(button_1);
comboBox = new JComboBox();
comboBox.setFont(new Font("幼圆", Font.BOLD, 15));
comboBox.setBounds(123, 26, 109, 24);
comboBox.addItem("书籍名称");
comboBox.addItem("书籍作者");
panel_2.add(comboBox);
String[] BookTitle={"编号", "书名", "类型", "作者", "描述" };
/*具体的各栏行记录 先用空的二位数组占位*/
String[][] BookDates={};
/*然后实例化 上面2个控件对象*/
BookModel=new DefaultTableModel(BookDates,BookTitle);
BookTable=new JTable(BookModel);
putDates(new Book());//获取数据库数据放置table中
panel_2.setLayout(null);
JScrollPane jscrollpane1 = new JScrollPane();
jscrollpane1.setBounds(22, 74, 607, 250);
jscrollpane1.setViewportView(BookTable);
panel_2.add(jscrollpane1);
jf.getContentPane().add(panel_1);
JPanel panel_3 = new JPanel();
panel_3.setBorder(new TitledBorder(null, "\u501F\u4E66", TitledBorder.LEADING, TitledBorder.TOP, null, Color.RED));
panel_3.setBounds(23, 730, 645, 87);
jf.getContentPane().add(panel_3);
panel_3.setLayout(null);
JLabel label = new JLabel("编号:");
label.setFont(new Font("Dialog", Font.BOLD, 15));
label.setBounds(68, 31, 48, 33);
panel_3.add(label);
textField_2 = new JTextField();
textField_2.setEditable(false);
textField_2.setColumns(10);
textField_2.setBounds(126, 34, 135, 27);
panel_3.add(textField_2);
JLabel label_1 = new JLabel("书名:");
label_1.setFont(new Font("Dialog", Font.BOLD, 15));
label_1.setBounds(281, 31, 48, 33);
panel_3.add(label_1);
textField_3 = new JTextField();
textField_3.setEditable(false);
textField_3.setColumns(10);
textField_3.setBounds(339, 34, 135, 27);
panel_3.add(textField_3);
JButton button_2 = new JButton("借书");
//借书
button_2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String bookId = textField_2.getText();
String bookName = textField_3.getText();
if (ToolUtils.isEmpty(bookId) || ToolUtils.isEmpty(bookName)) {
JOptionPane.showMessageDialog(null, "请选择相关书籍");
return;
}
BorrowDetail borrowDetail = new BorrowDetail();
borrowDetail.setUserId(LoginFrame.currentUser.getUserId());
borrowDetail.setBookId(Integer.parseInt(bookId));
borrowDetail.setStatus(1);
borrowDetail.setBorrowTime(ToolUtils.getTime());
Connection con = null;
try {
con = dbUtil.getConnection();
//先查询是否有该书
ResultSet list = bdetailDao.list(con, borrowDetail);
while(list.next()){
JOptionPane.showMessageDialog(null, "该书已在借,请先还再借");
return;
}
int i = bdetailDao.add(con, borrowDetail);
if (i == 1) {
JOptionPane.showMessageDialog(null, "借书成功");
putDates(new BorrowDetail());
} else {
JOptionPane.showMessageDialog(null, "借书失败");
}
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
JOptionPane.showMessageDialog(null, "借书异常");
}finally{
try {
dbUtil.closeCon(con);
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
});
button_2.setFont(new Font("Dialog", Font.BOLD, 16));
button_2.setBounds(495, 31, 80, 33);
panel_3.add(button_2);
lblNewLabel_3 = new JLabel("");
lblNewLabel_3.setIcon(new ImageIcon(UserFrame.class.getResource("/tupian/uBG.png")));
lblNewLabel_3.setBounds(0, 0, 684, 864);
jf.getContentPane().add(lblNewLabel_3);
BookTable.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent evt) {
tableMousePressed(evt);
}
});
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(null, "欢迎再次使用");
jf.dispose();
}
});
btnBackBook.setVisible(false);
btnBackBook.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String BorrowStr = textField.getText();
if (ToolUtils.isEmpty(BorrowStr)) {
JOptionPane.showMessageDialog(null, "请选择未还的书籍");
return;
}
BorrowDetail detail = new BorrowDetail();
detail.setBorrowId(Integer.parseInt(BorrowStr));
detail.setStatus(2);
detail.setReturnTime(ToolUtils.getTime());
Connection con = null;
try {
con = dbUtil.getConnection();
int i = bdetailDao.returnBook(con, detail);
if (i == 1) {
JOptionPane.showMessageDialog(null, "还书成功");
} else {
JOptionPane.showMessageDialog(null, "还书失败");
}
} catch (Exception e1) {
e1.printStackTrace();
JOptionPane.showMessageDialog(null, "还书异常");
}finally{
try {
dbUtil.closeCon(con);
} catch (Exception e1) {
e1.printStackTrace();
}
}
putDates(new BorrowDetail());
}
});
jf.setVisible(true);
jf.setResizable(true);
}
protected void tableMousePressed(MouseEvent evt) {
int row = BookTable.getSelectedRow();
Object bookId = BookTable.getValueAt(row, 0);
Object bookName = BookTable.getValueAt(row, 1);
textField_2.setText(bookId.toString());
textField_3.setText(bookName.toString());
}
//从数据库获取书籍信息
private void putDates(Book book) {
DefaultTableModel model = (DefaultTableModel) BookTable.getModel();
model.setRowCount(0);
Connection con = null;
try {
con = dbUtil.getConnection();
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) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
try {
dbUtil.closeCon(con);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
private void putDates(BorrowDetail borrowDetail) {
DefaultTableModel model = (DefaultTableModel) table.getModel();
model.setRowCount(0);
Integer userId = LoginFrame.currentUser.getUserId();
Connection con = null;
try {
con = dbUtil.getConnection();
borrowDetail.setUserId(userId);
ResultSet list = bdetailDao.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(ToolUtils.getDateByTime(list.getLong("borrow_time")));
if (status == 2) {
rowData.add(ToolUtils.getDateByTime(list.getLong("return_time")));
}
model.addRow(rowData);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
try {
dbUtil.closeCon(con);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
table.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent me){
putBack(me);
}
});
}
protected void putBack(MouseEvent me){
int row = table.getSelectedRow();
Integer borrowId = (Integer) table.getValueAt(row, 0);
String status = (String) table.getValueAt(row, 2);
textField.setText(borrowId.toString());
if (status.equals("在借")) {
this.btnBackBook.setVisible(true);
} else {
this.btnBackBook.setVisible(false);
}
}
public static void main(String[] args) {
try {
BeautyEyeLNFHelper.frameBorderStyle = BeautyEyeLNFHelper.FrameBorderStyle.generalNoTranslucencyShadow;
org.jb2011.lnf.beautyeye.BeautyEyeLNFHelper.launchBeautyEyeLNF();
} catch (Exception e) {
e.printStackTrace();
}
new UserFrame();
}
}
【关键步骤】
1. 登录界面
用户在此界面输入自己的账号和密码进行身份验证。操作步骤:
输入用户名:在指定文本框中输入您的用户名。
输入密码:在密码框中输入您的登录密码。
点击登录:按下“登录”按钮,系统进行身份验证。
忘记密码:如果忘记密码,可以点击“忘记密码”链接,通过邮箱或手机号重置密码。
2. 主界面
成功登录后,您将进入主界面。主界面通常包括:
欢迎信息:显示用户的姓名或欢迎消息。
功能菜单:可以选择不同的操作,如查询、借阅、归还等。
消息通知:显示系统通知或用户相关信息,如借阅到期提醒。
3. 查询操作
在查询界面,用户可以查找书籍或相关信息。操作步骤:
输入查询条件:在搜索框中输入书名、作者、ISBN等。
选择查询类型:可根据类别选择如“书名”、“作者”、“出版社”等。
点击查询:按下“查询”按钮,系统返回符合条件的书籍列表。
查看书籍详情:用户可以点击书籍标题查看详细信息,如库存状态、书籍简介等。
4. 借阅操作
借阅界面允许用户借出书籍。操作步骤:
选择书籍:在查询结果中找到您想要借阅的书籍。
检查可借状态:确认该书籍的可借状态。
点击借阅:按下“借阅”按钮,系统将提示借阅条款和借阅时长。
确认借阅:仔细阅读并确认借阅信息;系统将生成借阅记录。

浙公网安备 33010602011771号