Solved

Need  help in design

Posted on 2002-05-24
7
185 Views
Last Modified: 2010-05-18
Hi,

I am designing a GUI part of an application.

-We know how the GUI screens should look like and how many screens are there etc.

- Each screen will have a MenuBar, ToolBar
and the rest of the screen(call it workarea) will have the portion divided into 3 panels. (left side, right side and bottom)

- Right side there can be some GUI components displayed and this data can keep changing depending on the navigation on left side(tree)

- What I am trying to do is provide a framework for GUi so that the developers have to plug in their individual screens in the workarea.

- As part of framework, I want to provide MenuBar, ToolBar functionality.

- Depending on what is clicked on MenuBar, the corresponding screen should get loaded

- Tool Bar has other functionality like print, save etc

- ToolBar, MenuBar do not share any functionality(Both are different and described in above two points)


The problem I have now is that :

How do I have an elegent solution for my Menubar and Tool bar listeners.

- I do not want to have if else kind of code which checks if this is clicked, do this etc.

So can I have some kind of elegent solution for this?

I am thinking that I can achieve this if I keep a map of the option pressed and the command that needs to take place.

For e.g., if save is pressed, I have a mapping for this in some hash table like :
save SaveCmd
SaveCmd class would have implemented execute() method
(Yes, I am talking of command pattern)

so I call execute() on SaveCmd.

is this the right approach?

Please send me your response.

Cheers,
kgreddy


0
Comment
Question by:kgreddy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 92

Expert Comment

by:objects
ID: 7033483
Simply implement your commands as Action's and add these Action objects directly to your menu and tool bars.
0
 
LVL 2

Author Comment

by:kgreddy
ID: 7034233
Are you saying that Command has to implement the Action interface?

I understand that I have to use command pattern
for encapsulating what needs to be done on click of a menu item.

I dont understand how exactly I have to use Action interface in cinjuction with Comandpattern.

can you give me a code snippet?
0
 
LVL 2

Author Comment

by:kgreddy
ID: 7034234
Are you saying that Command has to implement the Action interface?

I understand that I have to use command pattern
for encapsulating what needs to be done on click of a menu item.

I dont understand how exactly I have to use Action interface in cinjuction with Comandpattern.

can you give me a code snippet?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 92

Accepted Solution

by:
objects earned 150 total points
ID: 7034872
SaveAction save = new SaveAction();
menu.add(save);
toolbar.add(save);



class SaveAction extends AbstractAction
{
   public SaveAction()
   {
      super("Save");
   }

   public void actionPerfomed(ActionEvent event)
   {
      // Perform required action
   }
}
0
 
LVL 9

Expert Comment

by:Ovi
ID: 7036869
The Action interface and actionListener allready represent a implementation of the Command pattern, so you don't have to reinvent the wheel. This interfaces are part of the JDK.
0
 
LVL 35

Expert Comment

by:girionis
ID: 8797760
No comment has been added lately, so it's time to clean up this TA.

I will leave a recommendation in the Cleanup topic area that this question is:

- points to objects@idg

Please leave any comments here within the
next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

girionis
Cleanup Volunteer
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

761 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question