package SonView;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.sql.SQLException;
import java.util.List;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.table.DefaultTableModel;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import Pojo.Book;
import Pojo.Mybook;
import SonBooks.UpdateBook;
import tools.JDBCUtils;
import tools.ListTableModel;
import java.awt.Color;
import javax.swing.JScrollBar;
import javax.swing.JToggleButton;
import javax.swing.JList;
import javax.swing.JScrollPane;
public class Books {
public JFrame frame;
protected static JTable table;
private JButton button_1;
private JLabel label;
private JTextField textField;
private JButton button_2;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Books window = new Books();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
try {
QueryAll();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public Books() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setResizable(false);
frame.setLocationRelativeTo(null);
frame.setTitle("书籍借阅系统");
frame.setIconImage(Toolkit.getDefaultToolkit().getImage("C:\\Users\\Xu\\eclipse-workspace\\Library\\book.jpg"));
frame.setBounds(100, 100, 933, 464);
frame.setLocationRelativeTo(null);
table = new JTable();
table.setBounds(14, 92, 869, 247);
JButton button = new JButton("捐赠书籍");
button.setFont(new Font("华文楷体", Font.PLAIN, 20));
button.setBounds(360, 352, 175, 64);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
SonBooks.Add.main(null);
}
});
button.setBackground(new Color(255, 228, 225));
button_1 = new JButton("借阅书籍");
button_1.setFont(new Font("华文楷体", Font.PLAIN, 20));
button_1.setBounds(14, 352, 175, 64);
button_1.setBackground(new Color(255, 228, 225));
button_1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
QueryRunner qr = new QueryRunner(JDBCUtils.getDataSource());
int row = table.getSelectedRow();
Book book = getSortByTableRow(row);
int I = qr.update("DELETE FROM books WHERE GoodsCode=?",book.getGoodsCode());
int r = qr.update("INSERT INTO mybook VALUES(?,?,?,?)",book.getGoodsCode(),book.getGoodsName(),book.getPrice(),book.getStock());
List<Book> books = qr.query("SELECT * FROM books ", new BeanListHandler<Book>(Book.class));
setTableModel(books);
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
label = new JLabel("书籍名称:");
label.setBounds(180, 13, 107, 34);
label.setFont(new Font("宋体", Font.PLAIN, 20));
textField = new JTextField();
textField.setBounds(301, 20, 216, 24);
textField.setColumns(10);
JButton btnNewButton = new JButton("查询书籍");
btnNewButton.setFont(new Font("华文楷体", Font.PLAIN, 20));
btnNewButton.setBounds(568, 15, 151, 34);
btnNewButton.setBackground(new Color(255, 228, 225));
btnNewButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
QueryRunner qr = new QueryRunner(JDBCUtils.getDataSource());
try {
String bookname = textField.getText().trim();
if(bookname.isEmpty()) {
List<Book> books = qr.query("SELECT * FROM books ", new BeanListHandler<Book>(Book.class));
setTableModel(books);
}
else {
List<Book> books = qr.query("SELECT * FROM books WHERE goodsName LIKE '%"+bookname+"%'", new BeanListHandler<Book>(Book.class));
setTableModel(books);
}
textField.setText(null);
} catch (SQLException e1) {
e1.printStackTrace();
}
}
});
button_2 = new JButton("返回");
button_2.setFont(new Font("华文楷体", Font.PLAIN, 20));
button_2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});
button_2.setBounds(708, 352, 175, 64);
button_2.setBackground(new Color(255, 228, 225));
button_2.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
frame.setVisible(false);
}
});
JButton btnNewButton_1 = new JButton("书籍ID");
btnNewButton_1.setFont(new Font("华文新魏", Font.PLAIN, 18));
btnNewButton_1.setBounds(14, 65, 216, 27);
frame.getContentPane().setLayout(null);
frame.getContentPane().add(btnNewButton_1);
frame.getContentPane().add(label);
frame.getContentPane().add(textField);
frame.getContentPane().add(btnNewButton);
frame.getContentPane().add(table);
frame.getContentPane().add(button_1);
frame.getContentPane().add(button);
frame.getContentPane().add(button_2);
JButton btnNewButton_1_1 = new JButton("书籍名称");
btnNewButton_1_1.setFont(new Font("华文新魏", Font.PLAIN, 18));
btnNewButton_1_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});
btnNewButton_1_1.setBounds(231, 65, 216, 27);
frame.getContentPane().add(btnNewButton_1_1);
JButton btnNewButton_1_2 = new JButton("书籍价格");
btnNewButton_1_2.setFont(new Font("华文新魏", Font.PLAIN, 18));
btnNewButton_1_2.setBounds(446, 65, 216, 27);
frame.getContentPane().add(btnNewButton_1_2);
JButton btnNewButton_1_3 = new JButton("书籍数量");
btnNewButton_1_3.setFont(new Font("华文新魏", Font.PLAIN, 18));
btnNewButton_1_3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});
btnNewButton_1_3.setBounds(661, 65, 222, 27);
frame.getContentPane().add(btnNewButton_1_3);
}
protected static void setTableModel(List<Book> sortList) {
String[] colNames = new String[] {"书籍ID", "书籍名称", "价格", "数量"};
String[] propNames = new String[] {"goodsCode", "goodsName", "price", "stock"};
if(sortList == null || sortList.size() == 0) {
table.setModel(new DefaultTableModel(new Object[][] {
{null, null, null, null}, {null, null, null, null},
{null, null, null, null}, {null, null, null, null},
{null, null, null, null}, {null, null, null, null},
{null, null, null, null}, {null, null, null, null},
{null, null, null, null}, {null, null, null, null},
{null, null, null, null}, {null, null, null, null},
{null, null, null, null}, {null, null, null, null},
{null, null, null, null}, {null, null, null, null},
{null, null, null, null}, {null, null, null, null}
},colNames));
table.setEnabled(false);
return;
}
try {
table.setModel(new ListTableModel<Book>(sortList, Book.class, colNames, propNames));
table.setEnabled(true);
} catch (Exception e) {
e.printStackTrace();
}
}
protected Book getSortByTableRow(int row) {
return ((ListTableModel<Book>)table.getModel()).getInstance(row);
}
public static void QueryAll() throws SQLException {
QueryRunner qr = new QueryRunner(JD
没有合适的资源?快使用搜索试试~ 我知道了~
基于JavaWeb的电影售票系统
共99个文件
class:58个
java:16个
jar:8个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 63 浏览量
2022-07-09
16:53:14
上传
评论
收藏 4.07MB ZIP 举报
温馨提示
内容概要:通过带着读者手写简化版 Spring 框架,了解 Spring 核心原理。在手写Spring 源码的过程中会摘取整体框架中的核心逻辑,简化代码实现过程,保留核心功能,并逐步来实现一个完整的项目体系 适合人群:具备一定编程基础的学生用来学习 能学到什么:①三层框架②IOC、AOP、代理、切面、循环依赖都是如何设计和实现的。 阅读建议:此资源用来帮助学生们了解JavaWeb,以实践促使学生对该技术有进一步提高,不仅是代码编写实现也更注重内容上的需求分析和方案设计,所以在学习的过程要结合这些内容一起来实践,并调试对应的代码
资源推荐
资源详情
资源评论
收起资源包目录
01项目代码、数据库备份或数据文件-学生姓名.zip (99个子文件)
sql.sql 2KB
Library
bin
App
MainApp.class 1KB
SonBooks
UserBooks$2.class 2KB
UserBooks$7.class 1KB
UpdateBook$2.class 2KB
UserBooks.class 6KB
Add$1.class 782B
UserBooks$5.class 647B
Add.class 4KB
UpdateBook.class 3KB
UpdateBook$3.class 789B
UserBooks$3.class 901B
Add$3.class 740B
UserBooks$1.class 943B
UserBooks$4.class 831B
UserBooks$6.class 647B
Add$2.class 2KB
UpdateBook$1.class 824B
tools
JDBCUtils.class 1KB
ListTableModel.class 2KB
GrandsonBooks
UserAdd$3.class 961B
UserAdd$4.class 660B
UserAdd$1.class 831B
UserAdd.class 4KB
UserAdd$2.class 2KB
Pojo
User.class 2KB
Mybook.class 2KB
Book.class 2KB
View
Main$2.class 664B
Main.class 2KB
Main$1.class 875B
SonView
Mine$4.class 612B
User.class 3KB
Register$2.class 704B
Login$3.class 3KB
Mine.class 4KB
Books$5.class 618B
User$1.class 664B
Books$6.class 697B
Books$7.class 618B
Register$3.class 3KB
Books$8.class 618B
Books$4.class 2KB
Mine$3.class 1KB
Login$2.class 699B
Login$1.class 3KB
Register$1.class 3KB
Mine$5.class 612B
Books$1.class 894B
Mine$6.class 2KB
Mine$2.class 741B
Books.class 6KB
Register.class 3KB
Books$2.class 686B
Mine$1.class 783B
User$2.class 611B
Books$3.class 2KB
Login.class 3KB
User$3.class 852B
register.jpg 27KB
img
img1.jpg 7KB
book.jfif 14KB
img2.jpg 6KB
img3.jpg 7KB
user.jpg 7KB
.settings
org.eclipse.core.resources.prefs 57B
org.eclipse.jdt.core.prefs 598B
js.png 25KB
img.jpg 93KB
src
App
MainApp.java 278B
SonBooks
UpdateBook.java 5KB
Add.java 6KB
UserBooks.java 7KB
tools
ListTableModel.java 1KB
JDBCUtils.java 1KB
GrandsonBooks
UserAdd.java 6KB
Pojo
User.java 1KB
Mybook.java 1KB
Book.java 1KB
View
Main.java 2KB
SonView
Books.java 8KB
User.java 2KB
Login.java 6KB
Register.java 5KB
Mine.java 6KB
.project 383B
exit.png 25KB
.classpath 833B
book.jpg 480KB
lib
jcommon-1.0.12.jar 301KB
commons-beanutils-1.8.3.jar 510KB
commons-logging-1.1.1.jar 126KB
jfreechart-1.0.9.jar 1.23MB
commons-dbcp-1.4.jar 306KB
mysql-connector-java-5.1.28-bin.jar 855KB
commons-pool-1.3.jar 112KB
commons-dbutils-1.4.jar 96KB
my.png 26KB
login.jpg 27KB
共 99 条
- 1
资源评论
邂逅的光阴
- 粉丝: 8
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功