javaswing仓库商品管理系统java swing mysql实现的仓库商品管理系统源码和导入文档(1001)

发布于:2022-12-29 ⋅ 阅读:(213) ⋅ 点赞:(0)

目录

1.系统运行环境

2.系统功能介绍

3.项目结构和问题略讲

3.1 乱码问题

3.2 如何将GBK编码系统修改为UTF-8编码的系统?

3.3 项目结构

3.4 项目修改

 3.5 项目运行

 3.6 代码略讲

4.总结


1.系统运行环境

        运行环境:Java8 + MySQL8  

        开发工具:eclipse/idea 

2.系统功能介绍

(下面介绍的功能肯定都有,没有介绍的功能肯定没有!)

        系统采用模拟MVC三层进行开发,这样方便项目进行修改或者二次开发!

        数据库:三张表分别是用户表、仓库表、商品表

        功能:两种角色管理员用户
                  普通用户登录:查看商品信息、查询仓库信息及个人信息维护;
                  管理员登录:可以管理用户、仓库、商品等基本信息
                                        用户管理:增加、删除、修改、查看
                                        商品模块:增加、删除、修改、查看
                                        仓库管理:增加、删除、修改、查看

3.项目结构和问题略讲

3.1 乱码问题

        系统开发时的编码为GBK,因此导入eclipse时,也需要eclipse工作空间的编码为GBK

        修改编码:点击Window->Preference->General->workplace,然后选择默认编码方式 GBK。

       错误做法:开始将系统导入,出现乱码的问题,然后去修改eclipse的编码,这样有的   时候并不能修乱码的问题!需要将项目删除掉,                            然后修改eclipse的工作空   间编码,再次导入系统才能修改掉乱码!

3.2 如何将GBK编码系统修改为UTF-8编码的系统

        需要靠我们勤劳的双手,嘿嘿嘿......

        将系统文件复制一份,然后将eclipse的工作空间编码修改为UTF-8,导入系统;eclipse里面文件与原来文件进行一一比对,修改

        Ctrl +c 和ctrl + v

        除此之外,我目前还不知道如何一步修改,嘿嘿嘿......

3.3 项目结构

com.system.bean包:实体包,在有些情况下也写成entity或者pojo,相当于model持 久层

com.system.dao包:操作数据库的JDBC包,相当于model持久层

com.system.util包:工具包

com.system.view包:swing类包,相当于view视图层

MVC设计模式中:M是指业务模型,V是指用户界面,C则是控制器

你想问:这不是没有控制器层?

我:阿巴阿巴......确实没有

3.4 项目修改

在com.system.util包下面的DB类中,里面包含的一些数据库连接的基本信息,PASS变量需要修改成自己的数据库密码

 3.5 项目运行

在com.system.view包下面的Login类,main函数就在这个类里面,然后点击右键就可以运行

 3.6 代码略讲

public class Login extends JFrame {

	private JPanel contentPane;
	private JTextField usernameField;
	private JPasswordField passwordField;
	private User user = new User();

	/**
	 * Launch the application.
	 * 创作:码不停手
	 */
	public static void main(String[] args) {
		
	}

	/**
	 * Create the frame.
	 */
	public Login() {
                /*下面这些都是swing里面的一些button按钮样式等等,这里就省略*/
		setTitle("仓库管理系统");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 743, 538);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JPanel panel = new JPanel();
		panel.setBackground(Color.BLACK);
		panel.setBounds(0, 0, 391, 527);
		contentPane.add(panel);
		panel.setLayout(null);
		
		JLabel lblNewLabel = new JLabel("New label");
		lblNewLabel.setIcon(new ImageIcon(Login.class.getResource("/img/login.jpg")));
		lblNewLabel.setBounds(0, 0, 391, 382);
		panel.add(lblNewLabel);
		
		JLabel lblNewLabel_1 = new JLabel("仓库管理系统");
		lblNewLabel_1.setHorizontalAlignment(SwingConstants.CENTER);
		lblNewLabel_1.setFont(new Font("微软雅黑", Font.BOLD, 20));
		lblNewLabel_1.setForeground(Color.WHITE);
		lblNewLabel_1.setBounds(76, 416, 237, 51);
		panel.add(lblNewLabel_1);
		
		JPanel panel_1 = new JPanel();
		panel_1.setBackground(Color.WHITE);
		panel_1.setBounds(390, 0, 378, 527);
		contentPane.add(panel_1);
		panel_1.setLayout(null);
		
