Solved

Any idea how to do this?

Posted on 2001-07-29
2
149 Views
Last Modified: 2010-03-31
hi there,
I'm new in Java programming, so i don't know either i can do this in Java programming. What i'm trying to do is...

I want create a class that will dynamically create Menu based on the information store in a database. This mean every time i call the function in the class, the function will retrieve data from database such as Menu Description and create the menu accordingly. What i have in my idea is i will have 3 class. The First is used to create the menu, the second one is a main class file which will call the createMenu method in the first class file and the third act as Menu Listener.
Actually i had successfully finish the first and the second part but my problem here is how can i create another class file that act as the listner for all the menu item created?

i would be very grateful if somebody out there can help..
thanks a lot..

0
Comment
Question by:pleasure
2 Comments
 
LVL 7

Accepted Solution

by:
tomboshell earned 100 total points
ID: 6333322
The tricky part is recognizing the text stored in the menu items when using the Listener.  I usually extend the ActionListener (new class) and implement the public void actionPerformed(ActionEvent e) method.  In there a comparisson is made with the event triggered (e) and the stored string array containing the menu items.  Somewhere you must know what the string values to be expected are.  You could implements a string comparrison for all possible values, when one hits then goto a switch statement for executing the appropriate method.  Then declare an instance of the action handler class in your menu creation class and add the action listener with handler to each item.  ie (item1.addActionListener(myHandler);)  
could be something like this....
public class FileEvents implements ActionListener {
     String[] fileNames;
     Tester t;
     public FileEvents(String[] names, Tester test){
          fileNames=names;
          t=test;
     }
     public void actionPerformed(ActionEvent e){
         
          String name=e.getActionCommand();
          System.out.println("the value is =" + name);
          int i=0;
          while (name.compareToIgnoreCase(fileNames[i]) != 0){
               i++;
          }
          switch(i){
               case 0: t.newAction();
                         break;
               case 1: t.openEditAction();
                         break;
               case 2: t.openViewAction();
                         break;
               case 3: t.saveAction();
                         break;
               case 4: t.saveAsAction();
                         break;
               case 5: t.closeAction();
                         break;
               case 6: int confirm=JOptionPane.showConfirmDialog(null,"Are you sure you want to Exit the program?",
               "Exit Confirmation", JOptionPane.YES_NO_CANCEL_OPTION);
                         if (confirm==JOptionPane.YES_OPTION) System.exit(0);
                         else break;
               default: break;

          }
     }
}

Tom
0
 

Author Comment

by:pleasure
ID: 6698138
since there is no response from other experts, i decided to close the question.

Tombo:
since you are the only one reply to me... so i award u the point for your sincerity..thanks..:)
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

773 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