Saturday, November 10th, 2007
// Add the description to the Icons menu sectionMenu.add(new MenuItem(desc)); } // Add the Icons menu to the menu bar menuBar.add(sectionMenu); // Set the menu bar setMenuBar(menuBar); Notice that the Hashtable containing a list of the image categories is used to create our menu. The only way to examine the contents of a Hashtable without knowing each of the keys is to create an Enumeration object, which can be used to get the next key value of the Hashtable. Figure 8.1 shows our database-driven menu. Figure 8.1 The IconStore menu. Creating The Lists Next on our agenda: creating the list boxes containing the image descriptions. We ll create a list for each category, so when the user selects a category from the Icons menu, only a list of the images for the selected category will be shown. We ll use a CardLayout to do this, which is a nifty way to set up any number of lists and switch between them effortlessly. For each of the categories that we read from the ICONCATEGORY table, we also read each of the image descriptions for that category from the ICONSTORE table and store those descriptions in a Hashtable for use later. At the same time, we add each description to a list for the category. Listing 8.6 shows the code used to read the ICONSTORE table. Listing 8.6 Reading the ICONSTORE table. // // getIconDesc // Read the IconStore ICONSTORE table and create a Hashtable // a list of all the icons for the given category. The key is the // icon containing description and the data value is the icon ID. The // description is also added to the List object given. // public Hashtable getIconDesc( Connection con, String category, List list) {
If you need complete reliable cheap web hosting package, you come to right place. We offer all you need just check our cheap web hosting package section.