验证码|程序登录界面

编程实现用户登录界面需要输入验证码。

package shiyan2;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class QQGUI extends JFrame {
private JLabel userLa;
private JLabel pwdLa;
private JLabel user;
private JLabel verCodeLa;//验证码
private JTextField userTxt;
private JPasswordField pwdTxt;
private JTextField verCodeTxt;//验证码
private JButton sureBt;
private JButton quitBt;

//构造方法
public QQGUI()
{
Init();
}
public void Init()
{

Frame frame = new Frame("请登录");

//用户文本
userLa = new JLabel();
userLa.setText("登录名:");
userLa.setSize(60, 50);
userLa.setLocation(40, 30);


//忘记用户名、密码
user = new JLabel();
user.setText("忘记用户名/密码?");
user.setSize(110, 50);
user.setLocation(260, 75);

//密码文本
pwdLa = new JLabel();
pwdLa.setText("密 码:");
pwdLa.setSize(60, 50);
pwdLa.setLocation(40, 75);

//用户输入框
userTxt = new JTextField();
userTxt.setSize(160, 30);
//this.setSize(width, height)
userTxt.setLocation(90, 45);

//密码输入框
pwdTxt = new JPasswordField();
pwdTxt.setSize(160, 30);
pwdTxt.setLocation(90, 85);

//确认按钮
sureBt = new JButton("登录");
sureBt.setSize(170,30);
sureBt.setLocation(110, 170);

//退出按钮
quitBt = new JButton("快速注册");
quitBt.setSize(170, 30);
quitBt.setLocation(110, 210);

//验证码文本
verCodeLa = new JLabel();
verCodeLa.setText("验证码:");
verCodeLa.setSize(60, 50);
verCodeLa.setLocation(40,120);

//验证码文本框
verCodeTxt = new JTextField();
verCodeTxt.setSize(90, 30);
verCodeTxt.setLocation(90, 130);



this.setLayout(null);
this.setSize(400, 300);
this.add(userLa);
this.add(user);
this.add(pwdLa);
this.add(userTxt);
this.add(pwdTxt);
this.add(sureBt);
this.add(quitBt);
this.add(verCodeLa);
this.add(verCodeTxt);
this.setVisible(true);
}

}

package shiyan2;

import javax.swing.*;
public class MainFrame extends JFrame {
public MainFrame()
{
this.setSize(300, 300);
this.setVisible(true);
}
}

package shiyan2;

public class testQQGUI {
public static void main(String[] args) {
QQGUI frame = new QQGUI();
}
}

 运行结果:

本程序不太学会,所以借鉴了网上部分代码进行编写;主要是调用了Swing中的构件进行编译,构成登录界面;

目前存在的问题:

1、登录名文本框中无法提示  “用户名/邮箱”;

2、验证码无法生成及刷新;

3、控件颜色不会修改;

4、文字颜色、字体不会修改;

猜你喜欢

转载自www.cnblogs.com/KYin/p/9752446.html
今日推荐