这次代码是登录窗口的制作。

主要的方面是是包括,用户名、密码、验证码。以及输入数据所需要的文本框,对于验证码可以通过点击验证码进行修改。同时对于验证码的前景色和背景色同时都得到修改。

点击注册(这里还不完善)系统会提示你登录时需要输入的字符串,之后按照提示的字符串进行输入之后烯烃会对用户名以及密码验证码进行判断。可以通过enter直接进行登录二不用点击相应的按钮,之后如果错误会清空所输入的东西让您继续输入。 输入成功后即完成简单的登录。

重要内容是验证码的随机产生并进行显示。可以控制验证码的颜色以及字体还有大小。

package com.登录窗口;
//模拟登录窗口
import java.util.Random;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class DengLu extends JFrame
{
/**
*
*/
private static final long serialVersionUID = 1L;//系统进行的添加
static String wen=new String();
private JLabel yonghula;
private JLabel mimala;
private JLabel yanzhengla;
private JTextField yonghutxt;
private JPasswordField mimatxt;
private JTextField yanzhengtxt;
private JButton anniu1bt;
private JButton anniu2bt;
private JButton mianban;
public Color getRandomColor()
{//获得随机颜色
Random r=new Random();
int R=r.nextInt(255),G=r.nextInt(255),B=r.nextInt(255);
return new Color(R,G,B);
}
public String random()
{
Random r=new Random();
String result = "";//随机产生四个数字或者是字母
for(int i=0;i<4;i++){
int shuzi;
//生成一个1~3的int型的整数
shuzi=(r.nextInt(3)+1);
if(shuzi==1){//数字
shuzi=(r.nextInt(8)+1);
result=result+shuzi;
}
else if(shuzi==2){//大写字母
shuzi=(r.nextInt(25)+97);
result=result+(char)shuzi;
}
else {//小写字母
shuzi=(r.nextInt(25)+65);
result=result+(char)shuzi;
}
}
return result;
}
public DengLu()
{
this.setTitle("登录窗口界面");
//用户的文本
yonghula=new JLabel();
yonghula.setText("用户名:");
yonghula.setSize(60,50);
yonghula.setLocation(100,80);
//用户的输入框
yonghutxt=new JTextField();
yonghutxt.setSize(120,28);
yonghutxt.setLocation(150,95);
//密码文本
mimala=new JLabel();
mimala.setText("密 码:");
mimala.setSize(50,50);
mimala.setLocation(100,120);
//密码输入框
mimatxt=new JPasswordField();
mimatxt.setEchoChar('$');
mimatxt.setSize(120,28);
mimatxt.setLocation(150,135);
//登录按钮
anniu1bt=new JButton("登录");
anniu1bt.setSize(60,25);
anniu1bt.setLocation(140,220);
//注册按钮
anniu2bt = new JButton("注册");
anniu2bt.setSize(60, 25);
anniu2bt.setLocation(240, 220);
//验证码文本
yanzhengla=new JLabel();
yanzhengla.setText("验证码:");
yanzhengla.setSize(70, 50);
yanzhengla.setLocation(100,165);
//验证码文本框
yanzhengtxt= new JTextField();
yanzhengtxt.setSize(50, 28);
yanzhengtxt.setLocation(150, 180);
//验证码
mianban = new JButton();
mianban.setSize(80, 30);
mianban.setLocation(210, 180);
wen=random();
mianban.setText(wen);
mianban.setFont(new Font("华文行楷",Font.BOLD,15));
//判断
anniu1bt.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if(yonghutxt.getText().trim().equals("dazhi")&&new String(mimatxt.getPassword()).trim().equals("dazhi666")&&yanzhengtxt.getText().trim().equals(wen))
{
JOptionPane.showMessageDialog(null, "登陆成功!");
System.exit(-1);
}
else if(yonghutxt.getText().trim().equals(""))
JOptionPane.showMessageDialog(null, "用户名不能为空");
else if(new String(mimatxt.getPassword()).trim().equals(""))
JOptionPane.showMessageDialog(null, "密码不能为空");
else if(yanzhengtxt.getText().trim().equals(""))
JOptionPane.showMessageDialog(null, "验证码不能为空");
else
JOptionPane.showMessageDialog(null, "登录错误");
yonghutxt.setText("");
mimatxt.setText("");
yanzhengtxt.setText("");
mianban.setBackground(getRandomColor());
mianban.setForeground(getRandomColor());
Random r=new Random();
String result = "";//随机产生四个数字或者是字母
for(int i=0;i<4;i++){
int shuzi;
//生成一个1~3的int型的整数
shuzi=(r.nextInt(3)+1);
if(shuzi==1){//数字
shuzi=(r.nextInt(8)+1);
result=result+shuzi;
}
else if(shuzi==2){//大写字母
shuzi=(r.nextInt(25)+97);
result=result+(char)shuzi;
}
else {//小写字母
shuzi=(r.nextInt(25)+65);
result=result+(char)shuzi;
}
}
wen=result;
mianban.setText(wen);
}
});
//验证码处理
anniu2bt.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
// TODO 自动生成的方法存根
JOptionPane.showMessageDialog(null, "注册成功\n用户名:dazhi\n密码:dazhi666");
yonghutxt.setText("");
mimatxt.setText("");
yanzhengtxt.setText("");
Random r=new Random();
String result = "";//随机产生四个数字或者是字母
for(int i=0;i<4;i++){
int shuzi;
//生成一个1~3的int型的整数
shuzi=(r.nextInt(3)+1);
if(shuzi==1){//数字
shuzi=(r.nextInt(8)+1);
result=result+shuzi;
}
else if(shuzi==2){//大写字母
shuzi=(r.nextInt(25)+97);
result=result+(char)shuzi;
}
else {//小写字母
shuzi=(r.nextInt(25)+65);
result=result+(char)shuzi;
}
}
wen=result;
mianban.setText(wen);
}
});
//重新获取验证码
mianban.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
mianban.setBackground(getRandomColor());
mianban.setForeground(getRandomColor());
Random r=new Random();
String result = "";//随机产生四个数字或者是字母(大写后者小写)
for(int i=0;i<4;i++){
int shuzi;
//生成一个1~3的int型的整数
shuzi=(r.nextInt(3)+1);
if(shuzi==1){//数字
shuzi=(r.nextInt(8)+1);
result=result+shuzi;
}
else if(shuzi==2){//大写字母
shuzi=(r.nextInt(25)+97);
result=result+(char)shuzi;
}
else {//小写字母
shuzi=(r.nextInt(25)+65);
result=result+(char)shuzi;
}
}
wen=result;
mianban.setText(wen);
}
});
this.setLayout(null);//告知管理器这里不用布局管理器
this.getRootPane().setDefaultButton(anniu1bt);//按回车需要执行的按钮操作
this.setSize(400, 400);
this.add(yonghula);
this.add(yonghutxt);
this.add(mimala);
this.add(mimatxt);
this.add(mimala);
this.add(yanzhengla);
this.add(yanzhengtxt);
this.add(anniu1bt);
this.add(anniu2bt);
this.add(mianban);
this.setVisible(true);//使窗口可视
this.setResizable(true);//生成的窗口是否可以自由改变大小
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
public static void main(String[] args)
{
new DengLu();
}
}

