I have limited knowledge with GUI's. I am trying to create a very basic GUI and have the following so far:
public class Controller {
// variables
private JFrame ACMEFrame;
private JPanel contentPane;
private JPanel contentPanel;
private JPanel detailsPanel;
private JPanel buttonPanel;
private JLabel label;
private JComboBox box;
private JButton ok;
private JButton quit;
// constructor
public Controller() {
handleAddCruiseToShip();
}
public final void handleAddCruiseToShip() {
ACMEFrame = new JFrame("Assign Cruise to Ship"); // name of frame
ACMEFrame.setSize(600, 400); // size of JFrame
ACMEFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // exit JFrame on close
contentPanel = new JPanel();
contentPanel.setBackground(Color.GREEN);
quit = new JButton("Quit");
ok = new JButton("Ok");
detailsPanel.add(quit);
detailsPanel.add(ok);
ACMEFrame.add(detailsPanel);
ACMEFrame.pack();
ACMEFrame.setVisible(true);
}
}
However, upon running the test class(guiTest), I am coming across the following errors:
Exception in thread "main" java.lang.NullPointerException
at Controller.AddCruiseToShip(Controller.java:42)
at Controller.<init>(Controller.java:26)
at guiTest.main(guiTest.java:10)
Previously, I was able to run the test class and the GUI was displayed, however, now I am coming across errors.
This is my guiTest Class:
public class guiTest {
public static void main (String args []){
new Controller();
}
}
How do I overcome this?
Thank you.