a881205172822 2024-01-09 21:46 采纳率: 0%
浏览 7

超市收银系统java连接数据库


package com.yz.win;

import com.yz.util.JdbcUtil;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.*;

public class Login  {
    public Login(){
        JFrame jFrame=new JFrame();
        jFrame.setTitle("login");

        jFrame.setLayout(null);

        JButton jButton1=new JButton("登陆");
        JButton jButton2 = new JButton("退出");
        JLabel jLabel1 = new JLabel("账号");
        JLabel jLabel2 = new JLabel("密码");
        JLabel jLabel3 = new JLabel("收银员");
        JLabel jLabel4 = new JLabel("管理员");
        JTextArea jTextArea1 = new JTextArea();
        JTextArea jTextArea2 = new JTextArea();
        JRadioButton jRadioButton1 = new JRadioButton("管理员");
        JRadioButton jRadioButton2 = new JRadioButton("收银员");

        jRadioButton1.setSize(80,30);
        jRadioButton2.setSize(80,30);
        jRadioButton1.setLocation(150,250);
        jRadioButton2.setLocation(250,250);

        jLabel1.setSize(70,30);
        jLabel2.setSize(70,30);
        jLabel1.setLocation(100,100);
        jLabel2.setLocation(100,200);
        jLabel3.setSize(70,30);
        jLabel4.setSize(70,30);
        jLabel3.setLocation(100,250);
        jLabel4.setLocation(300,250);

        jButton1.setSize(70,30);
        jButton2.setSize(70,30);
        jButton1.setLocation(100,300);
        jButton2.setLocation(250,300);

        jTextArea1.setSize(130,20);
        jTextArea1.setLocation(180,100);
        jTextArea2.setSize(130,20);
        jTextArea2.setLocation(180,200);



        jFrame.add(jButton1);
        jFrame.add(jButton2);
        jFrame.add(jLabel1);
        jFrame.add(jLabel2);
        jFrame.add(jTextArea1);
        jFrame.add(jTextArea2);
        jFrame.add(jRadioButton1);
        jFrame.add(jRadioButton2);


        jFrame.setVisible(true);
        jFrame.setSize(500,500);
        jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        jFrame.setLocation(500,200);

        jButton1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String id=jTextArea1.getText().trim();
                String password=jTextArea2.getText().trim();
                Connection connection=JdbcUtil.getConnection();
                String sql="select * from staff where staffNo=?";
                PreparedStatement psta=null;
                ResultSet res=null;
                if (id.equals("") || password.equals("")) {
                    JOptionPane.showMessageDialog(jFrame, "用户信息不允许为空!");
                    return;
                }
                else {
                try {
                    psta=connection.prepareStatement(sql);
                    psta.setString(1,id);
                    res=psta.executeQuery();
                    while (res.next()){
                    if(password.equals(res.getString(7)))
                       if(jRadioButton1.isSelected()){
                           new AdminWin();
                           jFrame.dispose();
                           return;
                       }
                    else if (jRadioButton2.isSelected()){
                        new StaffWin();
                        jFrame.dispose();
                        return;
                    }
                    else {
                        JOptionPane.showMessageDialog(jFrame,"请选择身份!");
                    }
                    }

                } catch (SQLException e1) {
                    e1.printStackTrace();
                }
            }
            }
        });

        jButton2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                jFrame.dispose();
            }
        });

    }

    public static void main(String[] args) {
        new Login();
    }
}


这个超市收银的登陆的账号和密码怎么弄

  • 写回答

2条回答 默认 最新

  • Soulic 2024-01-10 07:04
    关注

    这个需要数据库的,在数据库中按要求创建表staff,并插入对应的用户数据

    评论

报告相同问题?

问题事件

  • 创建了问题 1月9日

悬赏问题

  • ¥15 python怎么在已有视频文件后添加新帧
  • ¥20 虚幻UE引擎如何让多个同一个蓝图的NPC执行一样的动画,
  • ¥15 fluent里模拟降膜反应的UDF编写
  • ¥15 MYSQL 多表拼接link
  • ¥15 关于某款2.13寸墨水屏的问题
  • ¥15 obsidian的中文层级自动编号
  • ¥15 同一个网口一个电脑连接有网,另一个电脑连接没网
  • ¥15 神经网络模型一直不能上GPU
  • ¥15 pyqt怎么把滑块和输入框相互绑定,求解决!
  • ¥20 wpf datagrid单元闪烁效果失灵