import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.JLabel;
import java.awt.Dimension;
import javax.swing.JPasswordField;
public class VerificationCode extends JFrame implements ActionListener{
private JLabel usernameLabel;
private JTextField usernameTextField;
private JLabel passwordLabel;
private JTextField passwordField;
private JLabel VerificationCodeLabel;
private JTextField VerificationCodeField;
private JButton ramstr;
private JLabel haha;
private JButton bu1;
private JButton bu2;
public void add(JFrame frame) {
frame.setTitle("请登录");
frame.setLayout(null);
usernameLabel =new JLabel("登录名");
usernameLabel.setBounds(60, 40, 70, 30);
usernameLabel.setFont(new Font("黑体",Font.BOLD,16));
usernameTextField =new JTextField();
usernameTextField.setBounds(140,45,120,20);
usernameTextField.setFont(new Font("宋体",Font.BOLD,16));
usernameTextField.setHorizontalAlignment(JTextField.CENTER);
passwordLabel =new JLabel("密码");
passwordLabel.setBounds(60, 70, 70, 30);
passwordLabel.setFont(new Font("黑体",Font.BOLD,16));
passwordField =new JPasswordField();
passwordField.setBounds(140,75,120,20);
passwordField.setFont(new Font("宋体",Font.BOLD,16));
haha =new JLabel("忘记用户名/密码?");
haha.setForeground(Color.blue);
haha.setBounds(260, 70, 140, 30);
haha.setFont(new Font("汉真广标",Font.BOLD,10));
VerificationCodeLabel =new JLabel("验证码");
VerificationCodeLabel.setBounds(60, 100, 70, 30);
VerificationCodeLabel.setFont(new Font("黑体",Font.BOLD,16));
VerificationCodeField =new JTextField();
VerificationCodeField.setBounds(140,105,60,20);
VerificationCodeField.setFont(new Font("宋体",Font.BOLD,16));
ramstr =new JButton();
ramstr.setText(ram());
ramstr.setBackground(Color.black);
ramstr.setForeground(Color.CYAN);
ramstr.setBounds(220, 100, 100, 30);
ramstr.setFont(new Font("汉真广标",Font.BOLD,16));
ramstr.addActionListener(this);
ramstr.setToolTipText("眼瞎?换一张?");
getContentPane().add(ramstr);
bu1=new JButton();
bu1.setText("登陆");
bu1.setBackground(Color.ORANGE);
bu1.setForeground(Color.white);
bu1.setBounds(120, 145, 120, 30);
getContentPane().add(bu1);
bu2=new JButton();
bu2.setText("快速注册");
bu2.setBounds(120, 185, 120, 30);
getContentPane().add(bu2);
frame.add(usernameLabel);
frame.add(usernameTextField);
frame.add(passwordLabel);
frame.add(passwordField);
frame.add(haha);
frame.add(VerificationCodeLabel);
frame.add(VerificationCodeField);
frame.add(ramstr);
frame.add(bu1);
frame.add(bu2);
}
public String ram() {
String result = "";
for(int i = 0 ; i < 6 ; i ++)
{
int intVal = (int)(Math.random() * 26 + 97);
result = result + (char)intVal;
}
return result;
}
public void actionPerformed(ActionEvent e) {
ramstr.setText(ram());
}
public static void main(String []args) {
JFrame frame =new JFrame("JFrame窗口");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400,300);
Dimension displaySize =Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize= frame.getSize();
if(frameSize.width>displaySize.width)
frameSize.width=displaySize.width;
if(frameSize.height>displaySize.height)
frameSize.height=displaySize.height;
frame.setLocation((displaySize.width-frameSize.width),(displaySize.height-frameSize.height));
VerificationCode Swing=new VerificationCode();
Swing.add(frame);
frame.setVisible(true);
}
}
验证码登陆界面
猜你喜欢
转载自www.cnblogs.com/kt-xb/p/9752547.html
今日推荐
周排行