Ok I have two frames.. one frame calls the other frame so it's like a dialog box... the second frame pops out, and yeah i want to close this second frame with a button.. how do i do it?? I was also wondering let's just say that I have two buttons in my second frame a YES and a NO... when the YES or NO gets clicked, the second frame closes.. how will the first frame will know which of the two button closed the second frame

Recommended Answers

All 9 Replies

Instead of a second frame use a dialog box. Read in this JOptionPane the static methods that begin with show...(...) .

Oh come on man.. i want a FRAME.. a window.. don't limit my creativity :(

Oh come on man.. i want a FRAME.. a window.. don't limit my creativity :(

You do know that you can handle a Dialog (or JDialog) in exactly the same way you do a JFrame, except that you do not have, per default, the min max buttons on the frame, right?

You don't have to use JOptionPane. Suggesting the use of, or using, a (J)Dialog does not "limit your creativity" in anyway, and it makes a few things in your life/coding much easier.

Edit: And a Dialog is a Window.

To close the second frame with the button you place the button where you want it, then you use actionperformed on that button. The code is:

/* jFrame1.pack();
jFrame1.setVisible(false); */

When you set the frame visible you have used setVisible with true.

I hope this helped? Because i am new of trying to explain for others.
/Me

ok this time the second frame pops up which was called by the first frame... What i want to do is to get some information to be passed into the first frame when the second frame closes. how do i do that?

ok this time the second frame pops up which was called by the first frame... What i want to do is to get some information to be passed into the first frame when the second frame closes. how do i do that?

Hi!
Well, you should probably put code under the button that are the close button (action performed). So when you close frame2 - this will happen in frame1 -, for an example in your textarea or what you use, in the place you want to show the information.
Or you can make a method with what you want to happen in frame1 and then you call that method from the close button actionperformed.

Good luck!

Of course, this is exactly what a Dialog is for...

But you don't want to limit his creativity, do you? ;-)

Of course not! :P

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.