pinpinsystem
Wzq 6 months ago
parent f11039597c
commit 99b3651a75

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="lib"/>
<classpathentry kind="lib" path="lib/mysql-connector-java-5.1.26.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>PinpinSystem</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8

@ -0,0 +1,14 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=17
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=17

@ -0,0 +1,79 @@
package com.hm.bean;
import java.util.Objects;
public class Pinpin {
private int id;
private String name;
private String press;
private String time;
private int num;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPress() {
return press;
}
public void setPress(String press) {
this.press = press;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
@Override
public String toString() {
return "Book [id=" + id + ", name=" + name + ", press=" + press + ", time=" + time + ", num="
+ num + "]";
}
@Override
public int hashCode() {
return Objects.hash(name);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Pinpin other = (Pinpin) obj;
return Objects.equals(name, other.name);
}
}

@ -0,0 +1,193 @@
package com.hm.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import com.hm.bean.Pinpin;
import com.hm.util.DBUtil;
public class PinpinDao {
//添加操作
public int add(Pinpin b) {
//获取连接对象
Connection conn = DBUtil.getConn();
String sql="insert into pinpin values(null,?,?,?,?)";
int i = 0;
try {
PreparedStatement ps=conn.prepareStatement(sql);
ps.setString(1, b.getName());
ps.setString(2, b.getPress());
ps.setString(3, b.getTime());
ps.setInt(4, b.getNum());
i = ps.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return i;
}
//查询全部
public ArrayList<Pinpin> select (Pinpin b){
Connection conn = DBUtil.getConn();
String sql = "select * from book where 1=1";
ArrayList<Object> params = new ArrayList<Object>();
if (b != null) {
if(b.getName() != null && !b.getName().isEmpty()) {
sql += " and name like ? ";
params.add("%"+b.getName()+"%");
}
if(b.getPress() != null && !b.getPress().isEmpty()) {
sql += " and press=? ";
params.add(b.getPress());
}
}
//处理sql语句
ArrayList<Pinpin> li = new ArrayList<>();
try {
PreparedStatement ps = conn.prepareStatement(sql);
for(int i=0;i<params.size();i++) {
ps.setObject(i+1, params.get(i));
}
ResultSet rs = ps.executeQuery();
while(rs.next()) {
Pinpin pinpin = new Pinpin();
pinpin.setId(rs.getInt("id"));
pinpin.setName(rs.getString("name"));
pinpin.setPress(rs.getString("press"));
pinpin.setTime(rs.getString("time"));
pinpin.setNum(rs.getInt("num"));
li.add(pinpin);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return li;
}
public ArrayList<Pinpin> riqipx (Pinpin b){
Connection conn = DBUtil.getConn();
String sql = "select * from book order by time";
ArrayList<Object> params = new ArrayList<Object>();
if (b != null) {
if(b.getName() != null && !b.getName().isEmpty()) {
sql += " and name like ? ";
params.add("%"+b.getName()+"%");
}
if(b.getPress() != null && !b.getPress().isEmpty()) {
sql += " and press=? ";
params.add(b.getPress());
}
}
ArrayList<Pinpin> li = new ArrayList<>();
try {
PreparedStatement ps = conn.prepareStatement(sql);
for(int i=0;i<params.size();i++) {
ps.setObject(i+1, params.get(i));
}
ResultSet rs = ps.executeQuery();
while(rs.next()) {
Pinpin book = new Pinpin();
book.setId(rs.getInt("id"));
book.setName(rs.getString("name"));
book.setPress(rs.getString("press"));
book.setTime(rs.getString("time"));
book.setNum(rs.getInt("num"));
li.add(book);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return li;
}
public ArrayList<Pinpin> shuliangpx (Pinpin b){
Connection conn = DBUtil.getConn();
String sql = "select * from book order by num";
ArrayList<Pinpin> li = new ArrayList<>();
try {
PreparedStatement ps = conn.prepareStatement(sql);
ResultSet rs = ps.executeQuery();
while(rs.next()) {
Pinpin pinpin = new Pinpin();
pinpin.setId(rs.getInt("id"));
pinpin.setName(rs.getString("name"));
pinpin.setPress(rs.getString("press"));
pinpin.setTime(rs.getString("time"));
pinpin.setNum(rs.getInt("num"));
li.add(pinpin);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return li;
}
//删除
public int delete(int id) {
Connection conn = DBUtil.getConn();
String sql = "delete from book where id=?";
int i=0;
try {
PreparedStatement ps = conn.prepareStatement(sql);
ps.setInt(1, id);
i = ps.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return i;
}
//修改 查询你要修改的对象的内容
public Pinpin selectId(int id) {
Connection conn = DBUtil.getConn();
String sql = "select * from book where id=?";
Pinpin pinpin = null;
try {
PreparedStatement ps=conn.prepareStatement(sql);
ps.setInt(1, id);
ResultSet rs = ps.executeQuery();
while(rs.next()) {
pinpin = new Pinpin();
pinpin.setId(rs.getInt("id"));
pinpin.setName(rs.getString("name"));
pinpin.setPress(rs.getString("press"));
pinpin.setTime(rs.getString("time"));
pinpin.setNum(rs.getInt("num"));
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return pinpin;
}
public void update(Pinpin b) {
Connection conn = DBUtil.getConn();
String sql = "update book set name=?,press=?,time=?,num=? where id=?";
try {
PreparedStatement ps = conn.prepareStatement(sql);
ps.setString(1, b.getName());
ps.setString(2, b.getPress());
ps.setString(3, b.getTime());
ps.setInt(4, b.getNum());
ps.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

@ -0,0 +1,46 @@
package com.hm.demo;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class JdbcDemo {
public static void main(String[] args) {
// io
// 加载驱动类 第一步
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
System.out.println("加载驱动类失败");
}
// 创建连接 第二步
try {
Connection connection = DriverManager
.getConnection("jdbc:mysql://localhost:3306/pinpin?characterEncoding=utf-8", "root", "");
// 往数据库添加数据
// 先定义你需要操作的sql语句
String sql = "select * from Pinpin";
Statement st = connection.createStatement();
ResultSet rs = st.executeQuery(sql);
while (rs.next()) {
int id = rs.getInt("id");
String name = rs.getString("name");
String press = rs.getString("press");
String time = rs.getString("time");
int num = rs.getInt("num");
System.out.println(id + "," + name + "," + press + "," + time + "," + num);
}
// System.out.println(connection);
} catch (SQLException e) {
System.out.println("连接失败");
}
}
}

@ -0,0 +1,51 @@
package com.hm.demo;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.HashSet;
import java.util.Random;
import com.hm.bean.Pinpin;
import com.hm.dao.PinpinDao;
public class PinpinDaoDemo {
public static void main(String[] args) throws ParseException {
PinpinDao bd = new PinpinDao();
HashSet<Pinpin> h = new HashSet<>();
String press[] = {"日用","食品","家具","出行","家电"};
String name[] = {"奶茶","零食","食用油","盐","冰箱","电视","沙发","雨伞","自行车"};
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//指定开始日期
long start = sdf.parse("2000-1-1 00:00:00").getTime();
//指定结束日期
long end = sdf.parse("2023-11-11 00:00:00").getTime();
Random r = new Random();
while(h.size()<=100) {
Pinpin b = new Pinpin();
b.setName(name[r.nextInt(name.length)]+r.nextInt(19));
b.setPress(press[r.nextInt(press.length)]);
//调用方法产生随机数
long randomDate = nextLong(start, end);
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String date = formatter.format(randomDate);
String time[] = {date};
b.setTime(time[r.nextInt(time.length)]);
b.setNum(r.nextInt(100,5000));
h.add(b);
}
for(Pinpin e:h) {
bd.add(e);
}
System.out.println("添加完成");
}
public static long nextLong(long start, long end) {
Random random = new Random();
return start + (long) (random.nextDouble() * (end - start + 1));
}
}

@ -0,0 +1,124 @@
package com.hm.ui;
import java.awt.Font;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import com.hm.bean.Pinpin;
import com.hm.dao.PinpinDao;
public class AddFrame extends JFrame {
public AddFrame() {
// 设置窗口标题
this.setTitle("添加");
// 设置窗口大小
this.setSize(800, 500);
// 设置窗口居中
this.setLocationRelativeTo(null);
// 设置窗口关闭程序自动结束
this.setDefaultCloseOperation(3);
// 设置窗口不可更改
this.setResizable(true);
// 面板
JPanel jp = new JPanel();
jp.setLayout(null);
JLabel jl = new JLabel("增加");
jl.setBounds(350, 30, 200, 40);
jl.setFont(new Font(Font.DIALOG, Font.BOLD, 40));
JLabel jl1 = new JLabel("名字:");
jl1.setBounds(210, 100, 100, 25);
jl1.setFont(new Font(Font.DIALOG, Font.PLAIN, 20));
JTextField jt1 = new JTextField(10);
jt1.setBounds(310, 100, 250, 30);
jt1.setFont(new Font(Font.DIALOG, Font.PLAIN, 20));
JLabel jl2 = new JLabel("出版:");
jl2.setBounds(210, 165, 100, 25);
jl2.setFont(new Font(Font.DIALOG, Font.PLAIN, 20));
JTextField jt2 = new JTextField(10);
jt2.setBounds(310, 165, 250, 30);
jt2.setFont(new Font(Font.DIALOG, Font.PLAIN, 20));
JLabel jl4 = new JLabel("时间:");
jl4.setBounds(210, 230, 100, 25);
jl4.setFont(new Font(Font.DIALOG, Font.PLAIN, 20));
JTextField jt4 = new JTextField(10);
jt4.setBounds(310, 230, 250, 30);
jt4.setFont(new Font(Font.DIALOG, Font.PLAIN, 20));
JLabel jl5 = new JLabel("数量:");
jl5.setBounds(210, 295, 100, 25);
jl5.setFont(new Font(Font.DIALOG, Font.PLAIN, 20));
JTextField jt5 = new JTextField(10);
jt5.setBounds(310, 295, 250, 30);
jt5.setFont(new Font(Font.DIALOG, Font.PLAIN, 20));
JButton jb1 = new JButton("增加");
jb1.setBounds(200, 370, 150, 40);
jb1.setFont(new Font(Font.DIALOG, Font.PLAIN, 30));
JButton jb2 = new JButton("返回");
jb2.setBounds(410, 370, 150, 40);
jb2.setFont(new Font(Font.DIALOG, Font.PLAIN, 30));
jp.add(jl);
jp.add(jl1);
jp.add(jt1);
jp.add(jl2);
jp.add(jt2);
jp.add(jl4);
jp.add(jt4);
jp.add(jl5);
jp.add(jt5);
jp.add(jb1);
jp.add(jb2);
//增加
jb1.addActionListener((e) -> {
Pinpin b = new Pinpin();
String name = jt1.getText();
b.setName(name);
String time = jt4.getText();
b.setTime(time);
String num = jt5.getText();
if(!num.isEmpty()) {
b.setNum(Integer.parseInt(num));
}
PinpinDao bd = new PinpinDao();
int i = bd.add(b);
if(i>0) {
//回到主界面,添加成功
new MainFrame();
dispose();
}else {
JOptionPane.showMessageDialog(null, "添加失败");
}
});
//返回
jb2.addActionListener((e) -> {
new MainFrame();
dispose();
});
this.add(jp);
// 显示方法
this.setVisible(true);
}
public static void main(String[] args) {
new AddFrame();
}
}

@ -0,0 +1,111 @@
package com.hm.ui;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
public class Login extends JFrame implements ActionListener {
JTextField UID = new JTextField();
JTextField Password = new JTextField();
JLabel zh = new JLabel("账号:");
JLabel mm = new JLabel("密码:");
JButton zhk = new JButton("登录");
JButton zhl = new JButton("返回主界面");
public Login() {
initFrame();
initzhuce();
this.setVisible(true);
}
private void initFrame() {
this.setTitle("登录界面");
this.setSize(500, 500);// 初始位置
this.setLayout(null);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(3);
}
private void initzhuce() {
// 文本框
UID.setBounds(190, 100, 160, 40);
Password.setBounds(190, 170, 160, 40);
// 标签
zh.setBounds(140, 75, 100, 80);
mm.setBounds(140, 150, 100, 80);
zh.setFont(new Font("宋体",Font.BOLD,15));
mm.setFont(new Font("宋体",Font.BOLD,15));
// 按钮
zhk.setBounds(80, 300, 100, 50);
zhl.setBounds(290, 300, 100, 50);
this.add(UID);
this.add(Password);
this.add(zh);
this.add(mm);
this.add(zhk);
this.add(zhl);
zhk.addActionListener(this);
zhl.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == zhk) {
String username = UID.getText();
String password = Password.getText();
try (BufferedReader reader = new BufferedReader(new FileReader("users.txt"))) {
String line;
if (validateUser(username, password)) {
// 登录成功,显示欢迎界面
JOptionPane.showMessageDialog(this, "欢迎来到系统!");
new MainFrame();
dispose();
} else {
// 登录失败,显示错误消息
JOptionPane.showMessageDialog(this, "登录失败。");
new Login();
dispose();
}
} catch (IOException e1) {
e1.printStackTrace();
}
}
if (e.getSource() == zhl) {
new System();
dispose();
}
}
private boolean validateUser(String username, String password) {
while (true) {
try (BufferedReader reader = new BufferedReader(new FileReader("users.txt"))) {
String line;
boolean flag = false;
while ((line = reader.readLine()) != null) {
String[] userInfo = line.split(",");
if (userInfo[0].equals(username) && userInfo[1].equals(password)) {
flag = true;
return true;
}
}
if (flag) {
continue;
}
} catch (IOException e) {
e.printStackTrace();
}
break;
}
return false;
}
}

@ -0,0 +1,204 @@
package com.hm.ui;
import java.awt.BorderLayout;
import java.util.ArrayList;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JFrame;
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.table.DefaultTableModel;
import com.hm.bean.Pinpin;
import com.hm.dao.PinpinDao;
public class MainFrame extends JFrame {
//上面
JPanel jp1 = new JPanel();
//查询 根据多字段查询
JLabel jl = new JLabel("活动:");
JTextField jt = new JTextField(10);
JLabel jl1 = new JLabel("用途:");
JTextField jt1 = new JTextField(10);
JButton jb = new JButton("查询");
JButton ripx = new JButton("按照日期排序");
JButton slpx = new JButton("查看接取状态");
//中间
JPanel jp2 = new JPanel();
DefaultTableModel dtm = new DefaultTableModel();
JTable jta = new JTable(dtm);
JScrollPane jsp = new JScrollPane(jta);
//下面
JPanel jp3 = new JPanel();
JButton jb1 = new JButton("发布任务");
JButton jb2 = new JButton("删除任务");
JButton jb3 = new JButton("修改任务");
JButton jb4 = new JButton("接取任务");
//显示数据表格
PinpinDao bd = new PinpinDao();
private void show(Pinpin b) {
ArrayList<Pinpin> li = bd.select(b);
//清除之前的数据表格
for(int i=0;i<dtm.getRowCount();i++) {
dtm.setRowCount(0);
}
for(int i=0;i<li.size();i++) {
Vector<Object> v = new Vector<>();
v.add(li.get(i).getId());
v.add(li.get(i).getName());
v.add(li.get(i).getPress());
v.add(li.get(i).getTime());
v.add(li.get(i).getNum());
dtm.addRow(v);
}
}
private void riqipx(Pinpin b) {
ArrayList<Pinpin> li = bd.riqipx(b);
//清除之前的数据表格
for(int i=0;i<dtm.getRowCount();i++) {
dtm.setRowCount(0);
}
for(int i=0;i<li.size();i++) {
Vector<Object> v = new Vector<>();
v.add(li.get(i).getId());
v.add(li.get(i).getName());
v.add(li.get(i).getPress());
v.add(li.get(i).getTime());
v.add(li.get(i).getNum());
dtm.addRow(v);
}
}
private void shuliangpx(Pinpin b) {
ArrayList<Pinpin> li = bd.shuliangpx(b);
//清除之前的数据表格
for(int i=0;i<dtm.getRowCount();i++) {
dtm.setRowCount(0);
}
for(int i=0;i<li.size();i++) {
Vector<Object> v = new Vector<>();
v.add(li.get(i).getId());
v.add(li.get(i).getName());
v.add(li.get(i).getPress());
v.add(li.get(i).getTime());
v.add(li.get(i).getNum());
dtm.addRow(v);
}
}
public MainFrame() {
this.setTitle("首页");// 设置窗口标题
this.setSize(800, 500);// 设置窗口大小
this.setLocationRelativeTo(null);// 设置窗口居中
this.setDefaultCloseOperation(3);// 设置窗口关闭程序自动结束
this.setResizable(true);// 设置窗口不可更改
// 添加第一部分
jp1.add(jl);
jp1.add(jt);
jp1.add(jl1);
jp1.add(jt1);
jp1.add(jb);
jp1.add(ripx);
jp1.add(slpx);
jb.addActionListener((e) -> {
// 按钮点击事件
Pinpin b = new Pinpin();
String name = jt.getText();
b.setName(name);
String press = jt1.getText();
b.setPress(press);
show(b);
});
ripx.addActionListener((e) ->{
Pinpin b = new Pinpin();
String name = jt.getText();
b.setName(name);
String press = jt1.getText();
b.setPress(press);
riqipx(b);
});
slpx.addActionListener((e) ->{
Pinpin b = new Pinpin();
shuliangpx(b);
});
// 添加第二部分
dtm.addColumn("编号");
dtm.addColumn("活动");
dtm.addColumn("用途");
dtm.addColumn("日期");
dtm.addColumn("状态");
show(null);
// 添加第三部分
jp3.add(jb1);
jp3.add(jb2);
jp3.add(jb3);
jp3.add(jb4);
// 增加
jb1.addActionListener((e) -> {
//跳转一个新的窗口
new AddFrame();
dispose();
});
//删除
jb2.addActionListener((e) -> {
//选中你要删除的行
int i = jta.getSelectedRow();
if(i>=0) {
//获取选中这一行的id
Object o = dtm.getValueAt(i, 0);
int id = Integer.parseInt(o.toString());
//是否删除
int j = JOptionPane.showConfirmDialog(null, "确认删除吗?");
if(j==0) {
//确认删除
bd.delete(id);
show(null);
}
}else {
JOptionPane.showMessageDialog(null, "请选择你要删除的行");
}
});
//修改
jb3.addActionListener((e) -> {
//选中你要修改的行
int i = jta.getSelectedRow();
if(i>=0) {
//获取选中这一行的id
Object o = dtm.getValueAt(i, 0);
int id = Integer.parseInt(o.toString());
Pinpin b = bd.selectId(id);
new UpdateFrame(b);
dispose();
}else {
JOptionPane.showMessageDialog(null, "请选择你要修改的行");
}
});
this.add(jp1, BorderLayout.NORTH);
this.add(jsp, BorderLayout.CENTER);
this.add(jp3, BorderLayout.SOUTH);
this.setVisible(true);// 显示窗口
}
public static void main(String[] args) {
new MainFrame();
}
}

@ -0,0 +1,96 @@
package com.hm.ui;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
public class Register extends JFrame implements ActionListener {
JTextField UID = new JTextField();
JTextField Password = new JTextField();
JLabel zh = new JLabel("账号:");
JLabel mm = new JLabel("密码:");
JButton zhk = new JButton("确认注册");
JButton sjm = new JButton("返回首界面");
public Register() {
initFrame();
initzhuce();
this.setVisible(true);
}
private void initFrame() {
this.setTitle("注册界面");
this.setSize(500, 500);// 初始位置
this.setLayout(null);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(3);
}
private void initzhuce() {
// 文本框
UID.setBounds(190, 100, 160, 40);
Password.setBounds(190, 170, 160, 40);
// 标签
zh.setBounds(140, 75, 100, 80);
mm.setBounds(140, 150, 100, 80);
zh.setFont(new Font("宋体", Font.BOLD, 15));
mm.setFont(new Font("宋体", Font.BOLD, 15));
// 按钮
zhk.setBounds(80, 300, 100, 50);
sjm.setBounds(300, 300, 100, 50);
this.add(UID);
this.add(Password);
this.add(zh);
this.add(mm);
this.add(zhk);
this.add(sjm);
zhk.addActionListener(this);
sjm.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == zhk) {
String username = UID.getText();
String password = Password.getText();
// 注册用户
if (username.equals("") || password.equals("")) {
JOptionPane.showMessageDialog(this, "注册失败,请重试!");
} else {
try {
BufferedWriter writer = new BufferedWriter(new FileWriter("users.txt", true));
BufferedReader reader = new BufferedReader(new FileReader("users.txt"));
String line;
String str = UID.getText() + "," + Password.getText();
boolean found = false;
while ((line = reader.readLine()) != null) {
String[] s = line.split(",");
if (UID.getText().equals(s[0])) {
JOptionPane.showMessageDialog(this, "该账号已存在,请重新注册!");
reader.close();
found = true;
new Register();
this.dispose();
}
}
if (!found) {
writer.write(username + "," + password);
writer.newLine();
writer.close();
JOptionPane.showMessageDialog(this, "注册成功,请登录!");
new Login();
dispose();
}
} catch (IOException e1) {
}
}
}
if (e.getSource() == sjm) {
new System();
dispose();
}
}
}

@ -0,0 +1,58 @@
package com.hm.ui;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
public class System extends JFrame implements ActionListener {
JLabel sy= new JLabel("欢迎来到拼拼系统");
JButton dl=new JButton("登录");
JButton zc=new JButton("注册");
public System() {
initxitong();
initFrame();
this.setVisible(true);
}
private void initFrame() {
this.setTitle("首界面");
this.setSize(500, 500);// 初始位置
this.setLayout(null);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(3);
}
private void initxitong() {
sy.setBounds(120, 100, 300, 100);
dl.setBounds(100, 300, 100, 50);
zc.setBounds(290, 300, 100, 50);
sy.setFont(new Font("宋体", Font.BOLD, 30));
this.add(dl);
this.add(sy);
this.add(zc);
dl.addActionListener(this);
zc.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == dl) {
new Login();
dispose();
}
if (e.getSource() == zc) {
new Register();
dispose();
}
}
public static void main(String[] args) {
new System();
}
}

@ -0,0 +1,125 @@
package com.hm.ui;
import java.awt.Font;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import com.hm.bean.Pinpin;
import com.hm.dao.PinpinDao;
public class UpdateFrame extends JFrame {
public UpdateFrame(Pinpin book) {
// 设置窗口标题
this.setTitle("修改");
// 设置窗口大小
this.setSize(800, 500);
// 设置窗口居中
this.setLocationRelativeTo(null);
// 设置窗口关闭程序自动结束
this.setDefaultCloseOperation(3);
// 设置窗口不可更改
this.setResizable(true);
// 面板
JPanel jp = new JPanel();
jp.setLayout(null);
JLabel jl = new JLabel("修改");
jl.setBounds(350, 30, 200, 40);
jl.setFont(new Font(Font.DIALOG, Font.BOLD, 40));
JLabel jl1 = new JLabel("书名:");
jl1.setBounds(210, 100, 100, 25);
jl1.setFont(new Font(Font.DIALOG, Font.PLAIN, 20));
JTextField jt1 = new JTextField(book.getName());
jt1.setBounds(310, 100, 250, 30);
jt1.setFont(new Font(Font.DIALOG, Font.PLAIN, 20));
JLabel jl2 = new JLabel("出版社:");
jl2.setBounds(210, 165, 100, 25);
jl2.setFont(new Font(Font.DIALOG, Font.PLAIN, 20));
JTextField jt2 = new JTextField(book.getPress());
jt2.setBounds(310, 165, 250, 30);
jt2.setFont(new Font(Font.DIALOG, Font.PLAIN, 20));
JLabel jl4 = new JLabel("时间:");
jl4.setBounds(210, 230, 100, 25);
jl4.setFont(new Font(Font.DIALOG, Font.PLAIN, 20));
JTextField jt4 = new JTextField(book.getTime() + "");
jt4.setBounds(310, 230, 250, 30);
jt4.setFont(new Font(Font.DIALOG, Font.PLAIN, 20));
JLabel jl5 = new JLabel("数量:");
jl5.setBounds(210, 295, 100, 25);
jl5.setFont(new Font(Font.DIALOG, Font.PLAIN, 20));
JTextField jt5 = new JTextField(book.getNum() + "");
jt5.setBounds(310, 295, 250, 30);
jt5.setFont(new Font(Font.DIALOG, Font.PLAIN, 20));
JButton jb1 = new JButton("修改");
jb1.setBounds(200, 370, 150, 40);
jb1.setFont(new Font(Font.DIALOG, Font.PLAIN, 30));
JButton jb2 = new JButton("返回");
jb2.setBounds(410, 370, 150, 40);
jb2.setFont(new Font(Font.DIALOG, Font.PLAIN, 30));
jp.add(jl);
jp.add(jl1);
jp.add(jt1);
jp.add(jl2);
jp.add(jt2);
jp.add(jl4);
jp.add(jt4);
jp.add(jl5);
jp.add(jt5);
jp.add(jb1);
jp.add(jb2);
// 修改
jb1.addActionListener((e) -> {
Pinpin b = new Pinpin();
String name = jt1.getText();
b.setName(name);
String press = jt2.getText();
b.setPress(press);
String time = jt4.getText();
b.setTime(time);
String num = jt5.getText();
if (!num.isEmpty()) {
b.setNum(Integer.parseInt(num));
}
//id不可以进行修改
b.setId(book.getId());
PinpinDao bd = new PinpinDao();
bd.update(b);
JOptionPane.showMessageDialog(null, "修改成功");
// 回到主界面,添加成功
new MainFrame();
dispose();
});
// 返回
jb2.addActionListener((e) -> {
new MainFrame();
dispose();
});
this.add(jp);
// 显示方法
this.setVisible(true);
}
public static void main(String[] args) {
// new UpdateFrame();
}
}

@ -0,0 +1,32 @@
package com.hm.util;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class DBUtil {
static {
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
System.out.println("加载驱动类失败");
}
}
public static Connection getConn() {
try {
Connection connection
= DriverManager.getConnection(
"jdbc:mysql://localhost:3306/pinpin?characterEncoding=utf-8",
"root", "");
return connection;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
}

@ -0,0 +1,2 @@
111,111
1111,1
Loading…
Cancel
Save