GUI实现超市管理系统

1.技术介绍
java+swing+mysql
2.主要功能说明:
登录
1)管理员
员工信息管理(新增、修改、删除、查询)
顾客信息管理(新增、修改、删除、查询)
2)收银员
分为会员收银和非会员收银
添加商品、查询商品、删除商品、对商品进行结算、清空
3)商品管理员
查询所有商品、更新库存信息、新增商品、删除商品
3.核心代码实现:

public class Test {
	public static void main(String[] args) {
		Login login = new Login();
		login.setVisible(true);
	}
}
public class Login extends JFrame {

	private JPanel contentPane;
	private JTextField userName;
	private JTextField pwd;
	private int roleId = 0;

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

	/**
	 * Create the frame.
	 */
	public Login() {
		this.setTitle("超市管理系统");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(400, 200, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblNewLabel = new JLabel("用户名:");
		lblNewLabel.setBounds(82, 52, 54, 15);
		contentPane.add(lblNewLabel);
		
		userName = new JTextField();
		userName.setBounds(186, 49, 141, 21);
		contentPane.add(userName);
		userName.setColumns(10);
		
		JLabel label = new JLabel("密码:");
		label.setBounds(82, 98, 54, 15);
		contentPane.add(label);
		
		pwd = new JTextField();
		pwd.setColumns(10);
		pwd.setBounds(186, 95, 141, 21);
		contentPane.add(pwd);
		
		JLabel label_1 = new JLabel("管理员类别:");
		label_1.setBounds(82, 144, 79, 15);
		contentPane.add(label_1);
		
		final JComboBox comboBox = new JComboBox();
		comboBox.setModel(new DefaultComboBoxModel(new String[] {"主管理员", "商品管理员", "收银员"}));
		comboBox.addItemListener(new ItemListener() {
			@Override
			public void itemStateChanged(ItemEvent e) {
				if(ItemEvent.SELECTED==e.getStateChange()){
					//String item = (String) comboBox.getSelectedItem();
					roleId = comboBox.getSelectedIndex();
				}
			}
		});
		comboBox.setBounds(186, 144, 79, 21);
		contentPane.add(comboBox);
		
		JButton button = new JButton("登录");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String UserName = userName.getText();
				String Pwd = pwd.getText();
				UsersService user = new UsersService();
				if(user.checkUsersService(UserName, Pwd, roleId)){
					Login.this.dispose();
					if(roleId == 0){
						RootAdministrator ra = new RootAdministrator();
						ra.setVisible(true);
					}else if(roleId == 1){
						GoodsAdministrator ga = new GoodsAdministrator();
						ga.setVisible(true);
					}else if(roleId == 2){
						UsersService us = new UsersService();
						int userId = 0;
						userId = us.getUserIdByUserNameService(UserName);
						Cashier c = new Cashier(userId);
						c.setVisible(true);
					}
				}else{
					JOptionPane.showMessageDialog(Login.this, "登陆失败!");
				}
			}
		});
		button.setBounds(100, 193, 93, 23);
		contentPane.add(button);
		
		JButton button_1 = new JButton("退出");
		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Login.this.dispose();
			}
		});
		button_1.setBounds(224, 193, 93, 23);
		contentPane.add(button_1);
	}
}
public class CustomerManagement extends JFrame {

	private JPanel contentPane;
	private JTable table;

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

	/**
	 * Create the frame.
	 */
	public CustomerManagement() {
		this.setTitle("顾客信息管理");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(400, 200, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBounds(10, 58, 414, 165);
		contentPane.add(scrollPane);
		
		String[] cols={"会员编号","会员用户名","会员联系方式","会员积分"};
		final DefaultTableModel model = new DefaultTableModel(cols,0);
		table = new JTable(model);
		CustomerService cs = new CustomerService();
		List<Customers> rows = cs.getAllCustomersService();
		for (Customers customers : rows) {
			Object[] row = {customers.getCustomerNo(),customers.getCustomerName(),customers.getPhone(),customers.getScore()};
			model.addRow(row);
		}
		scrollPane.setViewportView(table);
		
		JButton button = new JButton("新增");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				CustomerManagement.this.dispose();
				NewCustomer nc = new NewCustomer();
				nc.setVisible(true);
			}
		});
		button.setBounds(214, 25, 93, 23);
		contentPane.add(button);
		
		JButton button_1 = new JButton("删除");
		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int rowIndex = table.getSelectedRow();
				if(rowIndex<0){
					JOptionPane.showMessageDialog(CustomerManagement.this, "请选择要删除的行","错误提示",JOptionPane.ERROR_MESSAGE);
				}else{
					String cstNo = (String) model.getValueAt(rowIndex, 0);
					if(JOptionPane.showConfirmDialog(CustomerManagement.this, "确定删除第"+(rowIndex+1)+"行?")==0){
						CustomerService cs = new CustomerService();
						if(cs.deleteCustomersService(cstNo)){
							JOptionPane.showMessageDialog(CustomerManagement.this, "删除成功!");
							CustomerManagement.this.dispose();
							CustomerManagement frame = new CustomerManagement();
							frame.setVisible(true);
						}
					}
				}
			}
		});
		button_1.setBounds(331, 25, 93, 23);
		contentPane.add(button_1);
		
		JButton button_2 = new JButton("返回主管理员界面");
		button_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				CustomerManagement.this.dispose();
				RootAdministrator ra = new RootAdministrator();
				ra.setVisible(true);
			}
		});
		button_2.setBounds(279, 233, 145, 26);
		contentPane.add(button_2);
	}
}

系统演示视频:
链接:https://pan.baidu.com/s/1kfXU0L3HS8SQ1s3sJKCG6g
提取码:uajh

  • 0
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值