请编写一个用户登录界面,界面中必须要有文本控件(TextView)、编辑框(EditText)、按

请编写一个用户登录界面,界面中必须要有文本控件(TextView)、编辑框(EditText)、按钮(Button),分别用于显示用户名、密码,输入用户名、密码,登录功能

package com.zhidao20190103;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

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 Test extends JFrame {
    // 定义组件
    JPanel jp1, jp2, jp3;
    JLabel jl1, jl2;
    JTextField jtf;
    JPasswordField jpf;
    JButton jb1, jb2;

    public static void main(String[] args) {
        Test test = new Test();
    }

    // 构造函数 初始化组件
    public Test() {
        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("取消");

        jb1.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                JFrame frame = new JFrame("成功");
                frame.setLayout(null);
                frame.setBounds(0, 0, 200, 100);
                frame.setVisible(true);
                frame.setLocationRelativeTo(null);
            }
        });
        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(400, 400);
        this.setLocationRelativeTo(null);
        this.setResizable(true);
        this.setVisible(true);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

}

温馨提示:答案为网友推荐,仅供参考
第1个回答  2019-01-03
第101回 大观园月夜警幽魂 散花寺神签占异兆 第102回 宁国府骨肉病灾祲 大观园符水驱妖孽

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网