import java.util.ArrayList;
import javax.swing.*;
import java.awt.*;
import java.io.*;
public class Login {
private JFrame theWind;
//private JPanel thePane;
private JLabel title;
private JButton ok;
//private JButton cancel;
private JTextField theText;
public Login(){
}
public void open(){
theWind = new JFrame("Login");
title = new JLabel("Please Enter Your Voter ID:");
ok = new JButton("OK");
//cancel = new JButton("Cancel");
theText = new JTextField();
theWind.setLayout(new BorderLayout());
theWind.add(title,BorderLayout.NORTH);
theWind.add(theText,BorderLayout.CENTER);
theWind.add(ok,BorderLayout.SOUTH);
theWind.pack();
theWind.setVisible(true);
}
}
我道歉这不是完整的程序所以有些变量尚未使用。所以当我点击另一个JFrame上的按钮时,这个JFrame应该打开。当它遇到设置Jframe值的行时会发生此问题。 (下面的代码)。
theWind = new JFrame("Login");
我遇到运行时错误,声称该行有NullPointerException。我检查了JFrame是否被声明,它是。考虑到我的其他JFrame运行正常,并且我已经导入了所有必需的java库,这很奇怪。我有一个JPanel和一个JButton评论,因为我试图弄清楚这些东西是否搞乱了borderlayout,但我不认为这是问题所在。这是一个相对较短的代码,我真的很难过。我很乐意收到任何意见/建议。谢谢!