Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Need  help in design

Posted on 2002-05-24
7
Medium Priority
?
189 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
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 92

Accepted Solution

by:
objects earned 600 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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 “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Suggested Courses

916 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