Results 1 to 2 of 2
Thread: Create JMenuBar using DataBase
- 11-02-2009, 07:23 PM #1Member
- Join Date
- Oct 2009
- Rep Power
- 11-03-2009, 12:52 PM #2
I would separate the creation of the menu bar from the database part. start with getting a kind of "menu definition" data structure working to feed the creation of the jmenubar
for example a "MenuBean"
and a "MenuItemBean"
String type; // will be used to determine what Swing menu item will be created (JMenuItem, JmenuSepartor, JCheckboxMenuItem, etc)
String actionClass // the full package class to the handler when this menu item is selected.
where the action class is a string name for the handler class which would be something that implements the ActionListener interface (or any other listeners the JMenuItem wants to invoke).
alternatively we could have one big handler class and define the method to be invoked here. This is assuming we have the handler code for the menu item ahead of time, (as it the case if we wanted a dynamic JMenu from the database to show only the things the current user is allowed to do) when we create the JMenuItem we would need to either look up the object instance (e.g. spring framework, bean factory), or reflectively create it.
If we wanted to have the dynamic menu fire off a dynamic action, that is more complicated, you would need to have all jmenu items generate an event into a klnd of internal event bus, so as to provide hooks for something else to somehow act on that event.
Im sure iteration though experimentation will flush out other details of what is needed for these MenuBean and MenuItemBean classes. Note all fields here in these plain bean classes are just strings, ints,(simple types). once you have a test case able to create a JMENU from a List<MenuBean> , then it should be more obvious how to have these beans mapped to a database, using the database object mapper of your choice (jdbc, ibatis, hibernate, other?). Perhaps a menu and a menu_item table, with an additional menu_id property to link it to menu table.
- By vrk in forum Advanced JavaReplies: 2Last Post: 02-11-2009, 05:43 AM
- By cheecoo in forum Java AppletsReplies: 5Last Post: 06-12-2008, 03:50 AM
- By mathias in forum New To JavaReplies: 1Last Post: 08-07-2007, 06:48 AM
- By Jack in forum XMLReplies: 1Last Post: 07-09-2007, 12:56 AM