登录窗口java的更多相关文章

  1. 课程登记窗口java

    设计窗口,实现课程的登记,并且将相应的数据写入文件之中.保证的是课程名称不可以重复,对于任课老师必须是在已经设定好的五位老师之中.并且上课地点也是在预先设定的范围内.窗口可以持续进行保存,数据将在判断 ...

  2. 【转】【WPF】WPF 登录窗口关闭时打开主窗口

    在WPF中设计登录窗口关闭时打开主窗口,自动生成的App.xaml不能满足要求, 1.把App.xaml的属性窗口中的生成操作设定为 无 2.添加Program类 static class Progr ...

  3. SourceTree不出现用户登录窗口,提示错误fatal: unable to access'...'; error setting certificate verify locations

    SourceTree不出现用户登录窗口,提示错误fatal: unable to access'...'; error setting certificate verify locations; .. ...

  4. QUI操作超时弹出登录窗口登录的处理方式

    在使用QUI开发的业务系统中,如果长时间没操作,session过期后,再次操作系统超时会自动跳转到登陆页面,如果当前有一些操作没有保存,需要重新登录后再次填写信息,用户体验很不好! 为了避免超时后页面 ...

  5. C#实现登录窗口(不用隐藏)

    C#登录窗口的实现,特点就是不用隐藏,感兴趣的朋友不要错过 (1).在程序入口处,打开登录窗口 复制代码代码如下: static void Main()  {  Application.EnableV ...

  6. 基于WebForm+EasyUI的业务管理系统形成之旅 -- 登录窗口(Ⅱ)

    上篇<基于WebForm+EasyUI的业务管理系统形成之旅 -- 系统设置>,主要是介绍系统浏览器在线下载安装,这些前期准备是非常重要的. 最近忙于将工程管理系统中各个模块,用业务流程方 ...

  7. 高仿QQ即时聊天软件开发系列之三登录窗口用户选择下拉框

    上一篇高仿QQ即时聊天软件开发系列之二登录窗口界面写了一个大概的布局和原理 这一篇详细说下拉框的实现原理 先上最终效果图 一开始其实只是想给下拉框加一个placeholder效果,让下拉框在未选择未输 ...

  8. 高仿QQ即时聊天软件开发系列之二登录窗口界面

    继上一篇高仿QQ即时聊天软件开发系列之一开端之后,开始做登录窗口 废话不多说,先看效果,只有界面 可能还有一些细节地方没有做,例如那个LOGO嘛,不要在意这些细节 GIF虽短,可是这做起来真难,好吧因 ...

  9. C# WPF 建立无边框(标题栏)的登录窗口

    前言:笔者最近用c#写WPF做了一个项目,此前未曾做过完整的WPF项目,算是一边学一边用,网上搜了不少资料,效率当然是不敢恭维的,有时会在一些很简单的问题上纠结很长时间,血与泪的教训可不少. 不过,正 ...

