java注册代码
跑这儿作家庭作业了? 如果连用哪种页面技术都不知道提的话,恐怕别人给你源代码你也看不懂哦,想想别人给你个tapestry、Wicket之类的写的代码,拿给老师肯定挨批的哟(一看就露馅了)。
㈡ 如何用Java编写用户注册界面
界面建议用可视化来做,美观且便捷。下面这个是完全用代码写的,仅供参考。
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.sql.*;
public class Register extends JFrame {
JLabel jl1 = new JLabel("用户名");
JTextField jt1 = new JTextField();
JLabel jl2 = new JLabel("邮箱");
JTextField jt2 = new JTextField();
JLabel jl3 = new JLabel("密码");
JPasswordField jpw1 = new JPasswordField();
JLabel jl4 = new JLabel("密码确认");
JPasswordField jpw2 = new JPasswordField();
JButton register = new JButton("注册");
JButton clean = new JButton("清空");
public Register(){
setLayout(new GridLayout(5,2));
add(jl1);
add(jt1);
add(jl2);
add(jt2);
add(jl3);
add(jpw1);
add(jl4);
add(jpw2);
add(register);
add(clean);
String name = jt1.getText();
String email = jt2.getText();
String pw = jpw1.getText();
register.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/db","root","");
Statement sta = con.createStatement();
sta.executeUpdate("INSERT INTO register VALUES(name,email,pw)");
JOptionPane.showMessageDialog(null,"注册成功","提示",JOptionPane.INFORMATION_MESSAGE);
}
catch(Exception ex){
ex.getStackTrace();
}
}
});
clean.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
jt1.setText("");
jt2.setText("");
jpw1.setText("");
jpw2.setText("");
}
});
}
public static void main(String[] args){
Register frame = new Register();
frame.setTitle("用户注册");
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400,400);
frame.setVisible(true);
}
}
㈢ 求一个java注册登录的完整代码
public class Test extends JFrame
{
UserCertification uc;
String url;
Connection con;
public Test(String title)
{
setTitle(title);
uc=new UserCertification();
Container c=getContentPane();
c.setLayout(new BorderLayout());
c.add(uc,BorderLayout.CENTER);
setSize(400,250);
try
{
url="jdbc:odbc:aaa";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection(url);
uc.jtusername.setText("恭喜!数据库连接成功!");
}
catch(Exception e)
{
e.printStackTrace();
}
show();
}
public static void main(String args[])
{
Test test=new Test("登录界面");
test.addWindowListener(new MyWindowListener());
}
}
class UserCertification extends JPanel
{
㈣ 用JAVA编写一个用户或注册登录界面。请哪位高手能够写下具体的代码,谢谢
效果图
html"><!DOCTYPEhtml>
<html>
<head>
<metacharset="UTF-8">
<title>先锋图书馆管理系统-登录</title>
<style>
*{
margin:0;
padding:0;
list-style:none;
}
#top{
width:1000px;
height:95px;
margin:0auto;
margin-top:25px;
}
#top_top{
width:1000px;
height:65px;
background:deepskyblue;
}
#top_top_left{
width:300px;
height:65px;
float:left;
}
#top_top_left>label{
width:200px;
height:65px;
color:white;
float:right;
}
#top_top_left>#a2{
padding-left:10px;
padding-top:20px;
font-size:16px;
}
#top_bottom{
width:1000px;
height:30px;
}
#top_bottom_left{
width:340px;
height:30px;
line-height:30px;
font-size:12px;
background:skyblue;
color:white;
text-indent:2em;
float:left;
}
#top_bottom_right{
width:660px;
height:30px;
line-height:30px;
font-size:12px;
color:blueviolet;
text-align:center;
float:right;
background:lightskyblue;
}
#content{
width:1000px;
height:600px;
margin:0auto;
background:#587FBA;
}
#content>#text{
width:1000px;
height:50px;
line-height:50px;
padding-top:100px;
font-size:36px;
font-family:"楷体";
font-weight:bold;
text-align:center;
}
#content>#login{
width:480px;
height:210px;
margin-top:20px;
margin-left:260px;
background:#85A0CB;
}
#content>#login>img{
float:left;
}
#content>#login>#select{
width:305px;
height:210px;
float:right;
}
#content>#login>#select>div{
width:230;
height:30px;
margin-left:30px;
}
#content>#login>#select>#d1{
margin-top:30px;
margin-bottom:3px;
}
#content>#login>#select>p{
font-size:14px;
margin-left:95px;
}
#bottom{
width:1000px;
height:35px;
line-height:35px;
margin:0auto;
background:deepskyblue;
text-align:center;
color:white;
}
</style>
</head>
<body>
<divid="top">
<divid="top_top">
<divid="top_top_left">
<imgsrc="img/test/a13.png"width="78px"height="65px"><labelid="a2">先锋图书馆系统管理平台</label>
</div>
</div>
<divid="top_bottom">
<divid="top_bottom_left">当前位置:首页>系统管理>登录</div>
<divid="top_bottom_right">当前时间:<labelid="lable"></label></div>
</div>
</div>
<divid="content">
<divid="text">欢迎登录先锋图书馆管理系统</div>
<divid="login">
<imgsrc="img/test/a14.png"width="175px"height="210px"/>
<formid="select">
<divid="d1">用户名: <inputtype="text"/></div>
<div>密 码: <inputtype="password"/></div>
<p>
<inputtype="radio"name="user"value="read"/>读者
<inputtype="radio"name="user"value="admin"/>管理员
</p><br/>
<p>
<inputtype="button"value="确定"style="width:50px;"onclick="put()"/>
<inputtype="reset"value="重置"style="width:50px;"/>
</p>
</form>
</div>
</div>
<divid="bottom">欣欣科技有限公司版权所有</div>
</body>
<scripttype="text/javascript"src="JQuery/jquery.js"></script>
<scripttype="text/javascript"src="js/GetCurrentTime.js"></script>
<script>
//验证用户名和密码
functionput(){
vard=$("#select>div>input");//获取用户名和密码
varname=d[0].value;
varpass=d[1].value;
varuser=null;
varr=document.getElementsByName("user");//获取用户类型
for(i=0;i<r.length;i++){
if(r[i].checked){
user=r[i].value;
}
}
//console.log(name+","+pass+","+user);//输出测试
if(user==null){
window.alert("请选择用户类型!");
}elseif(user=="admin"&&name!="admin"){
window.alter("用户名错误!");
}elseif(user=="admin"&&name=="admin"&&pass!="123456"){
window.alert("密码错误!");
}elseif(name=="admin"&&pass=="123456"&&user=="admin"){
window.location.href="work_02_welcome.html";//在js中在本页面中打开新链接
}else{
window.alert("用户名错误");
}
}
</script>
</html>
㈤ java编写一个登陆和注册信息的源代码,最简单的就可以,不需要数据库的那种
。。。不需要数据库,还要进行存储,好吧,我还真没这么尝试过,这是要存储为txt文件么⊙﹏⊙b。。。
㈥ java注册页面代码
很简单,
建一个叫student的对象,然后给他几个属性。
存在一个list里就行了,
登录的时候就便利这个list,发现有一样的,就给他进去,没有就报错。
你用可以存key和valu的容器也行。
㈦ 用Java编写注册登录程序
什么都不说了 直接给你代码吧
package com.moliying.ui;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.List;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Arrays;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class Login {
private JFrame frame = new JFrame("登录");
private Container c = frame.getContentPane();
private JTextField username = new JTextField();
private JPasswordField password = new JPasswordField();
private JButton ok = new JButton("确定");
private JButton cancel = new JButton("取消");
public Login() {
frame.setSize(300, 200);
frame.setBounds(450, 300, 300, 200);
c.setLayout(new BorderLayout());
initFrame();
frame.setVisible(true);
}
private void initFrame() {
// 顶部
JPanel titlePanel = new JPanel();
titlePanel.setLayout(new FlowLayout());
titlePanel.add(new JLabel("系统管理员登录"));
c.add(titlePanel, "North");
// 中部表单
JPanel fieldPanel = new JPanel();
fieldPanel.setLayout(null);
JLabel a1 = new JLabel("用户名:");
a1.setBounds(50, 20, 50, 20);
JLabel a2 = new JLabel("密 码:");
a2.setBounds(50, 60, 50, 20);
fieldPanel.add(a1);
fieldPanel.add(a2);
username.setBounds(110, 20, 120, 20);
password.setBounds(110, 60, 120, 20);
fieldPanel.add(username);
fieldPanel.add(password);
c.add(fieldPanel, "Center");
// 底部按钮
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new FlowLayout());
buttonPanel.add(ok);
buttonPanel.add(cancel);
c.add(buttonPanel, "South");
ok.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.out.println(username.getText().toString());
}
});
cancel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
frame.setVisible(false);
}
});
}
public static void main(String[] args) {
// new Login();
String ss = "abbabbbaabbbccba";
System.out.println(ss.split("b").length);
}
}
㈧ 用java编程实现用户注册并进行登录操作
String username = "",password = "",passwordagain = ""; // 定义用户名和密码
将该变量等于为全局变量 或局部变量即可
㈨ 用java写界面注册怎么写
package com.demo.client;
import java.awt.GridLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.*;public class RegistFrame extends JFrame implements ActionListener{
String serverIp = null;
int port = 0;
String strSex = "";
int PswProtectNum;
String area = "";
JLabel labUserId;
JLabel labChatname;
JLabel labPsw;
JLabel labRePsw;
JLabel labPswQst;
JLabel labPswAns;
JLabel labAge;
JLabel labArea;
JLabel labSex;
JTextField txtUserID;
JTextField txtChatname;
JPasswordField txtPsw;
JPasswordField txtRePsw;
JComboBox comPswQst;
JTextField txtPswAns;
JTextField txtAge;
JComboBox comArea;
JRadioButton rad1,rad2,rad3;
JButton btnSubmit;
JButton btnCancel;
JPanel p0,p1,p3,p4,p5,p6,p7,p8,p9,p10;
ItemListener listener1 = new ItemListener() { public void itemStateChanged(ItemEvent e) {
// TODO Auto-generated method stub
JRadioButton button = (JRadioButton)e.getItemSelectable();
if (button == rad1)strSex = "男";
if (button == rad2)strSex = "女";
if (button == rad3)strSex = "";
}
};
ItemListener listener2 = new ItemListener() { public void itemStateChanged(ItemEvent e) {
// TODO Auto-generated method stub
JComboBox box = (JComboBox)e.getItemSelectable();
if(box == comPswQst){
PswProtectNum = comPswQst.getSelectedIndex();
}
if(box == comArea){
area = comArea.getSelectedItem().toString();
}
}
};
public RegistFrame(String serverIp,int port) {
this.serverIp = serverIp;
this.port = port;
p0 = new JPanel();
labUserId = new JLabel("*帐号:");
txtUserID = new JTextField(20);
txtUserID.setEditable(true);
p0.add(labUserId);
p0.add(txtUserID);
p1 = new JPanel();
labChatname = new JLabel("*昵称:");
txtChatname = new JTextField(20);
txtChatname.setEditable(true);
p1.add(labChatname);
p1.add(txtChatname);
p3 = new JPanel();
labPsw = new JLabel("*请输入密码:");
txtPsw = new JPasswordField(20);
p3.add(labPsw);
p3.add(txtPsw);
p4 = new JPanel();
labRePsw = new JLabel("*请再次输入密码:");
txtRePsw = new JPasswordField(20);
p4.add(labRePsw);
p4.add(txtRePsw);
p5 = new JPanel();
labPswQst = new JLabel("请设定密码保护问题:");
String [] strQst = {
"",
"您母亲的姓名是?",
"您父亲的职业是?",
"您配偶的生日是?",
"您的学号(工号)是?",
"您母亲的生日是?",
"您高中班主任的姓名是?",
"您父亲的姓名是?",
"您的出生地是?",
"您小学班主任的姓名是?",
"您配偶的姓名是?"
};
comPswQst = new JComboBox(strQst);
comPswQst.addItemListener(listener2);
p5.add(labPswQst);
p5.add(comPswQst);
p6 = new JPanel();
labPswAns = new JLabel("请设定密码保护答案:");
txtPswAns = new JTextField(20);
p6.add(labPswAns);
p6.add(txtPswAns);
p7 = new JPanel();
labAge = new JLabel("您的性别是:");
rad1 = new JRadioButton("我是帅哥!");
rad1.addItemListener(listener1);
rad2 = new JRadioButton("我是美女!");
rad2.addItemListener(listener1);
rad3 = new JRadioButton("我不告诉你!");
rad3.addItemListener(listener1);
ButtonGroup group = new ButtonGroup();
group.add(rad1);
group.add(rad2);
group.add(rad3);
p7.add(labAge);
p7.add(rad1);
p7.add(rad2);
p7.add(rad3);
p8 = new JPanel();
labArea = new JLabel("请选择您的地区:");
String [] strArea = {
"我是南方人",
"我是北方人",
"我是东北人",
"我是西北人",
"我是西南人"
};
comArea = new JComboBox(strArea);
comArea.addItemListener(listener2);
p8.add(labArea);
p8.add(comArea);
p9 = new JPanel();
labAge = new JLabel("您的年龄是:");
txtAge = new JTextField(15);
p9.add(labAge);
p9.add(txtAge);
p10 = new JPanel();
btnSubmit = new JButton("提交");
btnSubmit.addActionListener(this);
btnCancel = new JButton("取消");
btnCancel.addActionListener(this);
p10.add(btnSubmit);
p10.add(btnCancel);
getContentPane().setLayout(new GridLayout(10,1));
getContentPane().add(p0);
getContentPane().add(p1);
getContentPane().add(p3);
getContentPane().add(p4);
getContentPane().add(p5);
getContentPane().add(p6);
getContentPane().add(p7);
getContentPane().add(p8);
getContentPane().add(p9);
getContentPane().add(p10);
setTitle("注册新用户");
pack();
setResizable(false);
setDefaultCloseOperation(RegistFrame.DISPOSE_ON_CLOSE);
Toolkit tk=Toolkit.getDefaultToolkit();
setLocation((tk.getScreenSize().width-getSize().width)/2,(tk.getScreenSize().height-getSize().height)/2);
setVisible(true);
}
public void actionPerformed(ActionEvent e){
JButton button1 = (JButton)e.getSource();
//JRadioButton button2 = (JRadioButton)e.getSource();
if(button1 == btnSubmit){
if(txtUserID.getText().length() == 0
|| txtChatname.getText().length() == 0
|| txtUserID.getText().length() == 0
|| txtPsw.getPassword().length == 0){
JOptionPane.showMessageDialog(null, "昵称,用户名,密码都不能为空!",
"警告", JOptionPane.WARNING_MESSAGE);
}
else
if(!txtPsw.getText().equals(txtRePsw.getText())){
JOptionPane.showMessageDialog(null, "再次密码输入不一致!",
"警告", JOptionPane.WARNING_MESSAGE);
}
else {
addNewUser();
}
}
if(button1 == btnCancel){
dispose();
}
}
//处理注册用户
private void addNewUser(){
//代码请自己编写
}
public static void main(String []args){
new RegistFrame("127.0.0.1",2345);
}
}
㈩ java用户注册界面实现,下面代码哪错了呢
Exception in thread "main" java.lang.: 2
at wyf.jc.child.<init>(child.java:22)
at wyf.jc.child.main(child.java:66)
数组越界异常!!!好好检查下
还有这一句 :
else if{
jlArray[4].setText("正在注册中");
这个if后没跟条件