1

I have two forms form1 and form2. I want when i setVisible(false) form1, then form2 also automatically setVisible(false). So, how to use a single command setVisible but immediately close two forms.

Or maybe how to make form2 be like confirmdialog. so, do not get into Form1, if form2 has not closed

How can i do it?

dtnder
  • 381
  • 2
  • 10
  • 25

3 Answers3

2

Maybe just check if form1 isVisible(form1) and if so, just setVisible(false). Is this what you want?

And another thing comes in my mind. Depends what you want to do, maybe use dispose() instead of setVisible().

Hope I could help.

0

Write a method for this and use it instead:

private void setFormsVisible(boolean b) {
  form1.setVisible(b);
  form2.setVisible(b);
}

You forms should be class-variables then. You could also try to make the forms final, and override the setVisible-method of form1.

Blacklight
  • 3,809
  • 2
  • 33
  • 39
0

form2 should be a modal dialog with the parent set to form1. This will prevent interaction with form1 until form2 is closed.

jasg
  • 182
  • 2
  • 10