Java+Swing+mysql5实现超市商品管理系统

该博客介绍了使用Java Swing图形界面和MySQL数据库构建的超市商品管理系统。系统包括登录、商品添加、商品列表、查询、修改和删除功能。环境配置为JDK 1.8和MySQL 5.7,数据库包含商品和用户表。登录界面验证用户后,用户可进行商品管理操作。提供部分关键代码如DBConn.java和LoginFrm.java。源码可下载,数据库文件在swing_goods.sql中。
摘要由CSDN通过智能技术生成


一、系统介绍

1.系统功能

1.登录系统
2.添加商品
3.商品列表
4.查询商品
5.修改商品
6.删除商品
7.退出系统

2.环境配置

JDK版本:1.8
Mysql:5.7

3.数据库

/*
SQLyog Enterprise v12.09 (64 bit)
MySQL - 5.7.14 : Database - swing_goods
*********************************************************************
*/


/*!40101 SET NAMES utf8 */;

/*!40101 SET SQL_MODE=''*/;

/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
CREATE DATABASE /*!32312 IF NOT EXISTS*/`swing_goods` /*!40100 DEFAULT CHARACTER SET latin1 */;

USE `swing_goods`;

/*Table structure for table `goods` */

DROP TABLE IF EXISTS `goods`;

CREATE TABLE `goods` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(20) DEFAULT NULL,
  `number` int(11) DEFAULT NULL,
  `price` decimal(10,2) DEFAULT '0.00',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;

/*Data for the table `goods` */

insert  into `goods`(`id`,`name`,`number`,`price`) values (1,'农夫山泉矿泉水',100,'3.00'),(2,'优乐美奶茶',200,'10.00');

/*Table structure for table `user` */

DROP TABLE IF EXISTS `user`;

CREATE TABLE `user` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(20) DEFAULT NULL,
  `userpass` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

/*Data for the table `user` */

insert  into `user`(`id`,`username`,`userpass`) values (1,'admin','123456');

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

4.工程截图

在这里插入图片描述

二、系统展示

1.登录页

在这里插入图片描述

1.1登录成功

在这里插入图片描述

2.添加商品

在这里插入图片描述

3.商品列表

在这里插入图片描述

4.查询商品

在这里插入图片描述

5.修改商品

在这里插入图片描述

6.删除商品

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

7.退出系统

在这里插入图片描述

三、部分代码

DBConn.java

package cn.com.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
 
public class DBConn {
    private static String driverName = "com.mysql.jdbc.Driver";
    private static String url = "jdbc:mysql://localhost:3306/swing_goods?characterEncoding=utf8";
    private static String userName = "root";
    private static String password = "root";
    private Connection conn;
    private Statement stmt;
 
    public DBConn() {
        try {
            Class.forName(driverName);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
 
    /**
     * 连接数据库
     * 
     * @return
     * @throws SQLException
     */
    public Connection getConnection() throws SQLException {
        return DriverManager.getConnection(url, userName, password);
    }
    
 
    /**
     * 释放资源
     */
    public void close() {
        try {
            if (conn != null) {
                conn.close();
            }
            if (stmt != null) {
                stmt.close();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
 
}

LoginFrm.java

package cn.com.view;


import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.border.EmptyBorder;

import cn.com.dao.UserDao;
import cn.com.model.User;
import cn.com.util.DBConn;
import cn.com.util.StringUtil;

public class LoginFrm extends JFrame {

	private JPanel contentPane;
	private JTextField username_txt;
	private JPasswordField password_txt;
	
	private DBConn db=new DBConn();
	
	private UserDao userDao=new UserDao();

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					LoginFrm frame = new LoginFrm();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public LoginFrm() {
		setResizable(false);
		setTitle("\u7BA1\u7406\u5458\u767B\u5F55");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		
		JLabel lblNewLabel = new JLabel("\u8D85\u5E02\u5546\u54C1\u7BA1\u7406\u7CFB\u7EDF");
		lblNewLabel.setFont(new Font("微软雅黑", Font.PLAIN, 24));
		
		JLabel lblNewLabel_1 = new JLabel("\u7528\u6237\u540D:");
		
		JLabel lblNewLabel_2 = new JLabel("\u5BC6\u7801:");
		
		username_txt = new JTextField();
		username_txt.setColumns(10);
		
		password_txt = new JPasswordField();
		
		JButton btnNewButton = new JButton("\u767B\u5F55");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				LoginActionPerformed(e);
			}
		});
		
		JButton btnNewButton_1 = new JButton("\u91CD\u7F6E");
		btnNewButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				ResetActionPerformed(e);
			}
			
		});
		GroupLayout gl_contentPane = new GroupLayout(contentPane);
		gl_contentPane.setHorizontalGroup(
			gl_contentPane.createParallelGroup(Alignment.TRAILING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addGap(114)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
						.addGroup(gl_contentPane.createSequentialGroup()
							.addComponent(lblNewLabel_2)
							.addPreferredGap(ComponentPlacement.UNRELATED)
							.addComponent(password_txt, 224, 224, 224)
							.addPreferredGap(ComponentPlacement.RELATED))
						.addGroup(gl_contentPane.createSequentialGroup()
							.addComponent(lblNewLabel_1)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
								.addComponent(lblNewLabel)
								.addComponent(username_txt, 226, 226, 226))))
					.addGap(48))
				.addGroup(Alignment.LEADING, gl_contentPane.createSequentialGroup()
					.addGap(153)
					.addComponent(btnNewButton)
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addComponent(btnNewButton_1)
					.addContainerGap(157, Short.MAX_VALUE))
		);
		gl_contentPane.setVerticalGroup(
			gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addGap(50)
					.addComponent(lblNewLabel)
					.addGap(18)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblNewLabel_1)
						.addComponent(username_txt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addGap(18)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblNewLabel_2)
						.addComponent(password_txt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addGap(18)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
						.addComponent(btnNewButton)
						.addComponent(btnNewButton_1))
					.addContainerGap(60, Short.MAX_VALUE))
		);
		contentPane.setLayout(gl_contentPane);
		
		this.setLocationRelativeTo(null);
	}

	protected void ResetActionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		this.username_txt.setText("");
		this.password_txt.setText("");
		
		
	}

	protected void LoginActionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		
		String username=this.username_txt.getText();
		String password=new String(this.password_txt.getPassword());
		
		if(StringUtil.isEmpty(username)) {
			JOptionPane.showMessageDialog(null, "用户名不能为空");
			return;
		}
		
		if(StringUtil.isEmpty(password)) {
			JOptionPane.showMessageDialog(null, "密码不能为空");
			return;
		}
		
		User user=new User(username,password);
		Connection conn=null;
		try {
			conn=db.getConnection();
			User current_user=userDao.login(conn,user);
			if(current_user!=null) {
				JOptionPane.showMessageDialog(null, "登录成功");
				dispose();
				new MainFrm().setVisible(true);
			}else {
				JOptionPane.showMessageDialog(null, "用户名或者密码错误");
			}
		} catch (Exception e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		
		
	}
}


