zoukankan      html  css  js  c++  java
  • 利用绝对布局制作登陆页面(改进)

    import java.awt.Container;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.util.Random;

    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JOptionPane;
    import javax.swing.JPasswordField;
    import javax.swing.JTextField;
    import javax.swing.WindowConstants;
    //加载包swing
    @SuppressWarnings("serial")
    public class ZC extends JFrame{
    public ZC()
    {
    String[] a={"a","s","d","f","g","h","j","k","l","q","w","e","r","t","y","u","i","o","p","z","x","c","v","b","n","m","0","1","2","3","4","5","6","7","8","9"};
    setTitle("欢迎登陆");//设置窗体标题
    setLayout(null);//窗体取消布局管理器设置
    setBounds(0,0,250,350);//定位窗体的位置与大小
    @SuppressWarnings("unused")
    Container c=getContentPane();//创建容器对象
    Random s1=new Random();
    Random s2=new Random();
    Random s3=new Random();
    Random s4=new Random();
    int i,j,k,l;
    i=s1.nextInt(35);
    j=s2.nextInt(35);
    k=s3.nextInt(35);
    l=s4.nextInt(35);
    JLabel yh=new JLabel("用户名");//创建一个用户名标签
    JLabel mm=new JLabel("密码");//创建一个密码标签
    JLabel yz=new JLabel("验证码");//创建一个验证码标签
    JTextField yh1=new JTextField(null);//添加一个文本框
    JPasswordField mm1=new JPasswordField(null);//添加一个密码框
    JTextField yz1=new JTextField(null);//添加一个文本框
    JLabel yz2=new JLabel(a[i]+a[j]+a[k]+a[l]);
    JButton b1=new JButton("登陆");
    JButton b2=new JButton("取消");
    yh.setBounds(10,30,80,30);//用户名位置和大小
    mm.setBounds(10,75,80,30);//密码标签位置和大小
    yz.setBounds(10,120,80,30);//验证码标签位置和大小
    yh1.setBounds(60,30,100,30);//用户名框位置和大小
    mm1.setBounds(60,75,100,30);//密码框位置和大小
    yz1.setBounds(60,120,100,30);//验证码框位置和大小
    yz2.setBounds(70,170,80,30);
    b1.setBounds(20,220,80,30);
    b2.setBounds(120,220,80,30);
    c.add(yh);//讲标签和框添加到容器
    c.add(mm);
    c.add(yz);
    c.add(yh1);
    c.add(mm1);
    c.add(yz1);

    c.add(b2);
    c.add(yz2);


    c.add(b1);
    class YZ implements ActionListener
    {
    public void actionPerformed(ActionEvent c)
    {
    String s1=yh1.getText().toString();
    String s2=mm1.getText().toString();
    String s3=yz1.getText().toString();
    String s4=String.valueOf(a[i]+a[j]+a[k]+a[l]);
    if(s1.equals(""))//未输入用户名
    JOptionPane.showMessageDialog(null,"请输入用户名");
    //@SuppressWarnings("deprecation")

    else if(s2.equals(""))//未输入密码
    JOptionPane.showMessageDialog(null,"请输入密码");
    else if(s3.equals(""))//未输入验证码
    JOptionPane.showMessageDialog(null,"请输入验证码");
    else if(s3.equals(s4))
    JOptionPane.showMessageDialog(null,"登陆成功");
    else//验证码错误
    JOptionPane.showMessageDialog(null,"验证码错误");
    }
    }
    class GB implements ActionListener
    {
    public void actionPerformed(ActionEvent c)
    {
    System.exit(0);
    }
    }
    b1.addActionListener(new YZ());
    b2.addActionListener(new GB());
    setVisible(true);//使窗体可见
    }
    public static void main( String args[] )
    {
    new ZC();
    }

  • 相关阅读:
    linux下区分各种SCSI磁盘类型
    Linux那些事儿之我是SCSI硬盘(3)磁盘磁盘你动起来!
    待机(STR)suspend device flow
    %pf
    ftrace misc
    reboot系统调用的时候会调用shutdown函数
    Linux进程调度
    一张图让你读懂Linux内核运行原理
    linux O1 and CFS process sched
    SQL 视图 触发器 等
  • 原文地址:https://www.cnblogs.com/love-xi/p/4857807.html
Copyright © 2011-2022 走看看