• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Translation of a WindowEvent to ActionEvent

 
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
I'd like all actions that attempt to exit the GUI to do the same thing. As a solution I've created an ExitAction class that extends AbstractAction. However, the WindowEvents (windowClosing()) cannot directly use this new ExitAction class. In order to provide a translation I've extended WindowAdapter with a WindowAction class and provided the following implementation of windowClosing():

Can you pleae advise whether this is a suitable solution. Also can you please advise whether the id of the ActionEvent is an arbitrary integer or does it need to be specific.
Apologies if this is fairly basic but I'm new to Swing and GUI - I'm normally found stuck into J2EE!
Thanks in advance,
Steve
[ May 13, 2003: Message edited by: Steve Granton ]
 
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
you might want to have a look at the "Event Generator Idiom". here is a good article by Bill Venners:
http://www.artima.com/designtechniques/eventgen.html
cheers,
Chantal
 
Steve Granton
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
I did read this article but I'm not sure that it meets my requirement.
This details a 'one to many' relationship - i.e. a producer fires an event that is consumed by 'n' comsumers.
My situation is that there are two different producers and I want events from both to be received and processed by a single consumer - ' many to one'
I did think of making the ExitAction extend WindowAdapter but discounted this for two reasons:
1) The ExitAction class already extends AbstractAction and therefore I cannot extend another class.
2) Even if I did manage to get ExitAction to extend WindowAdapter it would not make sense for this class to also have to handle other window events since it would be registered as the Window Listener for the frame.
Thanks for the suggestion though and I found the article useful. I'm sure I'll use it elsewhere.
Steve
 
Chantal Ackermann
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
I get your point concering the "many to one" relationship. I've always used a main window and a main controller which would be notified whenever windowClosing would be called on the main window. thus I had no "many to one" relationship. Considering your situation, I think your solution is very good and flexible.
What concerns the argument you give the constructor of the ExitAction: actually, it doesn't matter what window event has been the trigger of the ExitAction (it should have been some windowClosing thing, anyway). When ExitAction.actionPerformed is called, the only thing that might be of interest is the source of the event (the window). Thus, I would call (for example):
exitAction.actionPerformed(new ActionEvent(theWindow, ActionEvent.ACTION_PERFORMED, "Exit"));
you might be interested in the "shutdown-hook":
http://www.javaspecialists.co.za/archive/Issue011.html
cheers,
Chantal
 
Steve Granton
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks,
That sounds good. I'll give it a look.
Steve
 
No more fooling around. Read this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic