Java拼图游戏

代码:

public Swingtest002() {
        // 设置标题
        setTitle("请登陆");
        // 绝对布局
        setLayout(null);
        // 定义一个容器
        Container c = getContentPane();
        // 创建"用户名:"标签
        JLabel jl1 = new JLabel("用户名:");
        // 创建文本框
        final JTextField jtf1 = new JTextField();
        // 创建"密码:"标签
        JLabel jl2 = new JLabel("密码:");
        // 创建密码框
        final JPasswordField jpf1 = new JPasswordField();
        // 设置密码字符为*
        jpf1.setEchoChar('*');
        // 创建"提交"按钮
        JButton jb1 = new JButton("提交");
        // 创建"重置"按钮
        JButton jb2 = new JButton("重置");
        
        // 当用户名为"mr",密码为"mrsoft"时点击"提交"按钮弹出"登录成功"提示对话框
        jb1.addActionListener(new ActionListener() {
 
            @Override
            public void actionPerformed(ActionEvent e) {
 
                String  name=(String)jtf1.getText().trim();
                String  password=new String(jpf1.getText().trim());
                String sql="select * from user where name='"+name+"' and pass='"+password+"'";
            System.out.println("name"+name+"password"+password);
                // TODO Auto-generated method stub
                try {
                    ResultSet rs=st.executeQuery(sql);
                    if (rs.next()) {
                        JOptionPane.showMessageDialog(null, "登陆成功!");
                        this.setVisible(false);//关闭当前的窗体
                    
                        MainFrame  mainframe=new MainFrame();
                    
                        
                        
                    } else if (jtf1.getText().trim().length() == 0 || new String(jpf1.getPassword()).trim().length() == 0) {
                        JOptionPane.showMessageDialog(null, "不能为空!");
                    } else {
                        JOptionPane.showMessageDialog(null, "错误");
                        // 清零
                        jtf1.setText("");
                        jpf1.setText("");
                    }
                } catch (HeadlessException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                } catch (SQLException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }
 
            }
 
            private void setVisible(boolean b) {
                // TODO Auto-generated method stub
                
            }
        });

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值