Skip to content
Advertisement

Java Swing Application Window – Second Form showing empty

The first class or JFrame that displays just fine

JavaScript

And now my second class.. I’m sorry I’m a complete noob, when I run the debugger it looks like Options Menu is constructing correctly, but then it just displays as the minimize, full screen and exit button and nothing else. It will also run perfectly fine independently if I run it on it’s own page. I’m really confused at this point and would appreciate any help. I have seen a lot of examples on here where the JFrame isn’t set to isVisible or instantiated, but that isn’t the case here. Thank you so much for any help!

JavaScript

Advertisement

Answer

The problem is that your classes (ATM_Display and OptionsMenu) extend JFrame but are never really used as JFrames (you create a separate JFrame instance in each).

That means that when you make the OptionsMenu visible there is nothing to show (because you add all elements to the OptionsMenu.frame).

You should drop the extends clause:

JavaScript

and

JavaScript

Now you will have a compile error in ATM_Display on the following line because the OptionsMenu doesn’t have a setVisible() method:

JavaScript

To make the code work again the OptionsMenu needs this setVisible() method to make its frame visible:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement