JOptionPane.showMessageDialog窗口无法弹出

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

public class Systems extends JFrame implements ActionListener {
    static  Systems ss;
    JPanel panel=new JPanel();
    JLabel label1=new JLabel("账号:");
    JTextField id=new JTextField();
    JLabel label2=new JLabel("密码:");
    JPasswordField pwd=new JPasswordField();
    JButton Enter=new JButton("登录");
    JButton Exit=new JButton("退出");
    ButtonGroup bgp=new ButtonGroup();
    JRadioButton use=new JRadioButton("用户");
    JRadioButton adm=new JRadioButton("管理员");
    public Systems(){
        super("二手车登陆系统");
        this.setResizable(false);
        use.setBounds(165,210,70,20);
        adm.setBounds(265,210,70,20);
        bgp.add(use);
        bgp.add(adm);
        panel.add(use);
        panel.add(adm);
        Enter.setBounds(150,250,80,20);
        Exit.setBounds(270,250,80,20);
        Enter.addActionListener(this);
        Exit.addActionListener(this);
        panel.add(Enter);
        panel.add(Exit);
        panel.setLayout(null);
        this.add(panel);
        label1.setBounds(135,130,100,25);
        panel.add(label1);
        id.setBounds(265,130,100,25);
        panel.add(id);
        label2.setBounds(135,165,100,25);
        panel.add(label2);
        pwd.setBounds(265,165,100,25);
        panel.add(pwd);
        this.setBounds(100,100,500,350);
        this.setVisible(true);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    public void actionPerformed(ActionEvent e) {
        if(e.getSource()==Enter){
            String userid,password;
            userid=id.getText();
            password=new String(pwd.getPassword());
            try{
                Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            }
            catch (ClassNotFoundException ce){
                JOptionPane.showMessageDialog(ss,ce.getMessage());
            }
            if(use.isSelected()) {
                try {
                    Connection con = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;", "sa", "liu872603526");
                    Statement stmt = con.createStatement();
                    ResultSet rs = stmt.executeQuery("select *from Users");
                    while (rs.next()) {
                        if (rs.getString("Uid").equals(userid)) {
                            if ((rs.getString("Upass").equals(password))) {
                                JOptionPane.showMessageDialog(ss, "登陆成功");
                                new User();
                            } else {
                                JOptionPane.showMessageDialog(ss, "登录失败");
                            }
                            rs.close();
                            stmt.close();
                        }
                    } }catch(SQLException se){
                        JOptionPane.showMessageDialog(ss, se.getMessage());
                    }
                }
            else if(adm.isSelected()){
                try{
                    Connection con=DriverManager.getConnection("jdbc:sqlserver://localhost:1433;","sa","liu872603526");
                    Statement stmt=con.createStatement();
                    ResultSet rs=stmt.executeQuery("select *from Admin");
                    while(rs.next()){
                        if(rs.getString("Aid").equals(userid))
                            if((rs.getString("Apass").equals(password))){
                                JOptionPane.showMessageDialog(ss,"登陆成功");
                                new Admins();
                            }
                            else{
                                JOptionPane.showMessageDialog(ss,"登陆失败");
                            }
                    }
                }
                catch (SQLException se) {
                    JOptionPane.showMessageDialog(ss,se.getMessage());
                }
            }
        }
        else{
            System.exit(0);
        }
    }
    public static void main(String[] args){
        new Systems();
    }
}

点击登录按钮没反应,程序也没有报错

 

查看全部
qq_46190382
神经细胞qwer
2021/01/14 01:02
  • java
  • 点赞
  • 收藏
  • 回答
    私信

1个回复