Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Same behaviour for all "Done" button  RSS feed

 
Jacky Luk
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Normally, when a form derives from GenericForm, I write form.this.dispose();
But I can't here because I don't have a reference to the derived class.
What should I write inside
private void DoneBtnActionPerformed(ActionEvent evt) {
/// What should I write here
}

So that All forms derived from GenericForm will close when the done button is pressed?
Thanks
Jack
 
K. Tsang
Bartender
Posts: 3630
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well say your GenericForm extends JFrame, and do dispose() in the done action listener. All your other forms in your app will then have to extend GenericForm. If this is the case you can use super() to trigger the GenericForm's action.

Another approach is not to extend JFrame. Then you probably want to pass in the JFrame (the one you want to dispose) to the the action listener.

Actually have you consider using an AbstractAction for the this dispose action listener?
 
Rob Camick
Ranch Hand
Posts: 2754
12
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use the SwingUtilities class to find the Window that the button was added to.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!