• Post Reply Bookmark Topic Watch Topic
  • New Topic

frame .exit or dispose

 
Maha Hassan
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am using netbeans 4.1 guibuilder to build my guis ,,,and i want to add exit menuitem ..but the point is the builder does not name the frame so i cant not use system.exit or dispose ..
anyhelp
 
sayan maity
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whatever I got from your question you try out the following procedure. Add one menu item as exit. In the actionevent add the code JFrame.setDefaultCloseOperation(1);
 
Joe Ess
Bartender
Posts: 9362
11
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sayan, setDefaultCloseOperation() is not a static method so you can't invoke it on the classname.

Maha, you should have given us a small sample of the code JBuilder generates. Some of us don't use GUI builders (I find they generate confusing and hard-to-maintain code). Without the code we are just guessing as to what the problem is.
You say that the code "does not name the frame". I take it that the code does not create a varaible to store an JFrame instance. There must be a reference SOMEWHERE, otherwise you would not have much of a GUI. I think JBuilder has either: 1) made your class a subclass of JFrame or 2) used a short-lived variable in a constructor or other initalizer. If 1 is the case, all you have to do is invoke the correct methods on "this" (i.e. this.dispose()). If 2 is the case, you need to find where the temporary JFrame instance is declared and move it to a longer-lived declaration:

Then you can invoke methods on the instance variable aFrame.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!