Hi, I'm having some problems with my program and I'm not sure how to fix them. I have a main method that starts out with a frame.
public class Cryptography
{
public static void main(String[] args)
{
CryptoMainMenu mainMenu = new CryptoMainMenu();
JFrame frame = new JFrame("Cryptography");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(mainMenu);
frame.pack();
frame.setVisible(true);
}
}
In CryptoMainMenu, I've basically just added some panels from my Templates class and a button to primaryPanel. When the algorithm button is pressed it goes to CryptoCategoriesMenu.
public class CryptoMainMenu extends JPanel implements ActionListener {
public CryptoMainMenu()
{
Templates template = new Templates();
//setting up the primary panel
primaryPanel = new JPanel();
primaryPanel.setLayout(new BorderLayout());
//setting up algorithm button
algorithm = new JButton("Algorithm");
algorithm.addActionListener(this);
getContentPane().add(primaryPanel);
setSize(730, 400);
}
}
My first problem is that I get the error IllegalArguementException: adding window to container. I'm not understanding why I'm getting this error though. I've had similar programs before and they worked.
public class CryptoCategoriesMenu extends JFrame implements ActionListener
{
if (event.getSource() == back)
{
CryptoMainMenu main = new CryptoMainMenu();
main.setVisible(true);
this.setVisible(false);
}
}
My second problem is that I can't use getContentPane() in CryptoMainMenu if I'm extending JPanel but if I get rid of it and just have add(primaryPanel), then my program doesn't work because I linked all of my GUI classes together, so that when it gets to CryptoCategoriesMenu, and if I try pressing back, CryptoMainMenu shows as blank.