tags:

views:

106

answers:

3

hello every one? 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

A: 

this might sound rude, but I think you are in need of a boolean. JFrame has a method getVisible() to determine wether or not this is the visible frame. You should check for it before the button event. Otherwise I didn't understand your question.

ONi
+1  A: 

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

J-16 SDiZ
A: 

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