基于 Eclipse+Java Swing + Mysql 进销存(物资)管理系统

这是一个使用Java Swing和Mysql8.0数据库构建的进销存管理系统,包括登录、用户管理、商品管理和进销存操作。文章展示了各功能界面,并提供了主要代码片段。此外,还提及了其他基于Java Swing的管理系统。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、项目概要:
        基于Java Swing+Mysql8.0数据库的物资(进销存)管理系统,具备登录功能。以及用户管理、商品进数据管理、进销存管理功能。
二、界面展示:

登录界面:

主界面:

商品管理界面:

进销存管理界面:

 三、主要代码:

 1)、登录

package com.bj.frame;


import java.awt.Font;
import java.awt.Image;

import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.File;
import java.io.IOException;
import java.util.Map;

import javax.imageio.ImageIO;
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.UIManager;

import com.bj.entity.User;
import com.bj.factory.ServiceFactory;
import com.bj.util.MD5Code;
import com.bj.util.MyFont;

@SuppressWarnings("serial")
public class LoginJFrame extends JFrame implements MouseListener, FocusListener{
	

	
	// 定义全局组件
	JTextField id = new JTextField(20);
	JPasswordField password = new JPasswordField(20);
	JPanel  backgroundPanel = null;
	JButton button_minimize, button_close, button_login, button_reset;
	
	public LoginJFrame() {
		try {
			Image imgae = ImageIO.read(new File("image/logo.png"));
			this.setIconImage(imgae);
		} catch (IOException e) {
			e.printStackTrace();
		}
		backgroundPanel = new JPanel();
		backgroundPanel.setBackground(UIManager.getColor("Button.background"));
		backgroundPanel.setLayout(null);

		id.setBounds(62, 102, 195, 42);
		id.setFont(MyFont.Static);
		id.setText("账号");
		id.addFocusListener(this);


		password.setBounds(62, 154, 195, 42);
		password.setFont(MyFont.Static);
		password.addFocusListener(this);
		password.setText("密码");
		password.setEchoChar('\0');


		

		button_login = new JButton("登录");
		button_login.setBounds(62, 222, 70, 27);
		button_login.setFont(MyFont.Static);
		button_login.addMouseListener(this);

		button_reset = new JButton("重置");
		button_reset.setBounds(187, 222, 70, 27);
		button_reset.addMouseListener(this);
		button_reset.setFont(MyFont.Static);

		backgroundPanel.add(id);
		backgroundPanel.add(password);
		backgroundPanel.add(button_login);
		backgroundPanel.add(button_reset);

		getContentPane().add(backgroundPanel);
		
		JLabel lblNewLabel = new JLabel("\u7528\u6237\u767B\u9646");
		lblNewLabel.setFont(new Font("微软雅黑", Font.BOLD, 24));
		lblNewLabel.setBounds(101, 50, 96, 42);
		backgroundPanel.add(lblNewLabel);
		this.setTitle("物资管理系统");
		this.setSize(310, 380);
		this.setVisible(true);
		this.requestFocus();
		this.setLocationRelativeTo(null);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setResizable(false);
		}
	
		
	@Override
	public void mouseClicked(MouseEvent e) {
		Map<String, Object> map;
		if (e.getSource() == button_login) {
			if ("账号".equals(id.getText())) {
				JOptionPane.showMessageDialog(null, "账号不能为空");
			} else if ("密码".equals(new String(password.getPassword()))) {
				JOptionPane.showMessageDialog(null, "密码不能为空");
			} else {
				String un =id.getText();
				String pw =new MD5Code().getMD5ofStr(new String(password.getPassword()));
				User user = new User();
				user.setId(un);
				user.setPassword(pw);
				
				try {
					map = ServiceFactory.getUserServiceInstance().login(user);
					boolean flag = (Boolean) map.get("flag");
					if (flag) { // 账号密码正确,表示登录成功
						User vo = (User)map.get("user");
						this.setVisible(false);
						new IndexJFrame(vo);
					}else { // 登录失败
						JOptionPane.showMessageDialog(null, "账号密码有误");
					}
				} catch (Exception e2) {
					
					e2.printStackTrace();
				}
				
			}
		} else if (e.getSource() == button_reset) {
			id.setText("账号");
			password.setText("密码");
			password.setEchoChar('\0');
		}

	}
	
	//聚焦事件
	@Override
	public void focusGained(FocusEvent e) {
		if (e.getSource() == id) {
			if (id.getText().equals("账号")) {
				id.setText("");
			}
		} else if (e.getSource() == password) {
			if (new String(password.getPassword()).equals("密码"
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

落寞秋雨

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

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

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

打赏作者

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

抵扣说明:

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

余额充值