java写登陆注册代码 java实现注册登录( 二 )


p
input type="radio" name="user" value="https://www.04ip.com/post/read"/读者nbsp;nbsp;nbsp;nbsp;
input type="radio" name="user" value="https://www.04ip.com/post/admin"/管理员
/pbr/
p
input type="button" value="https://www.04ip.com/post/确定" style="width: 50px;" onclick="put()"/nbsp;nbsp;nbsp;nbsp;
input type="reset" value="https://www.04ip.com/post/重置" style="width: 50px;"/
/p
/form
/div
/div
div id="bottom"欣欣科技有限公司版权所有/div
/body
script type="text/javascript" src="/images/defaultpic.gif"/script
script type="text/javascript" src="/images/defaultpic.gif"/script
script
//验证用户名和密码
function put(){
var d = $("#selectdivinput");//获取用户名和密码
var name = d[0].value;
var pass = d[1].value;
var user = null;
var r = document.getElementsByName("user");//获取用户类型
for(i=0;ir.length;i++){
if(r[i].checked){
user=r[i].value;
}
}
//console.log(name + "," +pass + "," +user);//输出测试
if(user==null){
window.alert("请选择用户类型!");
}else if(user=="admin"name!="admin"){
window.alter("用户名错误!");
}else if(user=="admin"name=="admin"pass!="123456"){
window.alert("密码错误!");
}else if(name=="admin"pass=="123456"user=="admin"){
window.location.href="https://www.04ip.com/post/work_02_welcome.html";//在js中在本页面中打开新链接
}else{
window.alert("用户名错误");
}
}
/script
/html
如何用Java编写用户注册界面?界面建议用可视化来做java写登陆注册代码,美观且便捷 。下面这个是完全用代码写java写登陆注册代码的,仅供参考 。\x0d\x0aimport javax.swing.*;\x0d\x0aimport java.awt.event.*;\x0d\x0aimport java.awt.*;\x0d\x0aimport java.sql.*;\x0d\x0apublic class Register extends JFrame {\x0d\x0a JLabel jl1 = new JLabel("用户名");\x0d\x0a JTextField jt1 = new JTextField();\x0d\x0a JLabel jl2 = new JLabel("邮箱");\x0d\x0a JTextField jt2 = new JTextField();\x0d\x0a JLabel jl3 = new JLabel("密码");\x0d\x0a JPasswordField jpw1 = new JPasswordField();\x0d\x0a JLabel jl4 = new JLabel("密码确认");\x0d\x0a JPasswordField jpw2 = new JPasswordField();\x0d\x0a JButton register = new JButton("注册");\x0d\x0a JButton clean = new JButton("清空");\x0d\x0a public Register(){\x0d\x0asetLayout(new GridLayout(5,2));\x0d\x0aadd(jl1);\x0d\x0aadd(jt1);\x0d\x0aadd(jl2);\x0d\x0aadd(jt2);\x0d\x0aadd(jl3);\x0d\x0aadd(jpw1);\x0d\x0aadd(jl4);\x0d\x0aadd(jpw2);\x0d\x0aadd(register);\x0d\x0aadd(clean);\x0d\x0aString name = jt1.getText();\x0d\x0aString email = jt2.getText();\x0d\x0aString pw = jpw1.getText();\x0d\x0aregister.addActionListener(new ActionListener(){\x0d\x0apublic void actionPerformed(ActionEvent e){\x0d\x0atry{\x0d\x0aClass.forName("com.mysql.jdbc.Driver");\x0d\x0aConnection con = DriverManager.getConnection("jdbc:mysql://localhost/db","root","");\x0d\x0aStatement sta = con.createStatement();\x0d\x0asta.executeUpdate("INSERT INTO register VALUES(name,email,pw)");\x0d\x0aJOptionPane.showMessageDialog(null,"注册成功","提示",JOptionPane.INFORMATION_MESSAGE);\x0d\x0a}\x0d\x0acatch(Exception ex){\x0d\x0aex.getStackTrace();\x0d\x0a}\x0d\x0a}\x0d\x0a});\x0d\x0aclean.addActionListener(new ActionListener(){\x0d\x0apublic void actionPerformed(ActionEvent e){\x0d\x0ajt1.setText("");\x0d\x0ajt2.setText("");\x0d\x0ajpw1.setText("");\x0d\x0ajpw2.setText("");\x0d\x0a}\x0d\x0a});\x0d\x0a }\x0d\x0a public static void main(String[] args){\x0d\x0aRegister frame = new Register();\x0d\x0aframe.setTitle("用户注册");\x0d\x0aframe.setLocationRelativeTo(null);\x0d\x0aframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);\x0d\x0aframe.setSize(400,400);\x0d\x0aframe.setVisible(true);\x0d\x0a }\x0d\x0a}
登陆界面的java代码怎么写?import java.awt.*; \x0d\x0aimport javax.swing.*; \x0d\x0aimport java.awt.event.*; \x0d\x0aimport java.sql.*; \x0d\x0a\x0d\x0aclass LoginFrm extends JFrame implements ActionListener \x0d\x0a{ \x0d\x0aJLabel lbl1=new JLabel("用户名"); \x0d\x0aJLabel lbl2=new JLabel("密码"); \x0d\x0aJTextField txt=new JTextField(15); \x0d\x0aJPasswordField pf=new JPasswordField(); \x0d\x0aJButton btn1=new JButton("确定"); \x0d\x0aJButton btn2=new JButton("取消"); \x0d\x0a\x0d\x0apublic LoginFrm() \x0d\x0a{ \x0d\x0athis.setTitle("登陆"); \x0d\x0aJPanel jp=(JPanel)this.getContentPane(); \x0d\x0ajp.setLayout(new GridLayout(3,2,10,10)); \x0d\x0ajp.add(lbl1);jp.add(txt); \x0d\x0ajp.add(lbl2);jp.add(pf); \x0d\x0ajp.add(btn1);jp.add(btn2); \x0d\x0abtn1.addActionListener(this); \x0d\x0abtn2.addActionListener(this); \x0d\x0a} \x0d\x0a\x0d\x0apublic void actionPerformed(ActionEvent ae) \x0d\x0a{ \x0d\x0aif(ae.getSource()==btn1) \x0d\x0a{ \x0d\x0atry \x0d\x0a{ \x0d\x0aClass.forName("sun.jdbc.odbc.JdbcOdbcDriver"); \x0d\x0aConnection con=DriverManager.getConnection("jdbc:odbc:MyDB","",""); \x0d\x0aStatement cmd=con.createStatement(); \x0d\x0aResultSet rs=cmd.executeQuery("select * from loginAndpassword where login='"+txt.getText()+"' and password='"+pf.getText()+"'"); \x0d\x0aif(rs.next()) \x0d\x0a{ \x0d\x0aJOptionPane.showMessageDialog(null,"登陆成功!"); \x0d\x0a} \x0d\x0aelse \x0d\x0aJOptionPane.showMessageDialog(null,"用户名或密码错误!"); \x0d\x0a} catch(Exception ex){} \x0d\x0a\x0d\x0aif(ae.getSource()==btn2) \x0d\x0a{ \x0d\x0atxt.setText(""); \x0d\x0apf.setText(""); \x0d\x0a} \x0d\x0a} \x0d\x0a} \x0d\x0a\x0d\x0apublic static void main(String arg[]) \x0d\x0a{ \x0d\x0aJFrame.setDefaultLookAndFeelDecorated(true); \x0d\x0aLoginFrm frm=new LoginFrm(); \x0d\x0afrm.setSize(400,200); \x0d\x0afrm.setVisible(true); \x0d\x0a} \x0d\x0a}

推荐阅读