Solved

Need  help in design

Posted on 2002-05-24
7
183 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
github account with ecipse 1 47
print map entry 34 67
even odd program using while loop 3 40
Tomcat: Unable to run tomcat service. 2 18
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
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 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…
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…

775 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