DC00019基于java swing+sqlserver超市商品信息管理系统java项目GUI商品信息管理系统

news2024/9/27 8:06:10

1、项目功能演示

DC00019基于java swing+sqlserver超市商品信息管理系统java项目GUI商品信息管理系统

2、项目功能描述

 基于java swing+sqlserver超市管理系统功能

1、系统登录
2、员工管理:添加员工、查询员工、所有员工
3、部门管理:添加部门、查询部门
4、商品管理:商品信息查询
5、销售管理:卖出商品、销售查询

3、项目功能截图

 

4、项目核心代码 

4.1  数据库操作类

package com.db;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.Reader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;

public class Jdbc {
	// 创建连接池
	public static Vector<Connection> connectionPool = new Vector<Connection>();
	// 在主函数运行之前创建好连接池
	static {
		String driver = "";
		String url = "";
		String username = "";
		String password = "";
		try {
			Reader read = new FileReader("src\\db.properties");
			BufferedReader bufferedReader = new BufferedReader(read);
			String line = bufferedReader.readLine();
			while (line != null) {
				String[] strings = line.split("=", 2);
				String key = strings[0];
				String value = strings[1];
				if ("username".equals(key)) {
					username = value;
				}
				if ("password".equals(key)) {
					password = value;
				}
				if ("driver".equals(key)) {
					driver = value;
				}
				if ("url".equals(key)) {
					url = value;
				}
				line = bufferedReader.readLine();
			}
			bufferedReader.close();
			read.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		try {
			Class.forName(driver);
			for (int i = 0; i < 10; i++) {
				Connection connection = DriverManager.getConnection(url,
						username, password);
				connectionPool.add(connection);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	// 取出连接
	public static Connection getConnection() {
		Connection connection = connectionPool.get(0);
		connectionPool.remove(0);
		return connection;
	}

	// 放回连接
	public static void releaseConnection(Connection connection) {
		connectionPool.add(connection);
	}

	// 增删改
	public static int zsg(String sql, Object... p) {
		Connection connection = getConnection();
		int n = 0;
		try {
			PreparedStatement preparedStatement = connection
					.prepareStatement(sql);
			for (int i = 0; i < p.length; i++) {
				preparedStatement.setObject(i + 1, p[i]);
			}
			n = preparedStatement.executeUpdate();

		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			releaseConnection(connection);
		}
		return n;
	}

	// 查詢
	public static ResultSet query(String sql, Object... p) {
		Connection connection = getConnection();
		ResultSet rs = null;
		try {
			PreparedStatement preparedStatement = connection
					.prepareStatement(sql);
			for (int i = 0; i < p.length; i++) {
				preparedStatement.setObject(i + 1, p[i]);
			}
			rs = preparedStatement.executeQuery();

		} catch (SQLException e) {
			e.printStackTrace();
		}
		return rs;
	}
}

4.2  登录窗口

package com.view;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.UnsupportedLookAndFeelException;

import com.control.CancelLoginListener;
import com.control.LoginActionListener;
import com.control.RandomNumberListener;

public class LoginView extends JFrame {
	
	private JLabel usernameJLabel, passwordJLabel;
	private JTextField usernameJTextField, passwordJTextField;
	private JButton loginButton, cancelButton;
	private JLabel randomNumber, randomNumberJLabel;
	private JTextField randomField;
	private Icon icon=new ImageIcon("src//Image//longin.jpg");
	private JLabel ImageLabel=new JLabel(icon);
	public LoginView() {
		// 设置容器属性
		setTitle("用户登录");
		setSize(650, 432);
		setLayout(null);
		setResizable(false);// 设置窗口的大小不能改变
		setLocationRelativeTo(null);
		// 初始化组件
		usernameJLabel = new JLabel("用戶名:");
		passwordJLabel = new JLabel("密    码:");
		usernameJTextField = new JTextField();
		passwordJTextField = new JPasswordField();
		randomNumber=new JLabel("验证码:");
		randomNumberJLabel=new JLabel("9527");
		randomField=new JTextField();
		cancelButton = new JButton("取消");
		loginButton = new JButton("登陆");

		// 地位组件

		usernameJLabel.setBounds(320, 170, 70, 20);
		usernameJTextField.setBounds(400, 170, 130, 20);
		passwordJLabel.setBounds(320, 220, 70, 20);
		passwordJTextField.setBounds(400, 220, 130, 20);
		randomNumber.setBounds(320, 270, 70, 20);
		randomNumberJLabel.setBounds(390, 270, 50, 20);
		randomField.setBounds(450, 270, 70, 20);
		cancelButton.setBounds(320, 320, 70, 20);
		loginButton.setBounds(450, 320, 70, 20);
		ImageLabel.setBounds(0, 0, 650, 432);
		add(usernameJLabel);
		add(usernameJTextField);
		add(passwordJLabel);
		add(passwordJTextField);
		add(randomNumber);
		add(randomNumberJLabel);
		add(randomField);
		add(cancelButton);
		add(loginButton);
		add(ImageLabel);
		loginButton.addActionListener(new LoginActionListener(this));
		randomNumberJLabel.addMouseListener(new RandomNumberListener(this));
		cancelButton.addActionListener(new CancelLoginListener(this));
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setVisible(true);

	}

	public JTextField getRandomField() {
		return randomField;
	}

	public void setRandomField(JTextField randomField) {
		this.randomField = randomField;
	}

	public JLabel getRandomNumber() {
		return randomNumber;
	}

	public void setRandomNumber(JLabel randomNumber) {
		this.randomNumber = randomNumber;
	}

	public JLabel getRandomNumberJLabel() {
		return randomNumberJLabel;
	}

	public void setRandomNumberJLabel(JLabel randomNumberJLabel) {
		this.randomNumberJLabel = randomNumberJLabel;
	}

	public JLabel getUsernameJLabel() {
		return usernameJLabel;
	}

	public void setUsernameJLabel(JLabel usernameJLabel) {
		this.usernameJLabel = usernameJLabel;
	}

	public JLabel getPasswordJLabel() {
		return passwordJLabel;
	}

	public void setPasswordJLabel(JLabel passwordJLabel) {
		this.passwordJLabel = passwordJLabel;
	}

	public JTextField getUsernameJTextField() {
		return usernameJTextField;
	}

	public void setUsernameJTextField(JTextField usernameJTextField) {
		this.usernameJTextField = usernameJTextField;
	}

	public JTextField getPasswordJTextField() {
		return passwordJTextField;
	}

	public void setPasswordJTextField(JTextField passwordJTextField) {
		this.passwordJTextField = passwordJTextField;
	}

	public JButton getLoginButton() {
		return loginButton;
	}

	public void setLoginButton(JButton loginButton) {
		this.loginButton = loginButton;
	}

	public JButton getCancelButton() {
		return cancelButton;
	}

	public void setCancelButton(JButton cancelButton) {
		this.cancelButton = cancelButton;
	}

	public static void main(String[] args) {
		
		try {
			javax.swing.UIManager.setLookAndFeel("com.jtattoo.plaf.bernstein.BernsteinLookAndFeel");
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (UnsupportedLookAndFeelException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		new LoginView();
		
	}


}

 4.3 主界面窗口

package com.view;

import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JLabel;

import com.control.CloseMainView;

public class MainView extends JFrame {
	


	private JLabel barLabel = new JLabel();
	private JLabel timejJLabel = new JLabel();

	// 创建内部窗体
	public static JDesktopPane rightDesktopPane = new JDesktopPane();
	JDesktopPaneTree jDesktopPaneTree = new JDesktopPaneTree();

	public MainView() {

		// 设计窗体属性
		setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
		setTitle("超市商品管理系统");
		setSize(950, 650);
		setLayout(null);
		setLocationRelativeTo(null);
		setResizable(false);// 设置窗口的大小不能改变

		rightDesktopPane.setOpaque(false);

		rightDesktopPane.setBounds(250, 30, 750, 590);

		barLabel.setBounds(700, 0, 200, 30);
		timejJLabel.setBounds(500, 555, 180, 20);
		jDesktopPaneTree.setBounds(0, 0, 250, 615);

		// 添加菜单
		add(barLabel);
		add(rightDesktopPane);
		add(jDesktopPaneTree);
		rightDesktopPane.add(timejJLabel);
		rightDesktopPane.setVisible(true);

		jDesktopPaneTree.setVisible(true);

		setVisible(true);
		addWindowListener(new CloseMainView());
	}

	public JLabel getBarLabel() {
		return barLabel;
	}

	public void setBarLabel(JLabel barLabel) {
		this.barLabel = barLabel;
	}

	public JDesktopPaneTree getjDesktopPaneTree() {
		return jDesktopPaneTree;
	}

	public void setjDesktopPaneTree(JDesktopPaneTree jDesktopPaneTree) {
		this.jDesktopPaneTree = jDesktopPaneTree;
	}
	public JLabel getTimejJLabel() {
		return timejJLabel;
	}

	public void setTimejJLabel(JLabel timejJLabel) {
		this.timejJLabel = timejJLabel;
	}

	public static JDesktopPane getRightDesktopPane() {
		return rightDesktopPane;
	}

	public static void setRightDesktopPane(JDesktopPane rightDesktopPane) {
		MainView.rightDesktopPane = rightDesktopPane;
	}
	public static void main(String[] args) {
		new MainView();
	}

}

4.4  登录窗口监听

package com.control;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.swing.JOptionPane;

import com.model.UserDao;
import com.view.LoginView;
import com.view.MainView;

public class LoginActionListener implements ActionListener {
	LoginView loginView;
	UserDao userDao1 = new UserDao();
	MainView mainView;

	public LoginActionListener(MainView mainView) {
		this.mainView = mainView;
	}

	//JDesktopPaneTree jDesktopPaneTree = new JDesktopPaneTree();

	public LoginActionListener(LoginView loginView) {
		this.loginView = loginView;
	}

	public void actionPerformed(ActionEvent e) {
		String username = loginView.getUsernameJTextField().getText();
		String password = loginView.getPasswordJTextField().getText();
		String s = loginView.getRandomNumberJLabel().getText();
		String s1 = loginView.getRandomField().getText();
		if (username.length() == 0) {
			JOptionPane.showMessageDialog(null, "用户名不能为空!");
			return;
		}
		if (password.length() == 0) {
			JOptionPane.showMessageDialog(null, "密码不能为空!");
			return;
		}
		if (s1.length() == 0) {
			JOptionPane.showMessageDialog(null, "请输入验证码!");
			return;
		}
		if (s1.equals(s)) {
			boolean b = userDao1.userDao(username, password);
			ResultSet rs = userDao1.getResultSet(username, password);
			Date date = new Date();
			SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH");
			int ss = Integer.parseInt(simpleDateFormat.format(date));

			if (b) {

				final MainView mainView = new MainView();// 登陆成功,跳转到主窗
				new Thread() {
					public void run() {
						while (true) {

							Date date = new Date();
							SimpleDateFormat simpleDateFormat = new SimpleDateFormat(
									"yyyy/MM/dd hh:mm:ss");
							String date1 = simpleDateFormat.format(date);

							mainView.getTimejJLabel().setText(date1);
							try {
								Thread.sleep(1000);
							} catch (InterruptedException e) {
								e.printStackTrace();
							}
						}

					}
				}.start();
				loginView.dispose();
					try {
						while (rs.next()) {
							if (ss > 0 && ss < 10) {
								
								mainView.getBarLabel().setText(
										"早上好!!!" + rs.getString(1));
								
							}
							if (ss >=10 && ss < 14) {
								mainView.getBarLabel().setText(
										"中午好!!!" + rs.getString(1));
							}
							if (ss >=14 && ss < 19) {
								mainView.getBarLabel().setText(
										"下午好!!!" + rs.getString(1));
							}
							if (ss >=19 && ss < 24) {
								mainView.getBarLabel().setText(
										"晚上好!!!" + rs.getString(1));
							}

						}
					} catch (SQLException e1) {
						e1.printStackTrace();
					}
			
			} else {
				JOptionPane.showMessageDialog(null, "用户名或密码错误!");
			}

		} else {
			JOptionPane.showMessageDialog(null, "验证码错误!");
		}

	}
}

 4.5 验证码监听

package com.control;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Random;

import com.view.LoginView;

public class RandomNumberListener implements MouseListener {
	LoginView loginView;

	public RandomNumberListener(LoginView loginView) {
		this.loginView = loginView;
	}

	public void mouseClicked(MouseEvent e) {
		String s = "abcdefghijklmnopqrstuvwxzyABCDEFGHIJKLMNOPQPSTWVWXYZ01234567890";
		Random random = new Random();
		char[] c = new char[4];
		for (int i = 0; i < 4; i++) {
			int intdex = random.nextInt(62);
			c[i] = s.charAt(intdex);			
		}
		loginView.getRandomNumberJLabel().setText(new String(c));
	}

	@Override
	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mousePressed(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub

	}

}

5、项目文件内容包含

6、项目获取 

6.1 方式一 

私聊或扫描下方名片联系获取项目文件。

6.2 方式二

点击此处直接获取项目文件。 

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2169406.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

数据结构 ——— 移除元素(快慢指针)

目录 题目要求 代码实现&#xff08;快慢指针&#xff09; 题目要求 编写函数&#xff0c;给你一个数组 nums 和一个值 val&#xff0c;你需要在 nums 数组 原地 移除所有数值等于 val 的元素&#xff0c;并且返回移除后数组的新长度 不能使用额外的数组空间&#xff0c;要…

SSM的学习(3)

项目的结构: 如下图所示。 对SqlMapConfig.xml的分析&#xff1a; 是主要的配置文件。里面写的是 数据的配置 1:引入jdbc.properties 这个里面写的是 账号和密码等信息&#xff0c;不在写在xml里面了&#xff0c;防止写死! 用的是<properties resource "这个外部…

将图片资源保存到服务器的盘符中

服务类 系统盘符&#xff1a;file-path.disk&#xff08;可能会变&#xff0c;配置配置文件dev中&#xff09;文件根路径&#xff1a;file-path.root-path&#xff08;可能会变&#xff0c;配置配置文件dev中&#xff09;http协议的Nginx的映射前缀&#xff1a;PrefixConstant.…

__问题——解决CLion开发Linux驱动时显示头文件缺失

问题描述&#xff1a; 在使用CLion开发Linux驱动时&#xff0c;需要引入各种头文件&#xff0c;比如<linux/module>、<linux/init>等&#xff0c;但是毫无例外&#xff0c;都会在报错提示文件或文件路径不存在。这在很大程度上限制了CLion的发挥&#xff0c;因为无…

【linux】gdb

&#x1f525;个人主页&#xff1a;Quitecoder &#x1f525;专栏&#xff1a;linux笔记仓 目录 01.gdb使用 01.gdb使用 程序的发布方式有两种&#xff0c;debug模式和release模式Linux gcc/g出来的二进制程序&#xff0c;默认是release模式要使用gdb调试&#xff0c;必须在源…

c语言200例 063 信息查询

大家好&#xff0c;欢迎来到无限大的频道。 今天给大家带来的是c语言200例 题目要求&#xff1a; 从键盘当中输入姓名和电话号&#xff0c;以“#”结束&#xff0c;编程实现输入姓名、查询电话号的功能。 参考代码如下&#xff1a; #include <stdio.h> #include <st…

1.6 判定表

欢迎大家订阅【软件测试】 专栏&#xff0c;开启你的软件测试学习之旅&#xff01; 文章目录 1 基本概念1.1 作用1.2 优点 2 基本组成2.1 条件桩2.2 动作桩2.3 条件项2.4 动作项 3 判定表的结构与规则3.1 规则的生成3.2 动作结果3.3 判定表简化 4 判定表的使用场景4.1 软件测试…

什么是Node.js?

为什么JavaScript可以在浏览器中被执行&#xff1f; 在浏览器中我们加载了一些待执行JS代码&#xff0c;这些字符串要当中一个代码去执行&#xff0c;是因为浏览器中有JavaScript的解析引擎&#xff0c;它的存在我们的代码才能被执行。 不同的浏览器使用不同的javaScript解析引…

Linux 文件目录结构(详细)

一、基本介绍 Linux的文件系统是采用级层式的树状目录结构&#xff0c;在此结构中的最上层是根目录“/”&#xff0c;然后在此目录下再创建其他的目录。 Linux世界中&#xff0c;一切皆文件&#xff01; 二、相关目录 /bin[常用](/usr/bin、/usr/local/bin) 是Binary的缩写,…

RabbitMQ常用管理命令及管理后台

RabbitMQ管理命令 1、用户管理1.1、新增一个用户1.2、查看当前用户列表1.3、设置用户角色1.4、设置用户权限1.5、查看用户权限 2、RabbitMQ的web管理后台2.1、查看rabbitmq 的插件列表2.2、启用插件2.3、禁用插件2.4、访问RabbitMQ的web后台2.4、通过web页面新建虚拟主机 ./rab…

LLM - 使用 vLLM 部署 Qwen2-VL 多模态大模型 (配置 FlashAttention) 教程

欢迎关注我的CSDN&#xff1a;https://spike.blog.csdn.net/ 本文地址&#xff1a;https://spike.blog.csdn.net/article/details/142528967 免责声明&#xff1a;本文来源于个人知识与公开资料&#xff0c;仅用于学术交流&#xff0c;欢迎讨论&#xff0c;不支持转载。 vLLM 用…

虚拟机开启网络代理设置,利用主机代理访问国外资源

前言 有时候需要访问一些镜像网站拉取安装包或是学习资料&#xff0c;由于国内外网络环境差异和网络安全的问题&#xff0c;总会被阻拦。下文来说一下虚拟机centos7如何通过连接主机的代理软件。 一、代理软件设置 1、前提是主机要安装有代理软件&#xff0c;查看代理软件的…

LabVIEW提高开发效率技巧----并行处理

在LabVIEW开发中&#xff0c;充分利用并行处理能力可以显著提高程序的执行效率和响应速度。LabVIEW的图形化编程模型天然支持并行任务的执行&#xff0c;可以通过以下几种方式优化程序性能。 1. 并行For循环&#xff08;Parallel For Loop&#xff09; 对于能够独立执行的任务…

开源鸿蒙OpenHarmony系统更换开机Logo方法,瑞芯微RK3566鸿蒙开发板

本文适用于开源鸿蒙OpenHarmony系统更换开机Logo&#xff0c;本次使用的是触觉智能的Purple Pi OH鸿蒙开源主板&#xff0c;搭载了瑞芯微RK3566芯片&#xff0c;类树莓派设计&#xff0c;是Laval官方社区主荐的一款鸿蒙开发主板。 介绍 OpenHarmony的品牌标志、版本信息、项目…

RabbitMQ 高级特性——重试机制

文章目录 前言重试机制配置文件设置生命交换机、队列和绑定关系生产者发送消息消费消息 前言 前面我们学习了 RabbitMQ 保证消息传递可靠性的机制——消息确认、持久化和发送发确认&#xff0c;那么对于消息确认和发送方确认&#xff0c;如果接收方没有收到消息&#xff0c;那…

每日一题:⻓度最⼩的⼦数组

文章目录 一、题目二、解析1、暴力算法&#xff08;1&#xff09;纯暴力&#xff08;2&#xff09;前缀和 循环 2、滑动窗口 一、题目 209. 长度最小的子数组 给定一个含有 n 个正整数的数组和一个正整数 target 。 找出该数组中满足其总和大于等于 target 的长度最小的 子数组…

Java项目实战II基于Java+Spring Boot+MySQL的IT技术交流和分享平台的设计与实现(源码+数据库+文档)

目录 一、前言 二、技术介绍 三、系统实现 四、文档参考 五、核心代码 六、源码获取 全栈码农以及毕业设计实战开发&#xff0c;CSDN平台Java领域新星创作者&#xff0c;专注于大学生项目实战开发、讲解和毕业答疑辅导。获取源码联系方式请查看文末 一、前言 在当今信息…

归并排序,外排序,计数排序(非比较排序)

归并排序&#xff1a;&#xff08;MERGE-SORT&#xff09;是建立在归并操作上的一种有效的排序算法,该算法是采用分治法&#xff08;Divide and Conquer&#xff09;的一个非常典型的应用。将已有序的子序列合并&#xff0c;得到完全有序的序列&#xff1b;即先使每个子序列有序…

Studying-图论包含的算法总结

目录 1.DFS&#xff08;深度优先搜索&#xff09; 代码框架&#xff1a; 2. BFS&#xff08;广度优先搜索&#xff09; 代码框架&#xff1a; 3. 并查集 4.最小生成树之Prim 5.最小生成树之Kruskal 6.拓扑排序 7. 最短路径之-dijkstra&#xff08;朴素版&#xff…

R语言非参数回归预测摩托车事故、收入数据:局部回归、核回归、LOESS可视化...

全文链接&#xff1a;https://tecdat.cn/?p37784 非参数回归为经典&#xff08;参数&#xff09;回归方法提供了一种灵活的替代方法。与假定回归关系具有依赖于有限数量的未知参数的已知形式的传统&#xff08;参数&#xff09;方法不同&#xff0c;非参数回归模型尝试从数据样…