hu825065235
hu825065235
2012-07-22 23:00

SWING做简单的登录界面,抛出空指针异常

  • 空指针异常

package com.hu.login;

import java.awt.*;
import javax.swing.*;

public class Loginframe extends JFrame {

/**
 * 
 */
private static final long serialVersionUID = 1L;
/**
 * @param args
 */
JPanel jp1, jp2;
JLabel jl1, jl2;
JButton jb1, jb2;
JTextField jtf;
JPasswordField jpf;

public static void main(String[] args) {
    // TODO Auto-generated method stub
    Loginframe lf = new Loginframe();
}

public Loginframe() {
    jl1 = new JLabel("用户名:");
    jtf = new JTextField(10);
    jl2 = new JLabel("密  码:");
    jpf = new JPasswordField();
    jb1 = new JButton("登录");
    jb1 = new JButton("取消");

    jp1 = new JPanel();
    jp2 = new JPanel();

    jp2.add(jl1);
    jp2.add(jtf);
    jp2.add(jl2);
    jp2.add(jpf);
    jp2.add(jb1);
    jp2.add(jb2);

    this.setSize(400, 400);
    this.setTitle("登录界面");

    this.add(jp1, BorderLayout.NORTH);
    this.add(jp2, BorderLayout.SOUTH);

    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.setVisible(true);

}

}

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答

为你推荐

换一换