import javax.swing.*;标签:JLabel,int,18,add,new,周一,jf,JTextField From: https://www.cnblogs.com/jiajiayu/p/17713180.html
import java.awt.*;
import java.util.Random;
public class denglujiemian {
public denglujiemian() {
}
public void initUI(){
//创建对象
JFrame jf = new JFrame ();
//设置窗体名称
jf.setTitle ("登录界面");
//设置窗体大小(宽,长)
jf.setSize(500,250);
jf.setResizable(false);
jf.setLocationRelativeTo(null);
//点击关闭按钮时,退出程序
jf.setDefaultCloseOperation(3);
//流式布局
FlowLayout flow = new FlowLayout ();
jf.setLayout(flow);
//创建按钮
JButton btn = new JButton ("登录");
//创建标签
JLabel namejia = new JLabel("账号");
JLabel password=new JLabel("密码");
JLabel captcha=new JLabel("验证码");
//创建输入框
JTextField nameInput1 = new JTextField();
JTextField nameInput2 = new JTextField();
JTextField nameInput3 = new JTextField();
//生成验证码
String result = "";
for(int i = 0 ; i < 6 ; i ++)
{
Random r=new Random();
int a=r.nextInt(3);
int intVal;
if(a==0) {
intVal = (int) (Math.random() * 26 + 97);
}else if(a==1){
intVal=(int)(Math.random()*26+65);
}else{
intVal=(int)(Math.random()*10+48);
}
result = result + (char)intVal;
}
System.out.println(result);
/*
Random r=new Random();
int a=r.nextInt(100);
int b=r.nextInt(100);
JTextField nameInput4 = new JTextField(a+"+"+b+"=?");
*/
JTextField nameInput4 = new JTextField(result);
btn.setText("登录");
//尺寸 Dimension 此处应结合窗口大小去尝试并选取比较美观的的输入框尺寸
Dimension dim = new Dimension(200,50);
nameInput1.setPreferredSize(dim);
nameInput2.setPreferredSize(dim);
nameInput3.setPreferredSize(dim);
nameInput4.setPreferredSize(dim);
jf.add(namejia);
jf.add(nameInput1);
jf.add(password);
jf.add(nameInput2);
jf.add(captcha);
jf.add(nameInput3);
jf.add(nameInput4);
jf.add(btn);
jf.setVisible(true);
}
public static void main(String[] args) {
denglujiemian loginui = new denglujiemian();
loginui.initUI();
}
public String toString() {
return "denglujiemian{}";
}
}
这是使用Java自带的命令框所做的登录界面