Advertisement

OO Menu Design

Started by June 01, 2001 02:15 PM
1 comment, last by snowball123 23 years, 8 months ago
Hi, I''m trying to implement a menu system that is both efficient and sound. I''m coding in C++. The main classes that would somehow interact with it are Application and Game. In the menu, you should be able to start a Game via a button and the Game class will take over. Any thoughts or ideas? I''m very open. Thanks
well tbe general way is to make a set of components and a set of listener interfaces. So you might have a button class with a method called addActionListener(ActionListener a) and you might have an ActionListener interface with only the following method: abstract void ActionPerformed(ActionEvent e). Then in your application you build your menu out of various components. You make a class that implements ActionListener and overrides the method. Perhaps in your case you might have a class called GameLoader that extends ActionListener. So then you make the button and call addActionListener with the game loader. Now when someone hits the button it calls ActionPerformed on all the listeners that have registered with it (so the button will need to maintain a list of all listeners that registered with it).

This is basically how the java GUI works, it works quite nicely too. In C++ (I''m not that familiar with it sorry) you have function pointers so you might want to use them instead. Instead of making and registering various listener interfaces you would instead register function pointers with the components. Then when the action occurs you invoke all the functions.

This general way of doing things works very well in GUIs but it also works well for other things. Anytime you want something to change when something else changes consider using this strategy.
Advertisement
I think his questions is more related to the classes he would need to do his menus. Ah these unclear questions... : )

If you want to know how to implement your menu navigation, you should look into Finite State Machines. I won''t discuss them as there is a lot of infos about them if you search on the net.

As for the widget stuff, I would do something similar as JFC (Java) as suggested in the previous post. Why reinvent the wheel? : )

Patrick Lafleur

System Engineer
Creation Objet Inc.

This topic is closed to new replies.

Advertisement