1. 程式人生 > >登陸界面代碼

登陸界面代碼

equals tla ack ner ext amp 自動刷新 charat lose

1、設計思想

添加窗口界面,想i面添加一系列組件。

輸入賬號密碼和驗證碼後,如果驗證碼正確,進行註冊,否則註冊失敗。註冊成功後,驗證碼自動刷新,並將註冊的帳號和密碼保存。註冊失敗後,驗證碼刷新,從新註冊。

而後進行登錄,輸入帳號密碼和驗證碼,當三個都輸入對的時候,登錄成功,否則登錄失敗,刷新驗證碼重新登錄。

當點擊刷新驗證碼後,驗證碼自動刷新。

2、流程圖

技術分享

3、源程序代碼

package java作業;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

class chuang extends JFrame implements ActionListener
{
private JTextField txt1;
private JTextField txt2;
private String base = "abcdefghijklmnopqrstuvwxyz0123456789";
private String zifu;
private JLabel haha;
private JTextField txt3;
private JButton d;
private JButton dl;
private JButton zc;
private String zhanghao;
private String mima;
private String yanzheng;
private StringBuffer sb;
chuang()
{
setBounds(800,400,300,250);
setVisible(true);
setTitle("界面");
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLayout(null);

JLabel zh=new JLabel("帳號:");
zh.setBounds(20,15,50,25);
add(zh);

JLabel mm=new JLabel("密碼:");
mm.setBounds(20,50,50,25);
add(mm);

JLabel en=new JLabel("點擊按鈕後,放大窗口刷新驗證碼");
en.setBounds(20,150,200,25);
add(en);

Random random = new Random();
sb = new StringBuffer();
for (int i = 0; i < 4; i++)
{
int number = random.nextInt(base.length());
sb.append(base.charAt(number));
}
haha=new JLabel(sb.toString()+":");
haha.setBounds(20,85,50,25);
add(haha);

txt1 = new JTextField(20);
txt1.setBounds(65,15,150,25);
add(txt1);
txt1.setText("請輸入帳號");

txt2 = new JTextField(20);
txt2.setBounds(65,50,150,25);
add(txt2);
txt2.setText("請輸入密碼");

txt3 = new JTextField(20);
txt3.setBounds(65,85,100,25);
add(txt3);
txt3.setText("請輸入驗證碼");

d=new JButton("刷新驗證碼");
d.addActionListener(this);
d.setBounds(170,85,100,24);
add(d);

dl=new JButton("登錄");
dl.addActionListener(this);
dl.setBounds(35,120,75,24);
add(dl);

zc=new JButton("註冊");
zc.addActionListener(this);
zc.setBounds(120,120,75,24);
add(zc);

validate();
}


public void actionPerformed(ActionEvent e)
{
if(e.getSource()==d)
{
remove(haha);
Random random = new Random();
sb = new StringBuffer();
for (int i = 0; i < 4; i++)
{
int number = random.nextInt(base.length());
sb.append(base.charAt(number));
}
haha=new JLabel(sb.toString()+":");
haha.setBounds(20,85,50,25);
add(haha);

validate();
}
else if(e.getSource()==dl)
{
yanzheng=txt3.getText();
if(yanzheng.equals(sb.toString())&&txt1.getText().equals(zhanghao)&&txt2.getText().equals(mima))
{
JFrame ha=new JFrame("登錄界面");
ha.setBounds(880,460,150,100);
ha.setVisible(true);
JLabel hao=new JLabel("登錄成功!");
ha.add(hao);
validate();
}
else
{
JFrame ha=new JFrame("登錄界面");
ha.setBounds(880,460,150,100);
ha.setVisible(true);
JLabel hao=new JLabel("登錄失敗!");
ha.add(hao);
validate();
}
}
else if(e.getSource()==zc)
{
yanzheng=txt3.getText();
zhanghao=txt1.getText();
mima=txt2.getText();
if(yanzheng.equals(sb.toString()))
{
JFrame ha=new JFrame("註冊界面");
ha.setBounds(880,460,150,100);
ha.setVisible(true);
JLabel hao=new JLabel("註冊成功!");
ha.add(hao);
validate();
}
else
{
JFrame ha=new JFrame("註冊界面");
ha.setBounds(880,460,150,100);
ha.setVisible(true);
JLabel hao=new JLabel("註冊失敗!");
ha.add(hao);
validate();
}
remove(haha);
Random random = new Random();
sb = new StringBuffer();
for (int i = 0; i < 4; i++)
{
int number = random.nextInt(base.length());
sb.append(base.charAt(number));
}
haha=new JLabel(sb.toString()+":");
haha.setBounds(20,85,50,25);
add(haha);

validate();
}
}
public void shuzi()
{
Random random = new Random();
StringBuffer sb = new StringBuffer();
for (int i = 0; i < 4; i++)
{
int number = random.nextInt(base.length());
sb.append(base.charAt(number));
}
System.out.println(sb.toString());
}
}

public class suiji {
public static void main(String args[])
{
new chuang();
}
}

4、結果截圖

技術分享

技術分享

技術分享

技術分享

技術分享

技術分享

登陸界面代碼