Solved

Need  help in design

Posted on 2002-05-24
7
178 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 92

Accepted Solution

by:
objects earned 150 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
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.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to implement Singleton Design Pattern in Java.

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now