zoukankan      html  css  js  c++  java
  • 简单登陆验证码界面代码

    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 Number extends JFrame implements ActionListener{

    private JLabel usernameLabel;
    private JTextField usernameTextField;
    private JLabel passwordLabel;
    private JTextField passwordField;
    private JLabel NumberLabel;
    private JTextField NumberField;
    private JLabel 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));

    NumberLabel =new JLabel("验证码");
    NumberLabel.setBounds(60, 100, 70, 30);
    NumberLabel.setFont(new Font("黑体",Font.BOLD,16));
    NumberField =new JTextField();
    NumberField.setBounds(140,105,60,20);
    NumberField.setFont(new Font("宋体",Font.BOLD,16));

    String result = "";
    for(int i = 0 ; i < 6 ; i++)
    {
    int intVal = (int)(Math.random() * 26 + 97);
    result = result + (char)intVal;
    }
    ramstr =new JLabel(result);
    ramstr.setBounds(220, 100, 70, 30);
    ramstr.setFont(new Font("汉真广标",Font.BOLD,16));

    bu1=new JButton();
    bu1.setText("Enter");
    bu1.setBackground(Color.RED);
    bu1.setForeground(Color.blue);
    bu1.setBounds(120, 145,120,30);
    getContentPane().add(bu1);
    bu2=new JButton();
    bu2.setText("Fast Register");
    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(NumberLabel);
    frame.add(NumberField);
    frame.add(ramstr);
    frame.add(bu1);
    frame.add(bu2);
    }

    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));
    Number Swing=new Number();
    Swing.add(frame);
    frame.setVisible(true);
    }
    }

  • 相关阅读:
    postman接口测试01_下载安装
    Jenkins持续集成_05_参数化构建
    IntelliJ 中设置与Eclipse中 Ctrl+1 功能类似的快捷键
    JAVA 内部类
    Adobe Air 现在可支持X86的移动设备
    开发一些自动编写代码的工具可以增加效率吗?
    制作 Flex 悬停提示帮助文档(转)
    没什么好说的
    JDK,Tomcat,Maven,Mysql环境变量配置
    神器三、Android端神器东皇钟:天界之门
  • 原文地址:https://www.cnblogs.com/lover995/p/9753208.html
Copyright © 2011-2022 走看看