My professor assigned a project where a simulation is ran through a GUI. To edit it, we need to create a ‘New’ menu item. We haven’t learned how to get data from a GUI, and our book does not cover it at all.
What I’m trying to do, is when the ‘New’ command is hit, focus gets shifted back to the CMD prompt, where System.out. starts working again and prompts the user for input.
However, when I try to implement this, my program crashes. What can I do to solve this problem?
It doesn’t look like you’re keeping the reference to your newly created GUI. As far as I remember, Java will garbage collect the FoxGui object (as well as any other object) if there are no references to that object. Try creating a global variable to store the reference to your newly created FoxGui object. Something like…