-1

is there a way i could make a button display a form only once? that is i have two jframe(courses and main page);at one jframe (main page),i have a jbutton that when i click on it the other jframe opens(the code at the button's event:

courses frame=new courses(); frame.setVisible(true);

but the issue is that i want when the jframe opens and i click on the button agin while it is open, not to display the the same form again not unless i have closed the opened one.

Thanks in advance

mnmyles
  • 75
  • 1
  • 6
  • You should rephrase the name to a question. For example: "How to display a JFrame only once on button-click?" Also it woul be better to change the tags to match the content of your question as it does not have anything to do with netbeans6.5. Possible Tags: Java Swing JFrame – Roland Schneider Jul 03 '09 at 08:25

2 Answers2

1

Don't new courses() everytime you click the button. Put the variable as a field in you main class.

J-16 SDiZ
  • 26,473
  • 4
  • 65
  • 84
1

You should add the frame as a member of the class, then when the button is clicked you can do:

if (this.frame == null)
    this.frame = new courses();

if (!this.frame.isVisible())
    this.frame.setVisible(true);
William
  • 13,332
  • 13
  • 60
  • 73