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();
}}