登录窗口java
这次代码是登录窗口的制作。
主要的方面是是包括,用户名、密码、验证码。以及输入数据所需要的文本框,对于验证码可以通过点击验证码进行修改。同时对于验证码的前景色和背景色同时都得到修改。
点击注册(这里还不完善)系统会提示你登录时需要输入的字符串,之后按照提示的字符串进行输入之后烯烃会对用户名以及密码验证码进行判断。可以通过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的更多相关文章
- 课程登记窗口java
设计窗口,实现课程的登记,并且将相应的数据写入文件之中.保证的是课程名称不可以重复,对于任课老师必须是在已经设定好的五位老师之中.并且上课地点也是在预先设定的范围内.窗口可以持续进行保存,数据将在判断 ...
- 【转】【WPF】WPF 登录窗口关闭时打开主窗口
在WPF中设计登录窗口关闭时打开主窗口,自动生成的App.xaml不能满足要求, 1.把App.xaml的属性窗口中的生成操作设定为 无 2.添加Program类 static class Progr ...
- SourceTree不出现用户登录窗口,提示错误fatal: unable to access'...'; error setting certificate verify locations
SourceTree不出现用户登录窗口,提示错误fatal: unable to access'...'; error setting certificate verify locations; .. ...
- QUI操作超时弹出登录窗口登录的处理方式
在使用QUI开发的业务系统中,如果长时间没操作,session过期后,再次操作系统超时会自动跳转到登陆页面,如果当前有一些操作没有保存,需要重新登录后再次填写信息,用户体验很不好! 为了避免超时后页面 ...
- C#实现登录窗口(不用隐藏)
C#登录窗口的实现,特点就是不用隐藏,感兴趣的朋友不要错过 (1).在程序入口处,打开登录窗口 复制代码代码如下: static void Main() { Application.EnableV ...
- 基于WebForm+EasyUI的业务管理系统形成之旅 -- 登录窗口(Ⅱ)
上篇<基于WebForm+EasyUI的业务管理系统形成之旅 -- 系统设置>,主要是介绍系统浏览器在线下载安装,这些前期准备是非常重要的. 最近忙于将工程管理系统中各个模块,用业务流程方 ...
- 高仿QQ即时聊天软件开发系列之三登录窗口用户选择下拉框
上一篇高仿QQ即时聊天软件开发系列之二登录窗口界面写了一个大概的布局和原理 这一篇详细说下拉框的实现原理 先上最终效果图 一开始其实只是想给下拉框加一个placeholder效果,让下拉框在未选择未输 ...
- 高仿QQ即时聊天软件开发系列之二登录窗口界面
继上一篇高仿QQ即时聊天软件开发系列之一开端之后,开始做登录窗口 废话不多说,先看效果,只有界面 可能还有一些细节地方没有做,例如那个LOGO嘛,不要在意这些细节 GIF虽短,可是这做起来真难,好吧因 ...
- C# WPF 建立无边框(标题栏)的登录窗口
前言:笔者最近用c#写WPF做了一个项目,此前未曾做过完整的WPF项目,算是一边学一边用,网上搜了不少资料,效率当然是不敢恭维的,有时会在一些很简单的问题上纠结很长时间,血与泪的教训可不少. 不过,正 ...
随机推荐
- 工具之scroolToIndex
需求定位:导航中实现子元素滚动到父元素的最左侧 解决方案:查找该子元素的offsetLeft值,然后让父元素滚动offsetLeft,parenDom.scrollLeft = childDom.of ...
- JavaScript中的内存释放
C.C++语言需要手动管理内存的分配与释放(常用方法:malloc(), calloc(), realloc()和free()等).而JavaScript与Java.C#相似,内置了垃圾回收器,能自动 ...
- 【Linux】linux系统管理---好用的一些开源工具
目录 linux系统管理---好用的一些开源工具 htop dstat Glances iftop nethogs iotop linux系统管理---好用的一些开源工具 htop htop是一款运行 ...
- appium移动自动化详解
1移动自动化简介 移动自动化就是通过代码来控制手机,模拟人的动作,对手机进行一些点击,输入等操作,那python代码如何能控制到手机呢?目前的思路应该是python代码->Appium-pyth ...
- Natas24 Writeup(strcmp绕过漏洞)
Natas24: 一个登录页面,查看源码,发现关键代码: if(array_key_exists("passwd",$_REQUEST)){ if(!strcmp($_REQUES ...
- Delphi10.3的DBGrid中memo类型显示内容而不是(WIDEMEMO)
1]连接好数据库,并显示: 2]增加所有字段: 3]添加事件: // FDQuery1UserName: TWideMemoField; procedure TForm1.FDQuery1Use ...
- Spinner 用法
</Spinner> <TextView android:layout_width="wrap_content" android:layout_height=&q ...
- 《吐血整理》Redis 性能优化的 13 条军规!史上最全
Redis 是基于单线程模型实现的,也就是 Redis 是使用一个线程来处理所有的客户端请求的,尽管 Redis 使用了非阻塞式 IO,并且对各种命令都做了优化(大部分命令操作时间复杂度都是 O(1) ...
- upload-labs学习笔记
项目地址:https://github.com/c0ny1/upload-labs 运行环境 操作系统:windows.Linux php版本:推荐5.2.17(其他版本可能会导致部分Pass无法 ...
- python set() leetcode 签到820. 单词的压缩编码
题目 给定一个单词列表,我们将这个列表编码成一个索引字符串 S 与一个索引列表 A. 例如,如果这个列表是 ["time", "me", "bell& ...