Solved

Need  help in design

Posted on 2002-05-24
7
182 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Starting to learn JAVA, 7 59
recursion example 16 111
diffSum example 4 26
web services creation SOAP vs REST 5 20
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

867 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