2024.1.23
通过java的自带类写出了登录系统的框架,其中SWing类其中包含了设置框,设置字体以及颜色,还可以设置绝对位置。
package denglujiemian;
import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.Random;
public class denglu {
public static void main(String[] args) {
JFrame jFrame = new JFrame("登录");
//设置窗口大小
jFrame.setSize(900,507);
//先将布局管理器置为null
jFrame.setLayout(null);
//添加标签【用户名】
JLabel textUser = new JLabel("用户名:");
textUser.setForeground(new Color(0xFF0000));
textUser.setFont(new Font("黑体", Font.PLAIN,30));
textUser.setBounds(200,140,200,100);
jFrame.add(textUser);
//添加输入框【用户名输入框】
JTextField user = new JTextField(20);
user.setFont(new Font("黑体", Font.PLAIN,18));
user.setSelectedTextColor(new Color(0xFF0000));
user.setBounds(330,170,280,40);
jFrame.add(user);
//添加验证码【验证码】
String Str=y2();
JLabel yzm=new JLabel(Str+" :");
yzm.setForeground(new Color(0xFF0000));
yzm.setFont(new Font("黑体",Font.PLAIN,30));
yzm.setBounds(200,250,200,100);
jFrame.add(yzm);
//添加验证码输入框【输入框】
JTextField kuang = new JTextField(20);
kuang.setFont(new Font("黑体", Font.PLAIN,18));
kuang.setSelectedTextColor(new Color(0xFF0000));
kuang.setBounds(330,280,280,40);
jFrame.add(kuang);
//添加标签【密码】
JLabel textPassword = new JLabel("密码 :");
textPassword.setForeground(new Color(0xFF0000));
textPassword.setFont(new Font("黑体", Font.PLAIN,30));
textPassword.setBounds(200,200,200,100);
jFrame.add(textPassword);
//添加密码输入框【密码】
JPasswordField password = new JPasswordField(20);
password.setBounds(330,230,280,40);
jFrame.add(password);
//添加按钮【登录】
JButton jButton = new JButton("登录");
jButton.setForeground(new Color(0x023BF6));
jButton.setBackground(new Color(0x38FF00));
jButton.setFont(new Font("黑体", Font.PLAIN,20));
jButton.setBorderPainted(false);
jButton.setBounds(300,330,100,50);
jFrame.add(jButton);
//添加按钮【注册】
JButton register = new JButton("注册");
register.setForeground(new Color(0x0029FF));
register.setBackground(new Color(0xECA871));
register.setFont(new Font("黑体", Font.PLAIN,20));
register.setBorderPainted(false);
register.setBounds(500,330,100,50);
jFrame.add(register);
jFrame.setVisible(true);
}
public static String y2(){
ArrayList list=new ArrayList<>();
for(int i=0;i<26;i++){
list.add((char)('a'+i));
list.add((char)('A'+i));
}
String yanzheng="";
Random random=new Random();
for(int i=0;i<5;i++){
int w=random.nextInt(list.size());
char c=(char)list.get(w);
yanzheng=yanzheng+c;
}
return yanzheng;
}
}