| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 5401 人关注过本帖
标题:java登录注册详细代码
只看楼主 加入收藏
maidou_code
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2016-9-7
结帖率:0
收藏
已结贴  问题点数:20 回复次数:8 
java登录注册详细代码
新手
搜索更多相关主题的帖子: java 
2016-09-19 18:10
反脑控2016
Rank: 4
等 级:业余侠客
威 望:2
帖 子:108
专家分:212
注 册:2016-9-2
收藏
得分:4 
看我在这个论坛发的第一个帖子吧

我学编程,总爱用自己的语言将所学的东西描述下来,渐渐的,一篇篇的文章,看起来像一个个杰作。
2016-09-24 23:38
LGing
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:32
专家分:107
注 册:2015-3-15
收藏
得分:4 
空手套代码
2016-09-25 16:44
吃货丶
Rank: 2
等 级:论坛游民
帖 子:14
专家分:41
注 册:2016-8-24
收藏
得分:4 
真的是醉了,不劳而获...
2016-09-26 18:04
zwx419685574
Rank: 1
来 自:上海
等 级:新手上路
帖 子:2
专家分:4
注 册:2016-9-25
收藏
得分:0 
2016-09-26 22:00
天马星空ss
Rank: 2
等 级:论坛游民
帖 子:8
专家分:26
注 册:2016-9-28
收藏
得分:4 
要的是java代码?
2016-09-28 10:52
liujinyong19
Rank: 2
等 级:论坛游民
帖 子:4
专家分:14
注 册:2012-11-28
收藏
得分:4 
登陆----
输入用户名,密码,点击登陆,验证
注册---
输入用户名,ajax验证是否存在,输入密码,保存
中间再加上你的js验证和服务端验证
2016-09-29 17:15
lidisi9510
Rank: 1
等 级:新手上路
帖 子:11
专家分:7
注 册:2016-9-28
收藏
得分:0 
百度上面搜索一大把,还在论坛里面问这个问题。我也是醉了~
2016-09-30 16:01
好学
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
帖 子:622
专家分:318
注 册:2004-5-4
收藏
得分:0 
程序代码:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Login {
    private JFrame jf;
    private Container con;
    private JPanel userJPanel, passJPanel, regJPanel;
    private JLabel userJLabel, passJLabel;
   

    private JTextField userJtf;
    private JPasswordField passJtf;
    private JButton login;
   

    public void init() {
        jf = new JFrame("登录");
        con = jf.getContentPane();
        con.setLayout(new GridLayout(5, 1));
       

        userJLabel = new JLabel("用户名:");
        userJtf = new JTextField(10);
        userJPanel = new JPanel();
        userJPanel.add(userJLabel);
        userJPanel.add(userJtf);
       

        passJLabel = new JLabel("密 码:");
        passJtf = new JPasswordField(10);
        passJPanel = new JPanel();
        passJPanel.add(passJLabel);
        passJPanel.add(passJtf);
       

   

   

        login = new JButton("登陆");
        login.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent e) {
                    String userName = userJtf.getText();
                    String pwd = new String(passJtf.getPassword());
                    User user = new User();
                    user.setUserName(userName);
                    user.setPwd(pwd);
                    LoginService service = new LoginService();
                    boolean b = service.login(user);
                    if(b) {
                        JOptionPane.showMessageDialog(jf, "登录成功");
                       

                    } else {
                        JOptionPane.showMessageDialog(jf, "登录失败");
                    }
                }
            });
        regJPanel = new JPanel();
       

        regJPanel.add(login);
       

        con.add(userJPanel);
        con.add(passJPanel);
       

        con.add(regJPanel);
       

        jf.setSize(300, 300);
        jf.setVisible(true);
    }
    public static void main(String[] args) {
        Login login = new Login();
        login.init();

    }
   

}

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Register {
    private JFrame jf;
    private Container con;
    private JPanel userJPanel, passJPanel, spassJPanel, regJPanel, msgJPanel;
    private JLabel userJLabel, passJLabel, spassJLabel;
    private JLabel msg;
    private JTextField userJtf;
    private JPasswordField passJtf, spassJtf;
    private JButton reset, register;
   

    public void init() {
        jf = new JFrame("注册");
        con = jf.getContentPane();
        con.setLayout(new GridLayout(5, 1));
       

        userJLabel = new JLabel("用户名:");
        userJtf = new JTextField(10);
        userJPanel = new JPanel();
        userJPanel.add(userJLabel);
        userJPanel.add(userJtf);
       

        passJLabel = new JLabel("密 码:");
        passJtf = new JPasswordField(10);
        passJPanel = new JPanel();
        passJPanel.add(passJLabel);
        passJPanel.add(passJtf);
       

        spassJLabel = new JLabel("确认密码:");
        spassJtf = new JPasswordField(10);
        spassJPanel = new JPanel();
        spassJPanel.add(spassJLabel);
        spassJPanel.add(spassJtf);
       

        msg = new JLabel();
        msgJPanel = new JPanel();
        msgJPanel.add(msg);
       

        reset = new JButton("清空");
        reset.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent e){
                        userJtf.setText("");
                        passJtf.setText("");
                        spassJtf.setText("");
                    }
            });
        register = new JButton("注册");
        register.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent e){
                    String pass = new String(passJtf.getPassword());
                    String spass= new String(spassJtf.getPassword());
                    if(!pass.equals(spass)) {
                        msg.setText("两次密码输入不一致");
                        return ;
                    }

                   

                    String userName = userJtf.getText();
                    User user = new User();
                    user.setUserName(userName);
                    user.setPwd(pass);
                    RegisterService service = new RegisterService();
                    service.register(user);
                    msg.setText("注册成功");
                }
            });
        regJPanel = new JPanel();
        regJPanel.add(reset);
        regJPanel.add(register);
       

        con.add(userJPanel);
        con.add(passJPanel);
        con.add(spassJPanel);
        con.add(msgJPanel);
        con.add(regJPanel);
       

        jf.setSize(300, 300);
        jf.setVisible(true);
    }
    public static void main(String[] args) {
        Register ref = new Register();
        ref.init();

    }
   

}







