TechArena Community

TechArena Community (
-   Software Development (
-   -   EventListner on Choice Menu (

Kingfisher 19-11-2009 02:30 PM

EventListner on Choice Menu
I need a help with the logic of codes that uses choice menu. I have created a program with 9 buttons in any array. When we press a button we get a corresponding value from an array of integers defined elsewhere. The value which are assigned to a particular button shows up in seperate text filed.
The difficulty which I am facing is
The array of buttons must listen to each of the selection of the choice menu, such that each item selected causes the button to pick from different sets of arrays of values when pressed I will be impressed if any one will help me out. Thanks in advance

Praetor 19-11-2009 02:34 PM

Re: EventListner on Choice Menu
You mean that when you click on a button you need to get a value from a "set of value" depending on the value of the radio button? If your answer is yes then you do no need any listeners to the radio buttons. Whenever you click the button you will get the value of the radio selected and the with a if statement you can set the value you want to take from. This is the general syntax of this

      // When a button is clicked
      actionPerformed(Action event) {
      // get the value of the choice button currently selected
      // with that choose which "set of values" you will use

If any help is need in future do post back we will solve your problem.

Kingfisher 19-11-2009 02:41 PM

Re: EventListner on Choice Menu
Thanks for for posting the syntax. I am posting my problem below step by step, please understand them and then if you know it post with a solution.
These are my choice buttons

  Choice tc;
      tc=new Choice();
      tc.addItem("A ");
      tc.addItem("B ");
      tc.addItem("C ");

These are my array values

  static final int[] fare = { 110, 200,100, 160,220,270,280,370,380 };
    static final int[] fareo={110, 110,110, 160, 160, 220,220,220,220,};
      static final int[] fares={160, 320,320, 400, 400, 400,400,400,400};

This is my listener

class ZoneListener implements ActionListener {
      public void actionPerformed(ActionEvent e) {
      amount = Integer.parseInt(e.getActionCommand());

I am providing this information see if you can help me out through any solution. Thanks in advance.

Praetor 19-11-2009 02:45 PM

Re: EventListner on Choice Menu
Just have an int[] array variable like "selectedFares[]" that points to the correct fare array. Your stateChanged method just needs to set it when they choose one. I am posting the code below, just go through it.

switch (option) {
      case 0:
      selectedFares = fare;
      case 1:
      selectedFares = fareo;
      ... etc

This should help you, if not then post back what is the problem. I will try my best to solve your problem.

All times are GMT +5.5. The time now is 10:56 AM.