		JLabel lblNewLabel_2 = new JLabel("用户名:");
		lblNewLabel_2.setFont(new Font("微软雅黑", Font.BOLD, 16));
		lblNewLabel_2.setBounds(32, 76, 221, 33);
		panel_1.add(lblNewLabel_2);
		
		usernameField = new JTextField();
		usernameField.setBounds(32, 119, 221, 33);
		panel_1.add(usernameField);
		usernameField.setColumns(10);
		
		JLabel lblNewLabel_2_1 = new JLabel("密码:");
		lblNewLabel_2_1.setFont(new Font("微软雅黑", Font.BOLD, 16));
		lblNewLabel_2_1.setBounds(32, 177, 221, 33);
		panel_1.add(lblNewLabel_2_1);
		
		passwordField = new JPasswordField();
		passwordField.setBounds(32, 220, 221, 33);
		panel_1.add(passwordField);
		
		JLabel lblNewLabel_2_1_1 = new JLabel("用户类型:");
		lblNewLabel_2_1_1.setFont(new Font("微软雅黑", Font.BOLD, 16));
		lblNewLabel_2_1_1.setBounds(32, 282, 221, 33);
		panel_1.add(lblNewLabel_2_1_1);
		
                /*多选框*/
		JComboBox comboBox = new JComboBox(new String[]{"管理员","普通用户"} );
		comboBox.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				if(comboBox.getSelectedItem().equals("管理员")){
					user.setFlag("2");
				}else{
					user.setFlag("1");
				}
			}
		});
		comboBox.setBounds(32, 325, 221, 33);
		panel_1.add(comboBox);
		
		JButton btnNewButton = new JButton("登录");
                /**给按钮绑定事件
                *  当点击按钮时,进行查询数据库,判断用户名和密码是否正确
                *  然后给出相应的提示
                **/
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
                                //获取上面输入框里面的数值
				String username = usernameField.getText();
				String password = passwordField.getText();
				
				user.setusername(username);
				user.setuserpwd(password);
				
				
				LoginUseImp l = new LoginUseImp();
				String state = user.getFlag();
				if(state != "1" && state != "2") {
					state = "2";
				}
				if(state == "2") {
					try {
                                              //这里进行传入sql语句,进行连接数据库
                                              // flag 字段就是判断用户名和密码是否正确
						boolean flag = l.Query(user, "select * from users where username=? and userpwd=? and flag="+state);
						if(flag) {
							JOptionPane.showMessageDialog(null, "登陆成功");
							setVisible(false);
							//切换页面
							new Bg(user).setVisible(true);
						} else {
							JOptionPane.showMessageDialog(null, "登陆失败,请检查用户名和密码");
							usernameField.setText("");
							passwordField.setText("");
						}
					} catch (SQLException e1) {
						e1.printStackTrace();
					}
			} else if(state == "1") {
				try {
					boolean flag = l.Query(user, "select * from users where username=? and userpwd=? and flag="+state);
					if(flag) {
						JOptionPane.showMessageDialog(null, "登陆成功");
						setVisible(false);	
						//切换页面
						new BgUser(user).setVisible(true);
	
					} else {
						JOptionPane.showMessageDialog(null, "登陆失败,请检查用户名和密码");
						usernameField.setText("");
						passwordField.setText("");
					}
				} catch (SQLException e1) {
					
					e1.printStackTrace();
				}
			}
				
			}
		});
		btnNewButton.setBackground(Color.BLUE);
		btnNewButton.setForeground(Color.DARK_GRAY);
		btnNewButton.setFont(new Font("微软雅黑", Font.BOLD, 16));
		btnNewButton.setBounds(32, 404, 221, 33);
		panel_1.add(btnNewButton);
	}
}

显示界面

 问:就这?就这是代码讲解?为啥不多写注释?

 我:阿巴阿巴,你知道头发对少年有多么重要吗?

        熬不了夜了,白天没时间,晚上又想休息,产生了矛盾,

        我要开始表演了,还不快去搬凳子

        矛盾双方相互排斥、相互分离的属性、趋势,又叫"斗争性",吧啦吧啦.......

        (想当年背考研政治,一只单身狗,在图书馆的大厅,早晚每天嗷嗷叫,嗷......)

4.下载地址

点击下载


网站公告

今日签到

点亮在社区的每一天
去签到