import *;
public class RegisterService{
    private static final String FILE_PATH = "c:\\user.txt";
    public void register(User user) {
        //获取到用户名和密码
        //存储到文件当中
        String msg = user.getUserName() + "," + user.getPwd();
        BufferedWriter bw = null;
        try {
            bw = new BufferedWriter(new FileWriter(FILE_PATH));
            bw.write(msg);
            bw.flush();
        }
        catch (IOException ex) {
            ex.printStackTrace();
        } finally  {
            try{
                if(bw != null)
                    bw.close();   

            }catch(IOException e) {
                e.printStackTrace();
            }
           

        }
       

    }
}



public class User {
    private String userName;
    private String pwd;
   

    public void setUserName(String userName) {
        this.userName = userName;
    }
    public String getUserName() {
        return this.userName;
    }
    public void setPwd(String pwd) {
        this.pwd = pwd;
    }
    public String getPwd() {
        return this.pwd;
    }
}



import *;
public class LoginService {
    private static final String FILE_PATH = "c:\\user.txt";
    public boolean login(User user) {
        //获取文件当中存储的用户名和密码
        //与参数(前台)传递来的用户名和密码进行匹配
        try {
            BufferedReader br = new BufferedReader(new FileReader(FILE_PATH));
            String msg = br.readLine();
            br.close();
            if(msg == null) {
                return false;
            }
            String[] temp = msg.split(",");
            return temp[0].equals(user.getUserName()) && temp[1].equals(user.getPwd());
        }
        catch (Exception ex) {
            return false;
        }
       

    }
}




2016-09-30 16:07
快速回复:java登录注册详细代码
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.048670 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved