- /*
- * 登录框
- */
- package com.test.swing;
- import java.awt.*;
- import javax.swing.*;
- public class Test1 extends JFrame{
- //定义组件
- JPanel jp1, jp2, jp3;
- JLabel jl1, jl2;
- JTextField jtf;
- JPasswordField jpf;
- JButton jb1, jb2;
- public static void main(String[] args) {
- Test1 test = new Test1();
- }
- //构造函数 初始化组件
- public Test1(){
- jp1 = new JPanel();
- jp2 = new JPanel();
- jp3 = new JPanel();
- jl1 = new JLabel("用户名");
- jl2 = new JLabel("密 码");
- jtf = new JTextField(10);
- jpf = new JPasswordField(10);
- jb1 = new JButton("登录");
- jb2 = new JButton("取消");
- jp1.add(jl1);
- jp1.add(jtf);
- jp2.add(jl2);
- jp2.add(jpf);
- jp3.add(jb1);
- jp3.add(jb2);
- this.add(jp1);
- this.add(jp2);
- this.add(jp3);
- this.setLayout(new GridLayout(3, 1));
- this.setTitle("窗体名");
- this.setSize(200,200);
- this.setLocation(100,200);
- this.setResizable(false);
- this.setVisible(true);
- this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- }
- }
Java图形界面——登录框
最新推荐文章于 2022-08-21 16:19:57 发布