随机推荐

  1. C 和 C++语言中的内存拷贝函数memcpy()

    memcpy指的是C和C++使用的内存拷贝函数 函数原型为void *memcpy(void *destin, void *source, unsigned n): 函数的功能是从源内存地址的起始位置 ...

  2. 面向对象里is-a和has-a的含义

    面向对象的核心思想是:抽象.封装.继承.多态.在实践中用的最多的术语就是 is a(是一个) ,和 has a(有一个).其实他们的意思很简单,对应面向对象设计中的两种形态继承.组合. 一.继承( i ...

  3. EOS基础全家桶(一)开篇

    简介 从今天开始我会在FishoPark上与大家分享EOS的一些技术经验和基础,如果大家在看文章的过程中有任何问题,欢迎在网站下方的评论里留言,我会尽力为大家解答,如果发现我内容中所写有错,欢迎指正, ...

  4. 2. weddriver的定位方法

    一. find_element_by_****的方式 首页在网页上鼠标右键选择检查并点击,查看需要定位的元素. https://www.baidu.com  以百度为例 导入模块的: from sel ...

  5. Journal of Proteome Research | Quantitative Subcellular Proteomics of the Orbitofrontal Cortex of Schizophrenia Patients (精神分裂症病人眶额叶皮层亚细胞结构的定量蛋白质组学研究)(解读人:王聚)

    期刊名:Journal of Proteome Research 发表时间:(2019年10月) IF:3.78 单位: 里约热内卢联邦大学 坎皮纳斯州立大学 坎皮纳斯州立大学神经生物学中心 卡拉博大 ...

  6. VirtualBox 安装 Centos8 使用 Xshell 连接

    1.下载CentOS CentOS下载地址:https://wiki.centos.org/Download 这里选择本地安装包,网络安装包在安装时需要在线下载资源比较慢 2.安装VirtualBox ...

  7. 《大空头》与A股内幕消息

    目录 <大空头>简介 投行人士透露内幕消息不划算 <大空头>里合规性的一些解释 相信A股内幕消息的一些惨痛教训. 风险提示. <大空头>简介 <大空头> ...

  8. Java基础语法(5)-特殊流程控制语句

    title: Java基础语法(5)-特殊流程控制语句 blog: CSDN data: Java学习路线及视频 1.嵌套循环结构 将一个循环放在另一个循环体内,就形成了嵌套循环.其中,for ,wh ...

  9. c++第一个程序测试-----c++每日笔记!

    #include <iostream>int main(){ //std::cout << "Enter two number:" <<std: ...

  10. 使用条件随机场模型解决文本分类问题(附Python代码)

    对深度学习感兴趣,热爱Tensorflow的小伙伴,欢迎关注我们的网站!http://www.tensorflownews.com.我们的公众号:磐创AI. 一. 介绍 世界上每天都在生成数量惊人的文 ...