• 登录界面


    下面是用java实现的一个简陋的登录界面

    import java.awt.Dimension;
    import java.awt.FlowLayout;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JTextField;
    import javax.swing.JPasswordField;
    import javax.swing.JButton;

    //1.定义Login类,
    public class Login {
    int num = (int)(Math.random()*9999);
    // 1.在类中定义初始化界面的方法;

    public void initUI() {
    // 3.在initUI方法中,实例化JFrame类的对象。
    JFrame frame = new JFrame();
    // 4.设置窗体对象的属性值:标题、大小、显示位置、关闭操作、布局、禁止调整大小、可见、...
    frame.setTitle("登录界面");// 设置窗体的标题
    frame.setSize(400, 300);// 设置窗体的大小,单位是像素
    frame.setDefaultCloseOperation(3);// 设置窗体的关闭操作;3表示关闭窗体退出程序;2、1、0
    frame.setLocationRelativeTo(null);// 设置窗体相对于另一个组件的居中位置,参数null表示窗体相对于屏幕的中央位置
    frame.setResizable(false);// 设置禁止调整窗体大小

    // 实例化FlowLayout流式布局类的对象,指定对齐方式为居中对齐,组件之间的间隔为5个像素
    FlowLayout fl = new FlowLayout(FlowLayout.CENTER, 10, 10);
    // 实例化流式布局类的对象
    frame.setLayout(fl);

    // 实例化JLabel标签对象,该对象显示"账号:"
    JLabel labName = new JLabel("账号:");
    // 将labName标签添加到窗体上
    frame.add(labName);

    // 实例化JTextField标签对象
    JTextField textName = new JTextField();
    Dimension dim1 = new Dimension(300,30);
    //textName.setSize(dim);//setSize这方法只对顶级容器有效,其他组件使用无效。
    textName.setPreferredSize(dim1);//设置除顶级容器组件其他组件的大小
    // 将textName标签添加到窗体上
    frame.add(textName);

    //实例化JLabel标签对象,该对象显示"密码:"
    JLabel labpass= new JLabel("密码:");
    //将labpass标签添加到窗体上
    frame.add(labpass);


    //实例化JPasswordField
    JPasswordField textword=new JPasswordField();
    //设置大小
    textword.setPreferredSize(dim1);//设置组件大小
    //添加textword到窗体上
    frame.add(textword);


    // 实例化JLabel标签对象,该对象显示"账号:"
    JLabel labyanzheng = new JLabel("验证码:");
    // 将labName标签添加到窗体上
    frame.add(labyanzheng);

    // 实例化JTextField标签对象
    JTextField textyanzheng = new JTextField();
    //设置大小
    Dimension dim2 = new Dimension(100,30);
    textyanzheng.setPreferredSize(dim2);//设置除顶级容器组件其他组件的大小
    // 将textName标签添加到窗体上
    frame.add(textyanzheng);

    // 实例化JTextField标签对象
    JTextField textshu = new JTextField(num+"");
    //设置大小
    textshu.setPreferredSize(dim2);//设置除顶级容器组件其他组件的大小
    // 将textName标签添加到窗体上
    frame.add(textshu);

    //实例化JButton组件
    JButton button=new JButton();
    //设置按钮的显示内容
    Dimension dim3 = new Dimension(100,30);
    button.setText("登录");
    //设置按钮的大小
    button.setSize(dim3);
    frame.add(button);
    frame.setVisible(true);// 设置窗体为可见
    }
    //1.在类中定义主函数
    public static void main(String[] args) {
    // 2.在主函数中,实例化Login类的对象,调用初始化界面的方法。
    Login login = new Login();
    login.initUI();



    }
    }

  • 相关阅读:
    elasticsearch配置小记(转)
    valgrind详解
    elasticsearch2.x优化小结(单节点)
    使 nodejs 代码 在后端运行(forever)
    使 nodejs 代码 在后端运行(nohup)
    Flutter移动电商实战 --(16)切换后页面状态的保持AutomaticKeepAliveClientMixin
    Flutter移动电商实战 --(14)首页_拨打电话操作
    Flutter移动电商实战 --(15)商品推荐区域制作
    Flutter移动电商实战 --(11)首页_屏幕适配方案和制作
    [UI] 精美UI界面欣赏[9]
  • 原文地址:https://www.cnblogs.com/xueqiuxiang/p/11580077.html
Copyright © 2020-2023  润新知