Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / April 2005

Tip: Looking for answers? Try searching our database.

ActionListener as external class

Thread view: 
Kurt Underhay - 20 Apr 2005 12:08 GMT
I'm writing a visual app using Swing; I've got a JMenuBar in the main
frame, on of the JMenuItems in one of the JMenus is an "exit" option -
obviously when this option is chosen, I'd like the app to close. I've
been implementing this so far by making the class of the application
implement ActionListener, and adding an actionPerformed function:

...
class myGUIApp implements ActionListener{
...
   JMenuItem exit = new JMenuItem("Exit");
   exit.addActionListener(this);
...
   public void actionPerformed(ActionEvent e){
      myMainJFrame.dispose();
   }

I'd like for all ActionListener to be an external class; this of itself
is not a problem, however, I don't know how to pass the dispose()
message to the main JFrame of the app if the ActionListening is handled
externally - anybody have any pointers for me?
Arnaud Berger - 20 Apr 2005 12:35 GMT
Hi,

What about :

class ExternalListener implements ActionListener{

private JFrame frame;

public ExternalListener (JFrame _frame){

   frame=_frame;
}

   public void actionPerformed(ActionEvent e){
      frame.dispose();
   }

and addActionListener(new ExternalListener(this));

Regards,

Arnaud

> I'm writing a visual app using Swing; I've got a JMenuBar in the main
> frame, on of the JMenuItems in one of the JMenus is an "exit" option -
[quoted text clipped - 16 lines]
> message to the main JFrame of the app if the ActionListening is handled
> externally - anybody have any pointers for me?
Kurt Underhay - 20 Apr 2005 14:20 GMT
> Hi,
>
[quoted text clipped - 14 lines]
>
> and addActionListener(new ExternalListener(this));

Works like a charm - thanks for the suggestion.
Thomas Weidenfeller - 20 Apr 2005 13:05 GMT
> I'd like for all ActionListener to be an external class; this of itself
> is not a problem, however, I don't know how to pass the dispose()
> message to the main JFrame of the app if the ActionListening is handled
> externally - anybody have any pointers for me?

Some info from

http://groups.google.com/groups?selm=d2gn1a%24f7k%241%40newstree.wise.edt.ericsson.se

should be applicable in a similar way.

/Thomas

Signature

The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.