AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Re: App Architecture II

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java GUI Toolkits
View previous topic :: View next topic  
Author Message
Alan Moore
Guest





PostPosted: Thu Nov 06, 2003 9:31 pm    Post subject: Re: App Architecture II Reply with quote



On 6 Nov 2003 07:42:21 -0800, [email]ruipacheco (AT) hotmail (DOT) com[/email] (Rui Pacheco)
wrote:

Quote:
I am developing an Swing application. The application has the
following objects: a menu, a toolbar, an action shared by both and a
jtree.

Now, my problem is, how to make those objects communicate. When I
press an JMenuItem on the menu or a button on the toolbar I call the
action object and it performs some sort of action upon the jtree.

But how do I handle the communication between the JTree and the
Action?

Stash a reference to the JTree where you can access it with a static
method. If you're subclassing JTree, you could put the method in the
Tree class itself:

tree = MyTree.getTree();

That's essentially how the Swing text package does it: JTextComponent
keeps a static reference to the currently-focused component, which is
used by TextAction to determine which component to act on, in case it
can't be determined from the ActionEvent.

Or, if you have a class that represents the application as a whole, or
a class that represents the overall state of the app, you could put
the getTree() method there.

Back to top
R. Kevin Cole
Guest





PostPosted: Fri Nov 07, 2003 12:03 am    Post subject: Re: App Architecture II Reply with quote



One approach is to have your actions extend AbstractAction and
have them reference an object passed to them in their constructor.

For example,

public class MyAction extends AbstractAction
{
private JTree myTree;

public MyAction( JTree tree )
{
this.myTree = tree;
}

public void actionPerformed( ActionEvent e )
{
this.myTree.doSomething().
}
}

In general I create an application interface and pass that
to the AbstractAction classes, rather than passing a
specific GUI object.

Hope this helps,

Kevin


[email]ruipacheco (AT) hotmail (DOT) com[/email] (Rui Pacheco) wrote:

Quote:
Hi everyone

I can't get past this problem. As far as this project is concerned,
this is the only thing separating em from Nirvana. I have asked this
question before, in an oversimplified manner so I'm developing the
question more this time.

I am developing an Swing application. The application has the
following objects: a menu, a toolbar, an action shared by both and a
jtree.

Now, my problem is, how to make those objects communicate. When I
press an JMenuItem on the menu or a button on the toolbar I call the
action object and it performs some sort of action upon the jtree.

But how do I handle the communication between the JTree and the
Action?


This is not a Java or Swing problem, it's rather one inherent to
object oriented development. Any detailed answers or pointers to sites
explaining how to handle this are more than welcome. Even google
keywords are welcome.

Thank you very much
Rui Pacheco


Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java GUI Toolkits All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.