GUI实现超市管理系统
1.技术介绍
java+swing+mysql
2.主要功能说明:
登录
1)管理员
员工信息管理(新增、修改、删除、查询)
顾客信息管理(新增、修改、删除、查询)
2)收银员
分为会员收银和非会员收银
添加商品、查询商品、删除商品、对商品进行结算、清空
3)商品管理员
查询所有商品、更新库存信息、新增商品、删除商品
3.核心代码实现:
```java
public class Test {
public static void main(String[] args) {
Login login = new Login();
login.setVisible(true);
}
}
```
```java
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);
}
}
```
```java
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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY