📄 email.java
字号:
import javax.swing.*;
import java.awt.*;
import javax.swing.border.*;
import java.awt.event.*;
public class email
{
public static void main(String args[])
{ new WindowBox();}
}
class Mycanvas extends Canvas /////////////////////////////用于产生验证码
{
String std;///////////////////////////////////验证码
public Color getRandc()
{
int r=(int)(Math.random()*255);
int g=(int)(Math.random()*255);
int b=(int)(Math.random()*255);
return new Color(r,g,b);
}
Mycanvas(String strd)
{
Color temc=new Color(255,0,0);
int r=255,g=0,b=0;
//while(r==255)
//temc=getRandc();
setBackground(new Color(0,0,0));
std=strd;
repaint();
}
public void paint(Graphics g)
{
g.setFont(new Font("楷体_GB2312", Font.PLAIN, 24));
g.setColor(new Color(255, 0, 0));
g.drawString(std,10, 30);
}
}
class WindowBox extends Frame implements ActionListener
{
Box baseBox1,boxV1,boxV2,boxV3,boxV4;
Panel pt=new Panel();
TextField tf=new TextField(20);/*姓名*/
TextField tf2=new TextField(20);/*用户名*/
TextField tf3=new TextField(20);/*密码1*/
TextField tf4=new TextField(20);/*重新输入密码*/
TextField tf5=new TextField(20);/*问题的答案*/
TextField tf6=new TextField(4);/*出生年*/
TextField tf7=new TextField(20);/*昵称*/
TextField tf8=new TextField(20);/*手机号*/
TextField tf9=new TextField(20);/*备用邮箱*/
String code;/*用于存储验证密码*/
CheckboxGroup sex;
String dic="骏雅秉才思敏捷过目年窗博学才见识广高富五车文武双全雄韬伟略谈吐谈笑风声高谈阔论眉飞色舞美卓义正严成显神通古流芳正双长大功德量众挽狂澜气贯长虹气势磅礴气山河坚韧前英姿焕发奉公守法奋斗忠鸣惊心动横千军惊天动地励精图治壮志凌云瞻远瞩盖世无双龙飞凤舞丝职理万英明有";
String dien="qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM";
public String getrandstr()
{
String resl="_";
for(int i=0;i<4;i++)
{
int temp=(int)(Math.random()*15);
if((temp%2)==1)
{
int randc=(int)(Math.random()*128);
resl=resl+dic.substring(randc,randc+1);
}
else
{
int rande=(int)(Math.random()*52);
resl=resl+dien.substring(rande,rande+1);
}
}
return resl;
}
String tr=(getrandstr()).substring(1);//////////////////////////////////////////////////得到验证码"****"
Mycanvas rancan=new Mycanvas(tr);
WindowBox()
{
/*///////////////////////////////////////////以下是创建第一个盒子*/
boxV1=Box.createVerticalBox();
Box boxV101=Box.createHorizontalBox();/*加载性别*/
boxV1.add(new Label("*邮箱用户名:",Label.RIGHT));
boxV1.add(Box.createVerticalStrut(8));
boxV1.add(new Label("*密码:",Label.RIGHT));
boxV1.add(Box.createVerticalStrut(8));
boxV1.add(new Label("*再次输入密码:",Label.RIGHT));
boxV1.add(Box.createVerticalStrut(8));
boxV1.add(new Label(" 姓名:",Label.RIGHT));
boxV1.add(Box.createVerticalStrut(8));
boxV1.add(new Label("*性别:",Label.RIGHT));
boxV2=Box.createVerticalBox();
boxV2.add(tf2);
boxV2.add(Box.createVerticalStrut(8));
boxV2.add(tf3);
boxV2.add(Box.createVerticalStrut(8));
boxV2.add(tf4);
boxV2.add(Box.createVerticalStrut(8));
boxV2.add(tf);
boxV2.add(Box.createVerticalStrut(8));
sex=new CheckboxGroup();
boxV101.add(new Checkbox("男",true,sex));
boxV101.add(new Checkbox("女",false,sex));
boxV2.add(boxV101);
baseBox1=Box.createHorizontalBox();
baseBox1.add(boxV1);
baseBox1.add(Box.createHorizontalStrut(10));
baseBox1.add(boxV2);
/*//////////////////////////////////////以下是创建第二个盒子,文本密码保护信息*/
Box baseBox2=Box.createHorizontalBox();
Label tip=new Label("请填写密码保护信息(以下信息用于取回密码及处理关于账户的其他问题,请您慎重填写并牢记!)",Label.CENTER);
tip.setForeground(Color.red);
baseBox2.add(tip);
/*/////////////////////////////////////以下是创建首个盒子*/
Box baseBox3=Box.createVerticalBox();
Label welc=new Label("-----------------------欢迎注册HOTMAIL邮箱------------------------",Label.CENTER);
welc.setFont(new Font("楷体_GB2312",Font.PLAIN,20));
welc.setForeground(Color.red);
baseBox3.add(welc);
/*////////////////////////////////////以下是放第四个盒子,密码保护问题,答案,因为第一个盒子有性别,故垂直对不齐*/
Box boxV4=Box.createVerticalBox();
boxV4.add(new Label("*密码保护问题:",Label.RIGHT));
boxV4.add(Box.createVerticalStrut(8));
boxV4.add(new Label("*您的答案:",Label.RIGHT));
Box boxV5=Box.createVerticalBox();
Choice choiceq=new Choice();
choiceq.add("请选择一个问题?");
choiceq.add("我就读的第一所学校的名称?");
choiceq.add("我最喜欢的休闲运动是什么?");
choiceq.add("我最喜欢的运动员是谁?");
choiceq.add("我最喜欢的物品的名称?");
choiceq.add("我最喜欢的歌曲?");
choiceq.add("我最喜欢的的食物?");
choiceq.add("我最新欢的人的名字?");
choiceq.add("我最爱的电影?");
choiceq.add("我妈妈的生日?");
choiceq.add("我的初恋日期?");
choiceq.add("我的自定义问题?");
boxV5.add(choiceq);
boxV5.add(Box.createVerticalStrut(8));
boxV5.add(tf5);
Box baseBox4=Box.createHorizontalBox();
baseBox4.add(boxV4);
baseBox4.add(Box.createHorizontalStrut(10));
baseBox4.add(boxV5);
/*///////////////////////////////////////以下是第五个盒子,出生日期6,昵称7,手机号8,保密邮箱9*/
Box boxV6=Box.createVerticalBox();
Box boxV7=Box.createVerticalBox();
Box boxH1=Box.createHorizontalBox();
boxV6.add(new Label(" 出生日期:",Label.RIGHT));
boxV6.add(Box.createVerticalStrut(8));
boxV6.add(new Label(" 昵称:",Label.RIGHT));
boxV6.add(Box.createVerticalStrut(8));
boxV6.add(new Label(" 手机号:",Label.RIGHT));
boxV6.add(Box.createVerticalStrut(8));
boxV6.add(new Label(" 保密邮箱:",Label.RIGHT));
boxH1.add(tf6);
boxH1.add(Box.createHorizontalStrut(1));
boxH1.add(new Label("年"));
boxH1.add(Box.createHorizontalStrut(1));
Choice choicem=new Choice();
for(int k=1;k<13;k++)
{ choicem.add(k+"月");}
boxH1.add(choicem);
boxV7.add(boxH1);
boxV7.add(Box.createVerticalStrut(8));
boxV7.add(tf7);
boxV7.add(Box.createVerticalStrut(8));
boxV7.add(tf8);
boxV7.add(Box.createVerticalStrut(8));
boxV7.add(tf9);
Box baseBox5=Box.createHorizontalBox();
baseBox5.add(boxV6);
baseBox5.add(Box.createHorizontalStrut(10));
baseBox5.add(boxV7);
///////////////////////////////////////////////////以下是完善信息,验证码,是否同意协议//////////////////
Label tip2=new Label("您可以进一步完善信息(选填)");
//tip2.setForeground(Color.red);
Label tip3=new Label("我愿意接收来自hotmail的邮件,请选择以下直邮类别(可多选)");
Checkbox cbox1=new Checkbox("旅游");
Checkbox cbox2=new Checkbox("休闲");
Checkbox cbox3=new Checkbox("财经");
Checkbox cbox4=new Checkbox("汽车");
Checkbox cbox5=new Checkbox("音乐");
Checkbox cbox6=new Checkbox("房产");
Checkbox cbox7=new Checkbox("家居");
Checkbox cbox8=new Checkbox("生活");
Checkbox cbox9=new Checkbox("数码");
Checkbox cbox10=new Checkbox("时尚");
Checkbox cbox11=new Checkbox("化妆");
Checkbox cbox12=new Checkbox("理财");
Checkbox cbox13=new Checkbox("宠物");
Checkbox cbox14=new Checkbox("健康");
Checkbox cbox15=new Checkbox("公益");
Checkbox cbox16=new Checkbox("其他");
TextField qita=new TextField(4);
Box boxH2=Box.createHorizontalBox();
Box boxH3=Box.createHorizontalBox();
boxH2.add(cbox1);boxH2.add(cbox2);boxH2.add(cbox3);boxH2.add(cbox4);boxH2.add(cbox5);
boxH2.add(cbox6);boxH2.add(cbox7);boxH2.add(cbox8);boxH2.add(cbox9);boxH2.add(cbox10);
boxH3.add(cbox11);boxH3.add(cbox12);boxH3.add(cbox13);boxH3.add(cbox14);boxH3.add(cbox15);
boxH3.add(cbox16);boxH3.add(qita);
Label flag0=new Label("-----------------------------------------------------------------------------------------------------------------------------------------------------");
Button mybutton=new Button("获取验证码");
mybutton.addActionListener(this);
Label jiaoyan0=new Label("注册校验");
Label jiaoyan1=new Label("输入右图校验码");
TextField jiaoyanma=new TextField(4);
Canvas mycanvas=new Canvas();
pt.setLayout(null);
pt.add(flag0);
flag0.setBounds(0,10,535,10);
pt.add(jiaoyan0);
jiaoyan0.setBounds(0,28,50,15);
pt.add(jiaoyan1);
jiaoyan1.setBounds(20,43,100,20);
pt.add(jiaoyanma);
jiaoyanma.setBounds(130,43,50,20);
pt.add(rancan);
rancan.setBounds(200,30,110,33);
pt.add(mybutton);
mybutton.setBounds(320,40,70,30);
pt.setBackground(new Color(120,0,250));
Label flag1=new Label("-------------------------------------");
Label tip4=new Label("scnu hotmail服务条款");
Label tip5=new Label("我已经阅读并同意scnu hotmail的服务条款和隐私权政策,同时遵守中华人民共和国法律。");
TextArea area=new TextArea();
area.setText("1.接受条款。迎光临scnu。scnu根据以下服务条款为您提供服务。这些条款可由中国雅虎随时更\n新,且毋须另行通知。scnu服务公约(以下简称本“服务公约”)一旦发生变动, scnu将在网页上\n公布修改内容。修改后的服务公约一旦在网页上公布即有效代替原来的服务公约。您可随时造访\n http://www.scnu.edu.cn 查阅最新版服务公约。应关注并遵守其所适用的相关条款。");
Panel pl=new Panel();
pl.setLayout(null);
pl.add(flag1);
flag1.setBounds(0,10,535,10);
pl.add(tip4);
tip4.setBounds(0,25,200,15);
pl.add(tip5);
tip5.setBounds(0,45,535,15);
pl.add(area);
area.setEnabled(false);
area.setBounds(0,65,535,80);
pl.setBackground(new Color(218,46,141));
///////////////////////////////////////////////////////////////同意并注册按钮
JButton sure=new JButton("同意并注册");
JButton canel=new JButton("取消");
sure.setBackground(new Color(255,220,120));
canel.setBackground(new Color(255,220,120));
Panel pb=new Panel();
pb.add(sure);
sure.setBounds(50,15,180,30);
pb.add(canel);
canel.setBounds(260,15,180,30);
pb.setLayout(null);
sure.setFont(new Font("楷体_GB2312",Font.PLAIN,20));
canel.setFont(new Font("楷体_GB2312",Font.PLAIN,20));
Panel plast=new Panel();
plast.setLayout(null);
plast.add(tip2);
tip2.setBounds(0,10,200,15);
plast.add(tip3);
tip3.setBounds(0,30,350,15);
plast.add(boxH2);
boxH2.setBounds(0,50,450,15);
plast.add(boxH3);
boxH3.setBounds(0,70,330,20);
plast.add(pt);
pt.setBounds(0,95,535,70);
plast.add(pl);
pl.setBounds(0,170,535,150);
//plast.add(tip4);
//plast.add(tip5);
//plast.add(area) ;
plast.setBackground(new Color(220,100,50));
///////////////////////////////////////////////////////////////////////以下整合这五个盒子
Panel p=new Panel();
p.add(baseBox3);
baseBox3.setBounds(0,0,586,50);
Label tip1=new Label("请填写用户信息(带 * 号项为必填项)");
tip1.setForeground(Color.red);
tip1.setBounds(30,50,250,50);
p.add(tip1);
p.add(baseBox1);
baseBox1.setBounds(0,100,386,150);
p.add(baseBox2);
baseBox2.setBounds(20,265,520,30);
p.add(baseBox4);
baseBox4.setBounds(-13,305,402,50);
p.add(baseBox5);
baseBox5.setBounds(40,363,350,120);
p.add(plast);
plast.setBounds(20,500,535,320);
p.add(pb);
pb.setBounds(20,820,535,80);
//pb.setBackground(new Color(65,45,91));
p.setBounds(0,0,586,1000);
p.setBackground(new Color(255,220,0));
p.setLayout(null);
////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////以下提示注意点标签
Label user1=new Label("由字母、数字、减号、下划线组成,");
Label user2=new Label("不区分大小写,长度是4至16位");
Label mima=new Label("密码长度为6至16位,区分大小写");
Label daan=new Label("答案长度是6至30位");
Label uname=new Label("姓名最长20字符,不能有特殊字符");
Label nick=new Label("昵称不超过20字符,不能有特殊字符");
Label baomi1=new Label("填写手机号或保密邮箱后,您就可以");
Label baomi2=new Label("通过手机或保密邮箱修改密码。所以");
Label baomi3=new Label("请您慎重填写这两项内容");
user1.setBackground(new Color(255,220,0));
user2.setBackground(new Color(255,220,0));
mima.setBackground(new Color(255,220,0));
daan.setBackground(new Color(255,220,0));
nick.setBackground(new Color(255,220,0));
uname.setBackground(new Color(255,220,0));
baomi1.setBackground(new Color(255,220,0));
baomi2.setBackground(new Color(255,220,0));
baomi3.setBackground(new Color(255,220,0));
p.add(user1);
user1.setBounds(390,97,250,15);
p.add(user2);
user2.setBounds(390,113,250,15);
p.add(mima);
mima.setBounds(390,140,200,15);
p.add(uname);
uname.setBounds(390,200,200,15);
p.add(daan);
daan.setBounds(390,340,200,15);
p.add(nick);
nick.setBounds(390,400,200,15);
p.add(baomi1);
baomi1.setBounds(390,430,200,15);
p.add(baomi2);
baomi2.setBounds(390,450,200,15);
p.add(baomi3);
baomi3.setBounds(390,470,200,15);
add(p);
FlowLayout myflow=new FlowLayout();
myflow.setAlignment(FlowLayout.CENTER);
myflow.setHgap(0);
myflow.setVgap(0);
setLayout(myflow);
setBounds(50,0,820,950);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
String tre=(getrandstr()).substring(1);//////////////////////////////////////////////////得到验证码"****"
rancan.std=tre;
rancan.repaint();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -