当前位置:首页 » 编程语言 » java制作注册界面

java制作注册界面

发布时间: 2022-11-18 07:57:57

A. 用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);

}
}

B. 用java写一个手机商城注册界面代码

这篇文章主要介绍了java通过JFrame做一个登录系统的界面完整代码示例,具有一定借鉴价值,需要的朋友可以参考下。
在java的JFrame内通过创建匿名对象的方式做登录界面
package com.sxt;
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class LoginFrame extends JFrame{
JTextField txtname=new JTextField();
JPasswordField txtpass=new JPasswordField();
JButton bl=new JButton("登录");
JButton bg=new JButton("关闭");
//构造无参构造器把主要的方法放在构造器里,然后在main方法里面调
public LoginFrame(){
setBounds(25,25,250,250);
Container c = getContentPane();
c.setLayout(new GridLayout(4,2,10,10));
c.add(new JLabel("用户名"));
c.add(txtname);
c.add(new JLabel("密码"));
c.add(txtpass);
c.add(bl);
c.add(bg);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
//注意:此处是匿名内部类
bg.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
System.exit(0);
}
}
);
//注意:此处是匿名内部类
bl.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {

C. java 设计一个用户注册页面,页面内包含各类组件,组件的布局采用布局管理器类

/*
* 这是客户端的界面层
*/
package Client_View;

import java.awt.*;
import java.awt.event.*;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.*;

import Client_Model.*;
import Common.QQ_Message;
import Common.QQ_UserInformation;

public class Client_Login extends JFrame implements ActionListener {

JPanel jp1, jp2, jp3, jp4;
JLabel jl1;
JButton jb1, jb2, jb3;
ImageIcon image_icon1;

// 选项卡
JTabbedPane jtp1 = null;

// 定义中间的控件
JLabel jp2_jl1, jp2_jl2, jp2_jl3, jp2_jl4;
JTextField jp2_jtf1;
JPasswordField jp2_jpf1;
JCheckBox jp2_jcb1, jp2_jcb2;
JButton jp2_jb1;

public static void main(String[] args) {
Client_Login qqcv = new Client_Login();
}

// 构造函数,用来做界面
public Client_Login()
{
this.showNorth();
this.showCenter();
this.showSouth();

this.showJFrame();
}

// 这是做北面的布局
public void showNorth()
{
image_icon1 = new ImageIcon("image/tou.gif");
jl1 = new JLabel(image_icon1);
this.add(jl1, "North");
}

// 这是中间的布局
public void showCenter()
{
jtp1 = new JTabbedPane();
this.add(jtp1);

// 中间有三个JPanel,它们由一个JTabbedPane管理
jp2 = new JPanel();
jp2.setLayout(new GridLayout(3, 3));
jp3 = new JPanel();
jp4 = new JPanel();
jtp1.add(jp2, "QQ号码");
jtp1.add(jp3, "手机号码");// jp3和jp4分别代表另外两个面板,这两个面板没有去实现
jtp1.add(jp4, "电子邮件");// jp3和jp4分别代表另外两个面板,这两个面板没有去实现
// //////////////////////////////////////////////////////////////////
jp2_jl1 = new JLabel("QQ号码", JLabel.CENTER);
jp2_jl2 = new JLabel("QQ密码", JLabel.CENTER);
jp2_jl3 = new JLabel("忘记密码", JLabel.CENTER);
jp2_jl4 = new JLabel("申请密码保护", JLabel.CENTER);

jp2_jtf1 = new JTextField("1");//登陆框
jp2_jpf1 = new JPasswordField("111111");//密码框

jp2_jcb1 = new JCheckBox("隐身登陆");
jp2_jcb2 = new JCheckBox("记住密码");

jp2_jb1 = new JButton(new ImageIcon("image/clear.gif"));//清除号码按钮
jp2_jb1.addActionListener(this);

jp2.add(jp2_jl1);
jp2.add(jp2_jtf1);
jp2.add(jp2_jb1);
jp2.add(jp2_jl2);
jp2.add(jp2_jpf1);
jp2.add(jp2_jl3);
jp2.add(jp2_jcb1);
jp2.add(jp2_jcb2);
jp2.add(jp2_jl4);
}

// 这是南边的布局
public void showSouth()
{
jp1 = new JPanel();
this.add(jp1, "South");

jb1 = new JButton(new ImageIcon("image/denglu.gif"));//登陆按钮
jb1.addActionListener(this);
jb2 = new JButton(new ImageIcon("image/quxiao.gif"));//取消按钮
jb2.addActionListener(this);
jb3 = new JButton(new ImageIcon("image/xiang.gif"));//注册向导按钮
jb3.addActionListener(this);
jp1.add(jb1);
jp1.add(jb2);
jp1.add(jb3);
}

// 这是显示总体的窗体
public void showJFrame()
{
int hight=Toolkit.getDefaultToolkit().getScreenSize().height;
int width=Toolkit.getDefaultToolkit().getScreenSize().width;
this.setSize(350, 240);
this.setLocation((width-this.getWidth())/2,(hight-this.getHeight())/2);
this.setTitle("QQ登陆");

this.setResizable(false);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

// 发送登陆信息到客户端的Model层的函数
public boolean send_Login_Message_To_Model(QQ_UserInformation userinfo)
{
boolean b=false;
Client_Model cm=new Client_Model();
b=cm.send_Login_info_to_Client_net(userinfo);

return b;
}

@Override
public void actionPerformed(ActionEvent arg0)
{
if (arg0.getSource() == jp2_jb1)
{
// 点击清除号码按钮
jp2_jtf1.setText("");
jp2_jpf1.setText("");
}
if (arg0.getSource() == jb1)
{
// 点击登录按钮
QQ_UserInformation userinfo=new QQ_UserInformation();
userinfo.setUserID(jp2_jtf1.getText() );
userinfo.setPassword(new String (jp2_jpf1.getPassword()));
System.out.println("登陆界面。用户名: "+userinfo.getUserID()+", 密码: "+userinfo.getPassword());

boolean b=send_Login_Message_To_Model(userinfo);
System.out.println("客户端login界面,得到的登陆的信息: b = "+ b);
if(b==false)
{
//用户名密码错误,登陆失败
JOptionPane.showMessageDialog(null,"用户名或密码错误","登陆失败...",JOptionPane.ERROR_MESSAGE);

}else if(b==true)
{
Client_FriendsList cf=new Client_FriendsList(userinfo);
this.dispose();
}
}
if (arg0.getSource() == jb2)
{
// 点击取消按钮,关闭该窗口
this.dispose();
}
if (arg0.getSource() == jb3)
{
// 点击注册向导按钮,暂时没有去实现该功能
}
}
}

D. java编程:设计用户注册界面

有做好的要么连mysql数据库

E. 用java web编写一个用户注册界面(只要写出以下要求就行)

一步步更新:页面
<form action="regist.servlet" method="post"><table width="99%" border="0" align="center" cellpadding="0" cellspacing="0" class="tableAdd borTop"> <tr> <th width="14%" height="30" nowrap>用户名</th> <td class="pl5"> <INPUT id="sName" name="name" type="text" size="20"> </td> </tr> <tr> <th width="14%" height="30" nowrap>密码</th> <td class="pl5"> <INPUT name="password" type="password" size="20"> </td> </tr> <tr> <th width="14%" height="30" nowrap>确认密码</th> <td class="pl5"> <INPUT name="confrimPwd" type="password" size="20"> </td> </tr> <tr> <th width="14%" height="30" nowrap>性别</th> <td class="pl5"> 男<INPUT name="sex" type="radio" value="1" checked="checked" size="20"> 女<INPUT name="sex" type="radio" value="0" size="20"> </td> </tr> <tr> <th width="14%" height="30" nowrap>爱好</th> <td class="pl5"> <INPUT name="enjoy" type="checkbox" size="20" value="篮球">篮球 <INPUT name="enjoy" type="checkbox" size="20" value="足球">足球 </td> </tr> <tr> <th width="14%" height="30" nowrap>生日</th> <td class="pl5"> <INPUT name="brithday" type="text" size="20"> </td> </tr> <tr> <th width="14%" height="30" nowrap>备注</th> <td class="pl5"> <textarea rows="5" cols="200" name="remark"></textarea> </td> </tr> <tr> <th width="14%" height="30" nowrap> </th> <td class="pl5"> <input type="submit" value="提交"> <input type="reset" value="重置"> </td> </tr></table></form>

数据库部分:
import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import com.mysql.jdbc.Connection;import com.mysql.jdbc.Statement;public class DataBaseUtil { public static Connection getConnection() throws ClassNotFoundException, SQLException { Class.forName("com.mysql.jdbc.Driver"); Connection conn = (Connection) DriverManager.getConnection("jdbc:mysql://192.168.100.113/datebase", "username", "password"); return conn; } public static Statement getPS() throws ClassNotFoundException, SQLException { Statement statement = (Statement) getConnection().createStatement(); return statement; } public static void close(Connection conn,Statement st,ResultSet rs) throws SQLException{ if(rs != null) { rs.close(); } if(st != null) { st.close(); } if(conn != null) { conn.close(); } }}

F. java编写登陆注册页面(简单一点的,连接数据库)

这是我自己做的一个管理系统的登录界面,代码虽然有点繁琐,不过简单易懂,你根据自己的需要进行修改吧。

import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.swing.JDialog;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

/**
*
* @author mzhe
*
*/

class Loginfrm extends JDialog implements ActionListener
{
JLabel l_name,l_pass,l_error;
JTextField t_name;
JButton b_enter,b_cancle,b_clear;
JPanel pan1,pan2,pan3,pan4;
JPasswordField t_pass;

String sname,spass;
int sunit;

NetConn sql;
Statement sqll;
ResultSet rs;

Librarybox lbox;

int until=0;

Loginfrm(JFrame f,String s)
{
//界面布局
super(f,s);
l_name=new JLabel("名字:");
l_pass=new JLabel("密码:");
l_error=new JLabel("请输入用户名和密码登录");
t_name=new JTextField("",10);
t_pass=new JPasswordField("",10);
t_pass.setEchoChar('*');
b_enter=new JButton("确定");
b_enter.addActionListener(this);
b_cancle=new JButton("取消");
b_cancle.addActionListener(this);
b_clear=new JButton("清除");
b_clear.addActionListener(this);
pan1=new JPanel();
pan2=new JPanel();
pan3=new JPanel();
pan4=new JPanel();
pan1.add(l_name);pan1.add(t_name);
pan2.add(l_pass);pan2.add(t_pass);
pan3.add(l_error);
pan4.add(b_enter);pan4.add(b_cancle);pan4.add(b_clear);
setLayout(new GridLayout(4,1));
add(pan1);add(pan2);add(pan3);add(pan4);
//建立数据库连接
sql=new NetConn();
//设置窗口大小
setSize(300,300);
setVisible(false);
//得到屏幕信息以便使框架居中显示
Dimension screeSize = Toolkit.getDefaultToolkit().getScreenSize();
int screeWidth=screeSize.width;
int screeHeight=screeSize.height;
//得到框架的大小信息
Dimension frameSize=this.getSize();
int x=(screeWidth-frameSize.width)/2;
int y=(screeHeight-frameSize.height)/2;
this.setLocation(x, y);
}
public void actionPerformed(ActionEvent e)
{
//单击确定按钮的事件处理程序
if(e.getSource()==b_enter)
{
//如果连续登录次数小于4
if(until<=4)
{
//如果用户名或者密码为空,将显示提示信息
if(t_name.getText().equals("")||t_pass.getText().equals(""))
{
l_error.setText("用户名和密码不能为空");
}
else
{
try
{

sqll=sql.connect();
//根据用户名查询
rs=sqll.executeQuery("SELECT * FROM users where username="+"'"+t_name.getText()+"'");
//遍历查询得到的结果集
while(rs.next())
{
sname=rs.getString(2);
spass=rs.getString(3);
//得到登录用户的级别
sunit=Integer.parseInt(rs.getString(4));
//如果密码正确
if(t_pass.getText().equals(spass))
{
//判断用户的级别,根据不同的级别,显示不同的菜单
switch(sunit)
{
case 1:
{
l_error.setText("登录成功");
t_name.setText("");
t_pass.setText("");
lbox=new Librarybox();
lbox.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
lbox.setResizable(false);
lbox.bookfi.setEnabled(true);
lbox.bookse.setEnabled(true);
lbox.bookth.setEnabled(true);
lbox.bookfo.setEnabled(true);
lbox.mi_system_manger.setEnabled(true);
lbox.mi_system_login.setEnabled(false);
lbox.setVisible(true);
this.dispose();
break;
}
case 2:
{
l_error.setText("登录成功");
t_name.setText("");
t_pass.setText("");
lbox=new Librarybox();
lbox.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
lbox.setResizable(false);
lbox.bookfi.setEnabled(false);
lbox.bookse.setEnabled(false);
lbox.bookth.setEnabled(true);
lbox.bookfo.setEnabled(false);
lbox.mi_system_manger.setEnabled(false);
lbox.mi_system_login.setEnabled(false);
lbox.setVisible(true);
this.dispose();
break;
}
case 3:
{
l_error.setText("登录成功");
t_name.setText("");
t_pass.setText("");
lbox=new Librarybox();
lbox.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
lbox.setResizable(false);
lbox.bookfi.setEnabled(true);
lbox.bookse.setEnabled(false);
lbox.bookth.setEnabled(false);
lbox.bookfo.setEnabled(true);
lbox.mi_system_manger.setEnabled(false);
lbox.mi_system_login.setEnabled(false);
lbox.fi_msglabel_user.setEnabled(false);
lbox.setVisible(true);
this.dispose();
break;
}
}
}
else
{
l_error.setText("用户名或密码错误!");
until++;
}

}

}
catch(SQLException e2)
{
e2.printStackTrace();
}

}
}
//超出登录次数
else
{
l_error.setText("你已经超出登录次数");
t_name.setEnabled(false);
t_pass.setEnabled(false);
b_enter.setEnabled(false);
b_clear.setEnabled(false);
}
}
//单击清除按钮的事件处理程序
else if(e.getSource()==b_clear)
{
t_name.setText("");
t_pass.setText("");
l_error.setText("请输入用户名和密码登录");
}
//单击取消按钮的事件处理程序
else if(e.getSource()==b_cancle)
{
dispose();

}
}

}

如果你比较认可的话,请采纳吧,不给分也没关系。只希望对你有用。

G. 用java设计一个注册界面,要求将注册信息利用输出流保存到本地txt文件

效果图

importjava.awt.*;
importjava.awt.event.*;
importjava.io.*;
importjavax.swing.*;

//该窗口继承自JFrame,实现了ActionListener接口
{
//定义需要的组件
JTextFieldjtfName,jtfEmail;
JPasswordFieldjpf;
JRadioButtonjrb1,jrb2;
JComboBox<String>jcb;
JButtonjbReset,jbSingUp;
//常量
staticfinalStringNEW_LINE=System.getProperty("line.separator");//获取系统的换行符
staticfinalStringFILE_PATH="d:/users.txt";//指定文件的路径

//构造器
publicSingUpFrame(){
JPaneljp1=newJPanel();
JLabeljl1=newJLabel("账号");
jtfName=newJTextField(15);
jp1.add(jl1);
jp1.add(jtfName);

JPaneljp2=newJPanel();
JLabeljl2=newJLabel("密码");
jpf=newJPasswordField(15);
jp2.add(jl2);
jp2.add(jpf);

JPaneljp3=newJPanel();
JLabeljl3=newJLabel("邮箱");
jtfEmail=newJTextField(15);
jp3.add(jl3);
jp3.add(jtfEmail);

JPaneljp4=newJPanel();
JLabeljl4=newJLabel("性别");
ButtonGroupbg=newButtonGroup();
jrb1=newJRadioButton("男");
jrb1.setSelected(true);//默认选中男性
jrb2=newJRadioButton("女");
bg.add(jrb1);
bg.add(jrb2);
jp4.add(jl4);
jp4.add(jrb1);
jp4.add(jrb2);

JLabeljl5=newJLabel("年龄");
String[]ary=newString[12];
for(inti=18;i<30;i++){//18~30可供选中的范围
ary[i-18]=i+"";
}
jcb=newJComboBox<String>(ary);
jp4.add(jl5);
jp4.add(jcb);

JPaneljpc=newJPanel(newGridLayout(4,1));//4行1列布局
jpc.add(jp1);
jpc.add(jp2);
jpc.add(jp3);
jpc.add(jp4);
add(jpc);

JPaneljps=newJPanel();
jbReset=newJButton("重填");
jbReset.addActionListener(this);//给按钮添加响应
jbSingUp=newJButton("确定");
jbSingUp.addActionListener(this);//给按钮添加响应
jps.add(jbReset);
jps.add(jbSingUp);
add(jps,BorderLayout.SOUTH);


setTitle("注册窗口");//窗口标题
setSize(300,285);//窗口大小
setLocationRelativeTo(null);//窗口居中
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//当窗口关闭时,程序结束
}

@Override
publicvoidactionPerformed(ActionEvente){
JButtonjb=(JButton)e.getSource();
if(jb==jbReset){
jtfName.setText("");
jpf.setText("");
jtfEmail.setText("");
jrb1.setSelected(true);
jcb.setSelectedIndex(0);//选中第1个选项(18)
}elseif(jb==jbSingUp){

Stringname=jtfName.getText().trim();
Stringpswd=newString(jpf.getPassword());
Stringemail=jtfEmail.getText().trim();
Stringxb=jrb1.isSelected()?"男":"女";
Stringage=(String)jcb.getSelectedItem();
if(name.equals("")||pswd.equals("")||email.equals("")){//对输入的信息进行一个简单的判断
JOptionPane.showMessageDialog(null,"请完整填写所有的信息","提示",JOptionPane.WARNING_MESSAGE);
return;
}

StringBuffersb=newStringBuffer();
sb.append("账号:"+name+NEW_LINE+"密码:"+pswd+NEW_LINE+"邮箱:"+email+NEW_LINE+"性别:"+xb
+NEW_LINE+"年龄:"+age+NEW_LINE);
booleanflag=saveInfo(sb.toString());
if(flag){
JOptionPane.showMessageDialog(null,"注册成功,保存成功");
}else{
JOptionPane.showMessageDialog(null,"Sorry!保存失败.注册出现了问题...","IO错误",JOptionPane.ERROR_MESSAGE);
}
}

}

//方法:保存信息到文件
publicbooleansaveInfo(Stringinfo){
FileWriterfw;
try{
fw=newFileWriter(FILE_PATH,true);//追加文字到文件尾部
fw.write(info);
fw.close();
}catch(IOExceptione){
e.printStackTrace();
returnfalse;//IO异常,保存不成功
}
returntrue;//保存成功
}

//main方法
publicstaticvoidmain(String[]args){
newSingUpFrame().setVisible(true);//创建窗口并可见
}

}

H. 用JAVA做一个网页(注册页)

<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>新用户注册</title>
<script language="javascript" src="js/send_request.js"></script>
<script language="javascript">
function refreshImage(){
document.getElementById("image").src = "image.jsp";
}
function checkInput(){
var f = document.forms[0];
var usernamePatrn = /^[a-zA-Z]{4,12}$/;
if(!usernamePatrn.exec(f.username.value)){
alert("输入用户名不合法,请重新输入!");
f.username.select;
f.username.focus();
return false;
}
var passwordPatrn = /^(\w){6,12}$/;
if(!passwordPatrn.exec(f.password.value)){
alert("密码不符合要求,请重新输入!");
f.passowrd.focus();
return false;
}
if(f.password.value != f.passwordverify.value){
alert("两次密码输入不一样,请重新输入!");
f.password.focus();
return false;
}
document.getElementById("info").innerHTML = "正在处理。。。请等待。。。";
send_request("get","private/register1.jsp?userName="+f.username.value+"&password="+f.password.value+
"&checkCode="+f.check.value,null,"text",callback);
}
function callback(){
if(http_request.readyState == 4){
if(http_request.status == 200){
var result = http_request.responseText;
if(result == 1){
alert("注册成功!点击确定后进入主界面!");
window.location="mainPage.html";
}
else alert(result);
}
else{
alert("页面异常");
alert(http_request.status);
}
}
}
</script>
</head>

<body>
<form action="" name="form1"method="post">
<table width="100%">
<tr align="center">
<td align="right">用户名:</td>
<td align="left"><input type="text" size="12" maxlength="12" id="username" name="username" />
(2-12字符, 必须全为英文字母)</td>
</tr>
<tr>
<td></td>
<td align="left"><label id="info" style="color:#0033FF"></td>
</tr>
<tr>
<td align="right">密码:</td>
<td align="left"><input type="password" size="12" maxlength="12" id="password" />(4-12字符)</td>
</tr>
<tr>
<td align="right">密码确认:</td>
<td align="left"><input type="password" size="12" maxlength="12" id="passwordverify" />(4-12字符)</td>
</tr>
<tr>
<td align="right"><img src="image.jsp" id="image" /></td>
<td align="left"><input type="button" value="看不清楚,换个验证码" onclick="javascript:refreshImage();" /></td>
</tr>
<tr>
<td align="right">请输入验证码:</td>
<td align="left"><input type="text" size="12" maxlength="12" id="check" name="check" /></td>
</tr>
<tr>
<td align="right"><input type="button" value="提交" onclick="javascript:checkInput();" /></td>
<td align="left"><input type="reset" value="取消" /></td>
</tr>
</table>
</form>
</body>
</html>
ajax的
下面是image.jsp

<%@ page contentType="image/jpeg" import="java.awt.*,java.awt.image.*,java.util.*,javax.imageio.*" %>
<%!

Color getRandColor(Random random,int fc,int bc)
{
if(fc>255) fc=255;
if(bc>255) bc=255;
int r=fc+random.nextInt(bc-fc);
int g=fc+random.nextInt(bc-fc);
int b=fc+random.nextInt(bc-fc);
return new Color(r,g,b);
}
%>
<%
response.setHeader("Pragma","No-cache");
response.setHeader("Cache-Control","no-cache");
response.setDateHeader("Expires", 0);

// 设置图片的长宽
int width=176, height=30;
//设置备选汉字,剔除一些不雅的汉字
String base = "\u7684\u4e00\u4e86\u662f\u6211\u4e0d\u5728\u4eba\u4eec\u6709\u6765\u4ed6\u8fd9\u4e0a\u7740\u4e2a\u5730\u5230\u5927"+
"\u91cc\u8bf4\u5c31\u53bb\u5b50\u5f97\u4e5f\u548c\u90a3\u8981\u4e0b\u770b\u5929\u65f6\u8fc7\u51fa\u5c0f\u4e48\u8d77"+
"\u90fd\u628a\u597d\u8fd8\u591a\u6ca1\u4e3a\u53c8\u53ef\u5bb6\u5b66\u53ea\u4ee5\u4e3b\u4f1a\u6837\u5e74\u60f3\u751f\u540c\u8001\u4e2d\u5341"+
"\u4ece\u81ea\u9762\u524d\u5934\u9053\u5b83\u540e\u7136\u8d70\u5f88\u50cf\u89c1\u4e24\u7528\u5979\u56fd\u52a8\u8fdb\u6210\u56de\u4ec0\u8fb9"+

"\u4f5c\u5bf9\u5f00\u800c\u5df1\u4e9b\u73b0\u5c71\u6c11\u5019\u7ecf\u53d1\u5de5\u5411\u4e8b\u547d\u7ed9\u957f\u6c34\u51e0\u4e49\u4e09\u58f0"+

"\u4e8e\u9ad8\u624b\u77e5\u7406\u773c\u5fd7\u70b9\u5fc3\u6218\u4e8c\u95ee\u4f46\u8eab\u65b9\u5b9e\u5403\u505a\u53eb\u5f53\u4f4f\u542c\u9769"+

"\u6253\u5462\u771f\u5168\u624d\u56db\u5df2\u6240\u654c\u4e4b\u6700\u5149\u4ea7\u60c5\u8def\u5206\u603b\u6761\u767d\u8bdd\u4e1c\u5e2d\u6b21"+

"\u4eb2\u5982\u88ab\u82b1\u53e3\u653e\u513f\u5e38\u6c14\u4e94\u7b2c\u4f7f\u5199\u519b\u5427\u6587\u8fd0\u518d\u679c\u600e\u5b9a\u8bb8"+

"\u5feb\u660e\u884c\u56e0\u522b\u98de\u5916\u6811\u7269\u6d3b\u90e8\u95e8\u65e0\u5f80\u8239\u671b\u65b0\u5e26\u961f\u5148\u529b\u5b8c\u5374"+

"\u7ad9\u4ee3\u5458\u673a\u66f4\u4e5d\u60a8\u6bcf\u98ce\u7ea7\u8ddf\u7b11\u554a\u5b69\u4e07\u5c11\u76f4\u610f\u591c\u6bd4\u9636\u8fde\u8f66"+

"\u91cd\u4fbf\u6597\u9a6c\u54ea\u5316\u592a\u6307\u53d8\u793e\u4f3c\u58eb\u8005\u5e72\u77f3\u6ee1\u65e5\u51b3\u767e\u539f\u62ff\u7fa4\u7a76"+

"\u5404\u516d\u672c\u601d\u89e3\u7acb\u6cb3\u6751\u516b\u96be\u65e9\u8bba\u5417\u6839\u5171\u8ba9\u76f8\u7814\u4eca\u5176\u4e66\u5750\u63a5"+

"\u5e94\u5173\u4fe1\u89c9\u6b65\u53cd\u5904\u8bb0\u5c06\u5343\u627e\u4e89\u9886\u6216\u5e08\u7ed3\u5757\u8dd1\u8c01\u8349\u8d8a\u5b57\u52a0"+

"\u811a\u7d27\u7231\u7b49\u4e60\u9635\u6015\u6708\u9752\u534a\u706b\u6cd5\u9898\u5efa\u8d76\u4f4d\u5531\u6d77\u4e03\u5973\u4efb\u4ef6"+

"\u611f\u51c6\u5f20\u56e2\u5c4b\u79bb\u8272\u8138\u7247\u79d1\u5012\u775b\u5229\u4e16\u521a\u4e14\u7531\u9001\u5207\u661f\u5bfc\u665a\u8868"+

"\u591f\u6574\u8ba4\u54cd\u96ea\u6d41\u672a\u573a\u8be5\u5e76\u5e95\u6df1\u523b\u5e73\u4f1f\u5fd9\u63d0\u786e\u8fd1\u4eae\u8f7b\u8bb2"+

"\u519c\u53e4\u9ed1\u544a\u754c\u62c9\u540d\u5440\u571f\u6e05\u9633\u7167\u529e\u53f2\u6539\u5386\u8f6c\u753b\u9020\u5634\u6b64\u6cbb\u5317"+

"\u5fc5\u670d\u96e8\u7a7f\u5185\u8bc6\u9a8c\u4f20\u4e1a\u83dc\u722c\u7761\u5174\u5f62\u91cf\u54b1\u89c2\u82e6\u4f53\u4f17\u901a\u51b2\u5408"+

"\u7834\u53cb\u5ea6\u672f\u996d\u516c\u65c1\u623f\u6781\u5357\u67aa\u8bfb\u6c99\u5c81\u7ebf\u91ce\u575a\u7a7a\u6536\u7b97\u81f3"+

"\u653f\u57ce\u52b3\u843d\u94b1\u7279\u56f4\u5f1f\u80dc\u6559\u70ed\u5c55\u5305\u6b4c\u7c7b\u6e10\u5f3a\u6570\u4e61\u547c\u6027\u97f3\u7b54"+

"\u54e5\u9645\u65e7\u795e\u5ea7\u7ae0\u5e2e\u5566\u53d7\u7cfb\u4ee4\u8df3\u975e\u4f55\u725b\u53d6\u5165\u5cb8\u6562\u6389\u5ffd\u79cd\u88c5"+

"\u9876\u6025\u6797\u505c\u606f\u53e5\u533a\u8863\u822c\u62a5\u53f6\u538b\u6162\u53d4\u80cc\u7ec6";
//备选汉字的长度
int length = base.length();

//创建内存图像
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
// 获取图形上下文
Graphics g = image.getGraphics();

//创建随机类的实例
Random random = new Random();

// 设定图像背景色(因为是做背景,所以偏淡)
g.setColor(getRandColor(random,200,250));
g.fillRect(0, 0, width, height);

//备选字体
String[] fontTypes = {"\u5b8b\u4f53","\u65b0\u5b8b\u4f53","\u9ed1\u4f53","\u6977\u4f53","\u96b6\u4e66"};
int fontTypesLength = fontTypes.length;

//在图片背景上增加噪点
g.setColor(getRandColor(random,160,200));
g.setFont(new Font("Times New Roman",Font.PLAIN,14));
for (int i=0;i<6;i++)
{
g.drawString("*********************************************",0,5*(i+2));
}

//取随机产生的认证码(6个汉字)

//保存生成的汉字字符串
String sRand="";
for (int i=0;i<4;i++)
{
int start = random.nextInt(length);
String rand=base.substring(start,start+1);
sRand+=rand;

//设置字体的颜色
g.setColor(getRandColor(random,10,150));
//设置字体
g.setFont(new Font(fontTypes[random.nextInt(fontTypesLength)],Font.BOLD,18 + random.nextInt(6)));
//将此汉字画到图片上
g.drawString(rand,24*i+ 10 + random.nextInt(8),24);
}

session.setAttribute("rand",sRand);

g.dispose();

ImageIO.write(image, "JPEG", response.getOutputStream());

%>

I. Java用户注册图形界面设计

代码有点长,加我发给你。
网络HI我!

J. java 编写用户注册页面,包含用户名、密码、性别、兴趣爱好、籍贯(下拉列表实现)、邮件地址等信

只是参考,需要自己需改!

packagecom.ivory.view;
importjava.awt.*;
importjava.awt.event.*;
importjava.io.*;
importjavax.imageio.ImageIO;
importjavax.swing.*;
importcom.ivory.common.User;
importcom.ivory.sql.UserServer;

{
JLabeljl1,jl2,jl3,jl4,jl5,jl6,jl7,jl8,jl9;
JTextFieldjtf1,jtf2,jtf3,jtf4,jtf5,jtf6,jtf7,jtf8;
JButtonjb1,jb2;
Fontf1=newFont("宋体",Font.PLAIN,16);
Useruser;
publicAddUser(Useru)
{
Containerct=newContainer();
jl1=newJLabel("账号");
jl1.setFont(f1);
jl1.setBounds(10,60,100,30);
jl2=newJLabel("密码");
jl2.setFont(f1);
jl2.setBounds(10,110,100,30);
jl3=newJLabel("密码");
jl3.setFont(f1);
jl3.setBounds(10,160,100,30);
jl4=newJLabel("姓名");
jl4.setFont(f1);
jl4.setBounds(10,210,100,30);
jl5=newJLabel("性别");
jl5.setFont(f1);
jl5.setBounds(10,260,100,30);
jl6=newJLabel("班级");
jl6.setFont(f1);
jl6.setBounds(10,310,100,30);
jl7=newJLabel("Tel");
jl7.setFont(f1);
jl7.setBounds(10,370,100,30);
jl8=newJLabel("成绩");
jl8.setFont(f1);
jl8.setBounds(10,410,100,30);
jl9=newJLabel("注册用户");
jl9.setFont(f1);
jl9.setBounds(100,10,100,30);
jb1=newJButton(newImageIcon("image\queding.jpg"));
jb1.setBounds(40,460,70,30);
jb1.addActionListener(this);
jb1.setActionCommand("queding");
jb2=newJButton(newImageIcon("image\quxiao.jpg"));
jb2.setBounds(200,460,70,30);
jb2.addActionListener(this);
jb2.setActionCommand("quxiao");
jtf1=newJTextField(20);
jtf1.setBounds(50,60,200,30);
jtf2=newJTextField(20);
jtf2.setBounds(50,110,200,30);
jtf3=newJTextField(10);
jtf3.setBounds(50,160,200,30);
jtf4=newJTextField(20);
jtf4.setBounds(50,210,200,30);
jtf5=newJTextField(15);
jtf5.setBounds(50,260,200,30);
jtf6=newJTextField(20);
jtf6.setBounds(50,310,200,30);
jtf7=newJTextField(10);
jtf7.setBounds(50,360,200,30);
jtf8=newJTextField(20);
jtf8.setBounds(50,410,200,30);
jtf8.setText("100");
jtf8.setEditable(false);
ct.add(jl9);ct.add(jl1);ct.add(jl2);
ct.add(jl3);ct.add(jl4);ct.add(jl5);
ct.add(jl6);ct.add(jl7);ct.add(jl8);
ct.add(jtf1);ct.add(jtf2);ct.add(jtf3);
ct.add(jtf4);ct.add(jtf5);ct.add(jtf6);
ct.add(jtf7);ct.add(jtf8);
ct.add(jb1);ct.add(jb2);
BackIamgebi=newBackIamge();
bi.setBounds(0,0,300,500);
ct.add(bi);
this.add(ct);
this.setSize(300,500);
this.setUndecorated(true);
this.setLocation(500,100);
this.setVisible(true);
}
//定义一个内部类(背景图片)
classBackIamgeextendsJPanel
{
Imageim;
publicBackIamge()
{
try{
im=ImageIO.read(newFile("image//add.jpg"));
}catch(IOExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}
}
//定义paint方法
publicvoidpaintComponent(Graphicsg)
{
//画出背景图片
g.drawImage(im,0,0,300,500,this);
}
}
@Override
publicvoidactionPerformed(ActionEvente){
//TODOAuto-generatedmethodstub
if(e.getActionCommand().equals("queding"))
{
Useru=newUser();
u.setUser(jtf1.getText());
u.setPassword(jtf2.getText());
u.setPassword(jtf3.getText());
u.setNumName(jtf4.getText());
u.setNumSex(jtf5.getText());
u.setNumClass(jtf6.getText());
u.setNumTel(jtf7.getText());
u.setNumMark(jtf8.getText());
u.setMessage("add");
if(!jtf2.getText().equals(jtf3.getText()))
{
JOptionPane.showMessageDialog(null,"密码不一致");
}
else
{

if(u.getMessage().equals("1"))
{
JOptionPane.showMessageDialog(null,"注册成功!");
this.dispose();
}else
{
JOptionPane.showMessageDialog(null,"注册失败!");
}
}
}
elseif(e.getActionCommand().equals("quxiao"))
{
this.dispose();
}
}
}
热点内容
内置存储卡可以拆吗 发布:2025-05-18 04:16:35 浏览:335
编译原理课时设置 发布:2025-05-18 04:13:28 浏览:378
linux中进入ip地址服务器 发布:2025-05-18 04:11:21 浏览:612
java用什么软件写 发布:2025-05-18 03:56:19 浏览:32
linux配置vim编译c 发布:2025-05-18 03:55:07 浏览:107
砸百鬼脚本 发布:2025-05-18 03:53:34 浏览:943
安卓手机如何拍视频和苹果一样 发布:2025-05-18 03:40:47 浏览:739
为什么安卓手机连不上苹果7热点 发布:2025-05-18 03:40:13 浏览:803
网卡访问 发布:2025-05-18 03:35:04 浏览:511
接收和发送服务器地址 发布:2025-05-18 03:33:48 浏览:371