Hey so I am working on a system login window for my computer science course. The professor wants a system login window with a checkbox to mark if username is case sensitive and another check box to show the password. So far my code compiles but it will not run and I cant figure out why, my code isn't finished but Im unsure where to go from here. When I compile I get the following
----jGRASP exec: java Win_SystemLogin
Exception in thread "main" java.lang.NullPointerException
at java.awt.Container.addImpl(Container.java:1097)
at java.awt.Container.add(Container.java:417)
at Win_SystemLogin.CreateComponents(Win_SystemLogin.java:71)
at Win_SystemLogin.<init>(Win_SystemLogin.java:37)
at Win_SystemLogin.main(Win_SystemLogin.java:100)
----jGRASP wedge2: exit code for process is 1.
Here is my code
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Win_SystemLogin extends JFrame
{
final String SYS_USERNAME = "Fernando";
final String SYS_PASSWORD = "Zavala";
int WIN_WIDTH = 400;
int WIN_HEIGHT = 400;
private JPanel panelN;
private JPanel panelS;
private JPanel panelE;
private JPanel panelW;
private JPanel panelC;
private JLabel attemptsLabel;
private JTextField attemptsTextField;
private JLabel userNameLabel;
private JTextField userNameJTextField;
private JLabel passwordLabel;
private JTextField passwordJTextField;
private JButton loginButton;
private JButton exitButton;
private JCheckBox caseSensitiveCheckBox;
public Win_SystemLogin()
{
setTitle("System Login");
setSize(WIN_WIDTH, WIN_HEIGHT);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new BorderLayout() );
CreateComponents();
add (panelN,BorderLayout.NORTH);
add (panelS,BorderLayout.SOUTH);
add (panelE,BorderLayout.EAST);
add (panelW,BorderLayout.WEST);
add (panelC,BorderLayout.CENTER);
setVisible(true);
loginButton.addActionListener(new ButtonListener());
exitButton.addActionListener(new ButtonListener());
}
private void CreateComponents()
{
userNameLabel = new JLabel("Username");
passwordLabel = new JLabel("Password");
userNameJTextField = new JTextField();
passwordJTextField = new JTextField();
attemptsLabel = new JLabel("Attempts");
attemptsTextField = new JTextField(10);
loginButton = new JButton("Login");
exitButton = new JButton("Exit");
JPanel panelN = new JPanel();
JPanel panelE = new JPanel();
JPanel panelS = new JPanel();
JPanel panelW = new JPanel();
JPanel panelC = new JPanel();
panelC.add(userNameLabel);
panelC.add(userNameJTextField);
panelC.add(passwordLabel);
panelC.add(passwordJTextField);
panelE.add(attemptsLabel);
panelE.add(attemptsTextField);
panelE.add(caseSensitiveCheckBox);
panelS.add(loginButton);
panelS.add(exitButton);
pack();
setVisible(true);
}
private class ButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
String actionCmd = e.getActionCommand();
if (actionCmd.equals("Login"))
{
JOptionPane.showMessageDialog(null,"Welcome" );
}
else if(actionCmd.equals("Exit"))
{
System.exit(0);
}
}
}
public static void main(String args[])
{
new Win_SystemLogin();
}
}