Results 1 to 4 of 4

Thread: EventListner on Choice Menu

  1. #1
    Join Date
    Jul 2009
    Posts
    188

    EventListner on Choice Menu

    Hi
    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

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: EventListner on Choice Menu

    Hi
    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
    Code:
       
          // 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.

  3. #3
    Join Date
    Jul 2009
    Posts
    188

    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
    Code:
       Choice tc;
          tc=new Choice();
          tc.addItem("A ");
          tc.addItem("B ");
          tc.addItem("C ");
    These are my array values
    Code:
       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
    Code:
     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.

  4. #4
    Join Date
    Apr 2008
    Posts
    1,948

    Re: EventListner on Choice Menu

    Hi
    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.
    Code:
     switch (option) {
          case 0:
          selectedFares = fare;
          break;
          case 1:
          selectedFares = fareo;
          break;
          ... etc
          }
    This should help you, if not then post back what is the problem. I will try my best to solve your problem.

Similar Threads

  1. Replies: 3
    Last Post: 17-08-2012, 05:43 PM
  2. Replies: 6
    Last Post: 15-03-2011, 02:39 PM
  3. Display of the Program Menu In Windows 7 As the Cascade Menu
    By dinkster in forum Customize Desktop
    Replies: 4
    Last Post: 04-12-2010, 11:14 PM
  4. Choice of ram
    By Eyesee in forum Motherboard Processor & RAM
    Replies: 4
    Last Post: 22-11-2008, 02:16 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,751,893,326.64154 seconds with 16 queries