Goods.java

package cn.com.model;

public class Goods {
	private Integer id;	
	private String name;
	private Integer number;
	private Float price;

	
	
	public Goods() {
		super();
		// TODO Auto-generated constructor stub
	}


	

	public Goods(String name, Integer number,  Float price) {
		super();		
		this.name = name;
		this.number = number;
		this.price = price;
	}




	public Integer getId() {
		return id;
	}



	public void setId(Integer id) {
		this.id = id;
	}

	
	public String getName() {
		return name;
	}



	public void setName(String name) {
		this.name = name;
	}


	public Integer getNumber() {
		return number;
	}



	public void setNumber(Integer number) {
		this.number = number;
	}



	



	public Float getPrice() {
		return price;
	}



	public void setPrice(Float price) {
		this.price = price;
	}



	

	
	
	
}


四、其他

获取源码

点击以下链接获取源码,数据库文件在swing_goods.sql文件里面。
Java+Swing+Mysql实现超市商品管理系统源码

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

Java+Swing+Mysql实现图书管理系统源码

员工工资管理系统是一个常见的软件应用程序,可以帮助公司管理员工的基本信息、薪资、考勤、福利等方面的内容。本文将介绍如何使用 Eclipse+Java+Swing+Mysql 实现员工工资管理系统。 步骤1:创建数据库 首先,我们需要在 Mysql 中创建一个名为 salary 的数据库,并在其中创建三个表:employee、salary_record 和 department。 employee 表用于存储员工的基本信息,包括员工编号、姓名、性别、部门编号等字段。salary_record 表用于存储员工的薪资记录,包括员工编号、发放日期、基本工资、奖金、扣款等字段。department 表用于存储部门的基本信息,包括部门编号、部门名称等字段。 步骤2:创建 Java 项目 在 Eclipse 中创建一个新的 Java 项目,命名为 SalaryManagementSystem。在项目中创建三个包:entity、dao 和 view。 entity 包用于存储实体类,包括 Employee、SalaryRecord 和 Department 等类。dao 包用于存储数据访问对象,包括 EmployeeDao、SalaryRecordDao 和 DepartmentDao 等类。view 包用于存储界面类,包括 LoginFrame、MainFrame 和 AddEmployeeFrame 等类。 步骤3:编写实体类 在 entity 包中创建 Employee、SalaryRecord 和 Department 等类,并为每个类添加相应的属性和方法。例如,Employee 类包括员工编号、姓名、性别、所属部门等属性,以及获取和设置这些属性的方法。 步骤4:编写数据访问对象 在 dao 包中创建 EmployeeDao、SalaryRecordDao 和 DepartmentDao 等类,并实现相应的数据访问方法。例如,EmployeeDao 类包括添加员工、删除员工、更新员工信息、查询员工信息等方法。 步骤5:编写界面类 在 view 包中创建 LoginFrame、MainFrame 和 AddEmployeeFrame 等类,并实现相应的界面和事件处理方法。例如,LoginFrame 类用于显示登录界面,并处理用户登录事件;AddEmployeeFrame 类用于显示添加员工界面,并处理添加员工事件。 步骤6:连接数据库 使用 JDBC 连接 Mysql 数据库,为每个数据访问对象创建相应的连接和预编译语句,实现数据库的增删改查操作。 步骤7:测试程序 在 Eclipse 中运行程序,测试各个功能是否正常。例如,登录功能、员工信息查询功能、添加员工功能等。 总结 本文介绍了如何使用 Eclipse+Java+Swing+Mysql 实现员工工资管理系统。通过实现实体类、数据访问对象和界面类等模块,实现对员工信息、薪资、部门信息等数据的管理。这个项目可以作为 Java 开发入门的练手项目,帮助初学者熟悉 Java 开发、Swing 界面设计和 Mysql 数据库操作等技术。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

reg183

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值