课后作业之登陆界面

题目:请编程设计一个登陆界面,要求输入账号和密码(不考虑事件)

源代码:

package cn.whpu.action;
import java.awt.*;
import javax.swing.*;
public class LoginWindow extends JFrame{


private JPanel jp1,jp2,jp3;
private JButton jbtnLogin;
private JLabel jlbUser,jlbPasswd;
private JPasswordField jpfPasswd;
private JTextField jtfUser;


public static void main(String[] args) {
// TODO Auto-generated method stub
new LoginWindow();
}
public LoginWindow()
{
jp1 = new JPanel(new BorderLayout());
jp2 = new JPanel(new GridLayout(2,2));
jp3 = new JPanel();
jbtnLogin = new JButton("登录");
jlbUser = new JLabel("用户名:");
jlbPasswd = new JLabel("密码:");
jtfUser = new JTextField();
jpfPasswd = new JPasswordField();
jp3.add(jbtnLogin);
jp2.add(jlbUser);
jp2.add(jtfUser);
jp2.add(jlbPasswd);
jp2.add(jpfPasswd);
jp1.add(jp2);
jp1.add(jp3,"South");
this.add(jp1);
int width = Toolkit.getDefaultToolkit().getScreenSize().width;
int height = Toolkit.getDefaultToolkit().getScreenSize().height;
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLocation(width/2-200, height/2-150);
this.setSize(400, 150);
}
}

课后作业之登陆界面_第1张图片

你可能感兴趣的:(作业)