package view;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.security.interfaces.RSAKey;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Calendar;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.AbstractTableModel;
import utils.DBUtil;
/**
* 用户借书的界面
*
* @author 何兴旺
*
*/
public class UserBorrow extends JFrame {
private JScrollPane jsp = new JScrollPane();
private JTable table = new JTable();
private JButton btn1 = new JButton("借书");
private JButton btn2 = new JButton("退出");
private int row;
private MyModel model;
private JLabel jLabel1 = new JLabel("图书编号:");
private JLabel jLabel2 = new JLabel("图书名称:");
private JLabel jLabel3 = new JLabel("借书日期:");
private JLabel jLabel4 = new JLabel("还书日期:");
private JLabel jLabel5 = new JLabel("借 书 人:");
private JLabel jLabel6 = new JLabel("借书人ID:");
private JLabel jLabel7 = new JLabel("书 类 型:");
private JTextField jTextField1 = new JTextField();
private JTextField jTextField2 = new JTextField();
private JTextField jTextField3 = new JTextField();
private JTextField jTextField4 = new JTextField();
private JTextField jTextField5 = new JTextField();
private JTextField jTextField6 = new JTextField();
private JTextField jTextField7 = new JTextField();
private Panel panBtn = new Panel();
private Panel panLab = new Panel();
public UserBorrow() {
setTitle("借书窗口");
setSize(600, 600);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
// 设置可见视图的接口
jsp.setViewportView(table);
// 定义表格 宽600,高度200
jsp.setPreferredSize(new Dimension(600, 200));
// 设置横向和垂直滚动条可见
jsp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
jsp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
panBtn.add(btn1);
panBtn.add(btn2);
// 设置中间的panel布局为空
panLab.setLayout(null);
JButton jButton1 = new JButton("查找");
JTextField jTextField = new JTextField();
// 单选框
JRadioButton JB1 = new JRadioButton("按书名查找");
JRadioButton JB2 = new JRadioButton("按作者查找");
JB1.setSelected(true); // 默认选择JB1
// 加入组,避免出现可以两个都选择的情况
ButtonGroup bg = new ButtonGroup();
bg.add(JB1);
bg.add(JB2);
JB1.setSize(100, 30);
JB1.setLocation(40, 30);
JB2.setSize(100, 30);
JB2.setLocation(140, 30);
jTextField.setSize(160, 30);
jTextField.setLocation(250, 30);
jButton1.setSize(80, 30);
jButton1.setLocation(450, 30);
// 给标签和文本框设置位置
jLabel1.setSize(100, 100);
jLabel1.setLocation(10, 60);
jLabel1.setHorizontalAlignment(JLabel.RIGHT);
jTextField1.setSize(150, 30);
jTextField1.setLocation(110, 95);
jLabel2.setSize(100, 100);
jLabel2.setLocation(280, 60);
jLabel2.setHorizontalAlignment(JLabel.RIGHT);
jTextField2.setSize(150, 30);
jTextField2.setLocation(380, 95);
jLabel3.setSize(100, 100);
jLabel3.setLocation(10, 120);
jLabel3.setHorizontalAlignment(JLabel.RIGHT);
jTextField3.setSize(150, 30);
jTextField3.setLocation(110, 155);
// 自动获取借书时间(当前时间)
Calendar c = Calendar.getInstance();
// 获取年月日
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH) + 1;
int date = c.get(Calendar.DATE);
String time = year + "-" + month + "-" + date;
jTextField3.setText(time);
jLabel4.setSize(100, 100);
jLabel4.setLocation(280, 120);
jLabel4.setHorizontalAlignment(JLabel.RIGHT);
jTextField4.setSize(150, 30);
jTextField4.setLocation(380, 155);
// 自动获取应还书时间(设置借阅时间为一个月)
Calendar c2 = Calendar.getInstance();// 可以对每个时间域单独修改
// 获取年月日
int year2 = c2.get(Calendar.YEAR);
int month2 = c2.get(Calendar.MONTH) + 2;
int date2 = c2.get(Calendar.DATE);
String time2 = year2 + "-" + month2 + "-" + date2;
jTextField4.setText(time2);
jLabel5.setSize(100, 100);
jLabel5.setLocation(10, 180);
jLabel5.setHorizontalAlignment(JLabel.RIGHT);
jTextField5.setSize(150, 30);
jTextField5.setLocation(110, 215);
String username = LibraryUserFrame.USER_NAME;
jTextField5.setText(username);// 自动获取当前登录用户名
jLabel6.setSize(100, 100);
jLabel6.setLocation(280, 180);
jLabel6.setHorizontalAlignment(JLabel.RIGHT);
jTextField6.setSize(150, 30);
jTextField6.setLocation(380, 215);
jLabel7.setSize(100, 100);
jLabel7.setLocation(10, 230);
jLabel7.setHorizontalAlignment(JLabel.RIGHT);
jTextField7.setSize(150, 30);
jTextField7.setLocation(110, 265);
String sql = "select userid from user where username = '" + username
+ "';";
Statement st = DBUtil.getStatement();
try {
ResultSet r = st.executeQuery(sql);
while (r.next()) {
String sId = r.getString(1);
jTextField6.setText(sId);
}
} catch (SQLException e1) {
e1.printStackTrace();
}
// 把标签和文本框加到panLab面板中
// panLab.add(Label);
// panLab.add(comboBox);
panLab.add(JB1);
panLab.add(JB2);
panLab.add(jTextField);
panLab.add(jButton1);
panLab.add(jLabel1);
panLab.add(jLabel2);
panLab.add(jLabel3);
panLab.add(jLabel4);
panLab.add(jLabel5);
panLab.add(jLabel6);
panLab.add(jLabel7);
panLab.add(jTextField1);
panLab.add(jTextField2);
panLab.add(jTextField3);
panLab.add(jTextField4);
panLab.add(jTextField5);
panLab.add(jTextField6);
panLab.add(jTextField7);
this.add(jsp, BorderLayout.NORTH);
this.add(panLab, BorderLayout.CENTER);
this.add(panBtn, BorderLayout.SOUTH);
jButton1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
if (JB1.isSelected()) {
String s = jTextField.getText().trim();
String sql = "select * from book where BookName like '%"
+ s + "%';";
model = new MyModel(sql);
table.setModel(model);
table.getColumnModel().getColumn(0).setHeaderValue("书号");
table.getColumnModel().getColumn(1).setHeaderValue("书名");
table.getColumnModel().getColumn(2).setHeaderValue("作者");
table.getColumnModel().getColumn(3).setHeaderValue("类型");
table.getColumnModel().getColumn(4).setHeaderValue("价格");
table.getColumnModel().getColumn(5).setHeaderValue("是否借出");
} else {
String s = jTextField.getText().trim();
String sql = "select * from book where Writter like '%" + s
+ "%';";
model = new MyModel(sql);
table.setModel(model);
table.getColumnModel().getColumn(0).setHeaderValue("书号");
table.getColumnModel().getColumn(1).setHeaderValue("书名");
table.getColumnModel().getColumn(2).setHeaderValue("作者");
table.getColumnModel().getColumn(3).setHeaderValue("类型");
table.getColumnModel().getColumn(4).setHeaderValue("价格");
table.getColumnModel().getColumn(5).setHeaderValue("是否借出");
}
}
});
// 获取表里的值
table.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
String id, name, type;
int selRow = table.getSelectedRow();
id = table.getValueAt(selRow, 0).toString().trim();
name = table.getValueAt(selRow, 1).toString().trim();
type = table.getValueAt(selRow, 3).toString().trim();
jTextField1.setText(id);
jTe
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
运用JDBC连接MySQL数据库,用Java Swing开发的图书管理系统。两个登录角色(管理员,用户),管理员可实现查看对用户借书信息的数据分析(饼形图和柱状图)结果查看。效果在:https://blog.csdn.net/destiny_98/article/details/82747472
资源推荐
资源详情
资源评论
收起资源包目录
用JDBC连接数据库的Java Swing开发的图书管理系统 (113个子文件)
UserBorrow.class 7KB
UserReturn.class 7KB
Book_Update_Delete.class 5KB
User_Update_Delete.class 5KB
LibraryRootFrame.class 4KB
LogIn.class 4KB
PieChart.class 4KB
BookAddFrame.class 4KB
UserAddFrame.class 4KB
ZhuceFrame.class 4KB
BarChart.class 4KB
UserSearch.class 4KB
BookSearch.class 4KB
LibraryUserFrame.class 3KB
RootXiugaiMima.class 3KB
UserXiugaimima.class 3KB
UserBorrow$3.class 3KB
LogIn$1.class 3KB
UserReturn$1.class 3KB
UserReturn$2.class 3KB
User_Update_Delete$2.class 3KB
BookAddFrame$1.class 3KB
UserSearch$1.class 3KB
BookSearch$1.class 3KB
Book_Update_Delete$2.class 3KB
ZhuceFrame$1.class 3KB
UserBorrow$1.class 2KB
UserAddFrame$1.class 2KB
UserXiugaimima$1.class 2KB
RootXiugaiMima$1.class 2KB
User_Update_Delete$3.class 2KB
AllBorrow.class 2KB
Book_Update_Delete$3.class 2KB
AllBook.class 2KB
UserReturn$MyModel.class 2KB
Book_Update_Delete$4.class 2KB
User_Update_Delete$MyModel.class 2KB
Book_Update_Delete$MyModel.class 2KB
DBUtil.class 2KB
BookSearch$MyModel.class 2KB
UserSearch$MyModel.class 2KB
UserBorrow$MyModel.class 2KB
AllBorrow$MyModel.class 2KB
AllBook$MyModel.class 2KB
User_Update_Delete$1.class 2KB
Book_Update_Delete$1.class 1KB
UserDao.class 1KB
UserBorrow$2.class 1KB
PieTest.class 1KB
BarTest.class 1KB
UserAddFrame$2.class 1KB
ZhuceFrame$2.class 1KB
BookAddFrame$2.class 908B
RootXiugaiMima$2.class 893B
UserXiugaimima$2.class 893B
UserBean.class 892B
LogIn$2.class 879B
LibraryRootFrame$12.class 757B
LibraryUserFrame$6.class 755B
LibraryRootFrame$6.class 737B
LibraryRootFrame$2.class 737B
LibraryRootFrame$11.class 735B
LibraryUserFrame$5.class 733B
LibraryRootFrame$1.class 731B
LibraryRootFrame$5.class 731B
LibraryRootFrame$10.class 730B
LibraryUserFrame$4.class 729B
LibraryRootFrame$7.class 729B
LibraryUserFrame$1.class 729B
LibraryUserFrame$3.class 729B
LibraryRootFrame$3.class 729B
LibraryRootFrame$8.class 726B
LibraryRootFrame$4.class 726B
LibraryRootFrame$9.class 726B
LibraryUserFrame$2.class 726B
LogIn$3.class 706B
UserReturn$3.class 653B
UserBorrow$4.class 653B
Entry.class 434B
.classpath 589B
jfreechart-1.0.13.jar 1.36MB
mysql-connector-java-5.1.39-bin.jar 966KB
jcommon-1.0.16.jar 302KB
gnujaxp.jar 226KB
UserBorrow.java 11KB
UserReturn.java 11KB
Book_Update_Delete.java 9KB
User_Update_Delete.java 8KB
LogIn.java 6KB
BookAddFrame.java 5KB
UserSearch.java 5KB
BookSearch.java 5KB
LibraryRootFrame.java 5KB
UserAddFrame.java 5KB
ZhuceFrame.java 5KB
UserXiugaimima.java 4KB
RootXiugaiMima.java 4KB
LibraryUserFrame.java 3KB
AllBorrow.java 3KB
PieChart.java 3KB
共 113 条
- 1
- 2
资源评论
知或谓之慧
- 粉丝: 21
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功