• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to override form default close operation

 
Azeem Rathore
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi i am new to programming and learning java and my first language is not English to hope you can understand my problem
i am working on human resource Management system
i have 6 forms which contain different information from database now i am making menu screen i have added menu bar and in the menu bar items are Departments, hr Units , Employees and so on
now i want is when user select departments it hide the menu screen and display display form i am able to do this successfully now i want to go back to previous menu screen when user close the department window
i am using netbeans so it is not allowing me to change the INITCOmponents function used in the forms constructor to change it
so please help me how to do this .
 
Ramesh Pramuditha Rathnayake
Ranch Hand
Posts: 178
2
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't change the code manually(That means by typing..). You have to change the property values of the JFrame. Goto Design widow of the frame. Then you can see property toolbox in a corner. You can change the properties of the JFrame (such as defalutCloseOperation..) from there.

And remember that, This is not overriding..!!
 
K. Tsang
Bartender
Posts: 3610
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you using the Netbean's GUI code generator thing? I highly recommend you don't, except for fast "sample" demos.

Azeem Rathore wrote:when user select departments it hide the menu screen and display display form i am able to do this successfully now i want to go back to previous menu screen when user close the department window


When you say "go back to previous menu screen when user close department window", is the department window a JDialog modal popup? Is the menu screen part of the main JFrame window?
 
Azeem Rathore
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes , menu screen is jframe and in the jframe i am using menu bar when i run the program And click on departments from menu new department form open
One approach is add exit button in all forms so when click on exit i show menu screen but this is not my teacher want he said on exit department form menu screen appear
Netbeans. Generated code which is uneditAble and i know from properties panel i can change on exit property but
It it for departments form how to display menu screen? When exit the department form?
 
Ramesh Pramuditha Rathnayake
Ranch Hand
Posts: 178
2
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is Departments from a JFrame or JDialog..?? If it is a Frame, insert a public method called setParent(JFrame parent) in Department form.


In menu screen, write this inside the department menu actionPerformed method.


Override windowClosing(...) method in Department form and insert,


The defaultCloseOperation of Department form should be DISPOSE_ON_CLOSE..

If Department is a JDialog, you can do this easily. Refer JDialog in API. You will be able to find how to do..



 
Azeem Rathore
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ramesh thanks for the reply but i do not know how to Override windowClosing(...) method in Department form can you please tell me this? i have done everything except lnserting parent.setVisible(true);
can you tell me where i do this ? and how to do this?
thanks
 
Ramesh Pramuditha Rathnayake
Ranch Hand
Posts: 178
2
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Goto design window and right click on Frame.
Then goto Events-->Window-->windowClosing
 
Azeem Rathore
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks alot ramesh , it is working as i want thanks alot
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!