What is the best way to code a swing application that has two windows where the first window has a button that creates the second window?
I've attached the code. You'll notice I'm creating the second window from the button handler on lines 42 and 53-48. Maybe this is the wrong way to generate a second window from a button?
On line 92, I'm trying to dispose the second window upon clicking the "Close" button. However, nothing happens when the "Close" button is clicked. I've also tried the setVisible(false) method, but get the same results.
For multiple windows you can check out using JDialog or may be using JInternalFrame within a JDesktopPane. This has been asked a few times before, so you might end up with few answers if you search in this forum.
Why would you write a 300 line program to test something?
If you want to test opening a window when clicking a button, then create a JFrame with a JButton that opens another JDialog. That should be about 20-30 lines of code. Then once you understand the basics you can apply the solution to your real program.
Rob Camick wrote:Why would you write a 300 line program to test something?
I did not write this program to solely test my problem. All other functionality of the program works except for this small piece. This is a final program that I wrote for an on-line course. I've been back and forth with the Instructor on the problem, but I'm not seeing her points. Thus, the reason I posted here. I hoped for a different perspective that might "dim up" the bulb in my thick head. I apologize for pasting a 300 line program here (I had a sense it would raise eyebrows on an internet forum), but I thought it might help provide context.
I have looked into opening a JDialog with the button, but I'm not seeing how to do it yet. Does anyone have any examples of how to do that?