java设计的登录页面

package day01;//创建一个包 day01

import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.AbstractButton;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.JTextField;

import org.omg.CORBA.PUBLIC_MEMBER;

public class Test01 extends Thread{
Thread thread=new Thread();
JProgressBar pb=new JProgressBar();

public Test01(){
JFrame jFrame=new JFrame("登陆");
jFrame.setSize(1200, 1000);//创建一个界面

jFrame.setLayout(null);
//jFrame.getContentPane().setVisible(false);

MyPanel myPanel=new MyPanel();
myPanel.setBackground(Color.PINK);
myPanel.setBounds(0,0,1200,1000);//面板颜色,大小,位置

JLabel jLabel=new JLabel("欢迎登录");
jLabel.setFont(new Font("宋体",Font.BOLD,60));
jLabel.setBounds(410,0,500,200);

JLabel jLabel1=new JLabel("用户名:");
jLabel1.setFont(new Font("宋体",Font.BOLD,25));
jLabel1.setBounds(260,200,230,150);

JTextField tf=new JTextField("");
tf.setFont(new Font("宋体",Font.BOLD, 25));
tf.setBounds(400, 250, 230, 50);

JLabel jLabel2=new JLabel("密码:");
jLabel2.setFont(new Font("宋体",Font.BOLD,25));
jLabel2.setBounds(260,300,230,150);

JTextField tf2=new JTextField("");
tf2.setFont(new Font("宋体",Font.BOLD, 25));
tf2.setBounds(400, 350, 230, 50);

JLabel jLabel3=new JLabel("验证码:");
jLabel3.setFont(new Font("宋体",Font.BOLD,25));
jLabel3.setBounds(260,400,230,150);

JTextField tf3=new JTextField("");
tf3.setFont(new Font("宋体",Font.BOLD, 25));
tf3.setBounds(400, 450, 230, 50);

JLabel jLabel4=new JLabel("服务器:");
jLabel4.setFont(new Font("宋体",Font.BOLD,25));
jLabel4.setBounds(260,500,230,150);

JTextField tf4=new JTextField("");
tf4.setFont(new Font("宋体",Font.BOLD, 25));
tf4.setBounds(400, 550, 230, 50);

JButton jButton=new JButton("刷新验证");
jButton.setFont(new Font("宋体",Font.BOLD,18));
jButton.setBounds(700,450,150,50);

JButton jButton2=new JButton("登录");
jButton2.setFont(new Font("宋体",Font.BOLD,25));
jButton2.setBounds(430,650,200,50);

jFrame.setDefaultCloseOperation(3);
jFrame.setLocationRelativeTo(null);
JLabel jLabel5=new JLabel("点击左侧刷新");
jLabel5.setFont(new Font("宋体",Font.BOLD,20));
jLabel5.setBounds(900,450,100,50);//验证码大小,字体

JLabel jLabel6=new JLabel();
jLabel6.setFont(new Font("宋体",Font.BOLD,26));
jLabel6.setBounds(200,650,500,50);

jButton2.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent arg0) {
String str1=tf.getText();
String str2=tf2.getText();
String str3=tf3.getText();
String str4=tf4.getText();
String str5=jLabel5.getText();
if(str1.equals("")==false&&
str2.equals("")==false&&
str3.equals("")==false&&
str4.equals("")==false) {
if(str3.equals(str5)==true) {
jLabel6.setText("请耐心等待。。。");
start();
}else {
jLabel6.setText("验证码错误");
}
}
if(str1.equals("")==false&&
str2.equals("")==false&&
str3.equals("")==false&&
str4.equals("")==true) {
jLabel6.setText("服务器不能为空");
}
if(str1.equals("")==false&&
str2.equals("")==false&&
str3.equals("")==true&&
str4.equals("")==false) {
jLabel6.setText("验证码不能为空");
}
if(str1.equals("")==false&&
str2.equals("")==true&&
str3.equals("")==false&&
str4.equals("")==false) {
jLabel6.setText("密码不能为空");
}
if(str1.equals("")==true&&
str2.equals("")==false&&
str3.equals("")==false&&
str4.equals("")==false) {
jLabel6.setText("用户名不能为空");
}

}
});





jButton.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
int index=(int)(Math.random()*8999+1000);
String b=index+"";
jLabel5.setText(b);//验证码随机数
}
});


pb.setStringPainted(true);
pb.setBorderPainted(true);
pb.setForeground(Color.GREEN);
pb.setBackground(Color.WHITE);
pb.setBounds(300, 800, 500, 20);//滚动条大小颜色,位置


jFrame.add(myPanel);
myPanel.add(jLabel6);
myPanel.add(jButton);
myPanel.add(jButton2);
myPanel.add(pb);
myPanel.add(tf);
myPanel.add(tf2);
myPanel.add(tf3);
myPanel.add(tf4);
myPanel.add(jLabel5);
myPanel.add(jLabel4);
myPanel.add(jLabel3);
myPanel.add(jLabel2);
myPanel.add(jLabel1);
myPanel.add(jLabel);//将所有东西赋到面板上

myPanel.setLayout(null);
jFrame.setVisible(true);

}

public void run() {
for (int i=0;i<100;i++) {
pb.setValue(i);
try{Thread.sleep(1000);}
catch (InterruptedException e) {
e.printStackTrace();//滚动条从0-100

}
}

}
public static void main(String[] args) {
new Test01();
}}

猜你喜欢

转载自www.cnblogs.com/zmzz/p/9238003.html