zoukankan      html  css  js  c++  java
  • 登录界面

    源代码:

    import java.awt.Component;

    import java.util.Random;

    import java.util.concurrent.Callable;

    import java.awt.event.MouseAdapter;

    import java.awt.event.MouseEvent;

    import javax.swing.JOptionPane;

    import javax.swing.JButton;

    import javax.swing.JFrame;

    import javax.swing.JLabel;

    import javax.swing.JPanel;

    import javax.swing.JPasswordField;

    import javax.swing.JTextField;

    public class SwingLoginExample

    {

        private static String result;

        public static void main(String[] args)

        {    

            // 创建 JFrame 实例

            JFrame frame = new JFrame("Login Example");

            // Setting the width and height of frame

            frame.setSize(500, 200);

            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

            /* 创建面板,这个类似于 HTML div 标签

             * 我们可以创建多个面板并在 JFrame 中指定位置

             * 面板中我们可以添加文本字段,按钮及其他组件。

             */

            JPanel panel = new JPanel();    

            // 添加面板

            frame.add(panel);

            /*

             * 调用用户定义的方法并添加组件到面板

             */

            placeComponents(panel);

            // 设置界面可见

            frame.setVisible(true);

         }

        private static void placeComponents(JPanel panel)

        {

            /* 布局部分我们这边不多做介绍

             * 这边设置布局为 null

             */

        

          new Random();

            result="";

       int intVal =new Random().nextInt(999999);

       result = result + intVal;

            

            panel.setLayout(null);

            // 创建 JLabel

            JLabel userLabel = new JLabel("用户名:");

            /* 这个方法定义了组件的位置。

             * setBounds(x, y, width, height)

             * x y 指定左上角的新位置,由 width height 指定新的大小。

             */

            userLabel.setBounds(10,20,80,25);

            panel.add(userLabel);

            /*

             * 创建文本域用于用户输入

             */

            JTextField userText = new JTextField(20);

            userText.setBounds(100,20,165,25);

            panel.add(userText);

            // 输入密码的文本域

            JLabel passwordLabel = new JLabel("密码:");

            passwordLabel.setBounds(10,50,80,25);

            panel.add(passwordLabel);

            /*

             *这个类似用于输入的文本域

             * 但是输入的信息会以点号代替,用于包含密码的安全性

             */

            JPasswordField passwordText = new JPasswordField(20);

            passwordText.setBounds(100,50,165,25);

            panel.add(passwordText);

            

            //输入验证码的文本域

            JLabel codeLabel = new JLabel("验证码:");

            codeLabel.setBounds(10,80,80,25);

            panel.add(codeLabel);

            

            JTextField codeText = new JTextField(20);

            codeText.setBounds(100,80,165,25);

            panel.add(codeText);

            

            JLabel yanzhengLable=new JLabel("验证码:"+result);

            yanzhengLable.setBounds(280,80,300,25);

            panel.add(yanzhengLable);

            // 创建登录按钮

            JButton loginButton = new JButton("login");

            loginButton.setBounds(10, 110, 80, 25);

            panel.add(loginButton);

           // mouseClicked(loginButton) ;

            JButton registerButton = new JButton("register");

            registerButton.setBounds(140, 110, 80, 25);

            panel.add(registerButton);

           // mouseClicked(registerButton) ;

        }

    }

    截图:

     

  • 相关阅读:
    Snmpwalk
    本地使用PostMan测试接口没有问题,但是线上直接进不了接口
    redis使用注意事项
    线程笔记
    springboot笔记
    springboot中多个地址指向同一个方法
    开发过程中遇到的注解
    使用maven时用到的一些问题
    遇到线程安全问题的案例
    mongodb
  • 原文地址:https://www.cnblogs.com/zhangliqiangvictory/p/7644982.html
Copyright © 2011-2022 走看看