为什么会出现此异常?试图用Java创建简单的GUI

|
import java.awt.*;


import javax.swing.*;




public class userInput extends JFrame {


private JButton newEntry;
private JButton deleteEntry;
private JButton editEntry;
private JButton saveEntry;
private JButton cancelEntry;
private FlowLayout layout;





public userInput() {

    super(\"My Address Book\"); //sets the title!
    JTextField field = new JTextField(20);
    Container content = getContentPane();
    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new FlowLayout());

    buttonPanel.add(newEntry);
    buttonPanel.add(deleteEntry);
    buttonPanel.add(editEntry);
    buttonPanel.add(saveEntry);
    buttonPanel.add(cancelEntry);

    add(buttonPanel, BorderLayout.SOUTH);
    content.setLayout(new BorderLayout());
    content.add(buttonPanel, \"South\");

    setVisible(true);





}
}
这是我的驱动程序:
import javax.swing.*;



public class AddressBookGui {
   public static void main (String[] args)
   {
        userInput addressBook = new userInput();
        addressBook.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //whenever you hit x you will exit the program
        addressBook.setSize(750, 600);
        addressBook.setVisible(true);

   }
}
已邀请:
你必须在做之前初始化newEntry
newEntry = new JButton(\"foo\");
buttonPanel.add(newEntry);
连同其他按钮
您忘记分配按钮了:
newEntry = new JButton();
deleteEntry = new JButton();
...

要回复问题请先登录注册