Results 1 to 7 of 7
  1. #1
    amirKhan is offline Member
    Join Date
    Mar 2011
    Posts
    3
    Rep Power
    0

    Exclamation Need some help in TextListener...

    Hey i hav writen the code below.
    Which is suppose to set the text in (j,i)th place same as in (i,j)th....
    The code below is...
    Java Code:
    for(i=0;i<noOfVar;i++)
        {
          for(j=0;j<noOfVar;j++)
          {
            tfD[i][j].addTextListener(new TextListener()
                                          {
                public void textValueChanged(TextEvent te)
                {
                        tfD[j][i].setText(tfD[i][j].getText());
                }
              });
          }
        }
    but it is showing runtime error ---array index out of bound i.e i=noOfVar & j=noOfVar...

    So i tried the different code which is as follows.....
    Java Code:
    public void textValueChanged(TextEvent te)
                {
                  for(int i=0;i<noOfVar;i++)
                  {
                    for(int j=0;j<noOfVar;j++)
                      if(te.getSource()==tfD[i][j])
                      tfD[j][i].setText(tfD[i][j].getText());
                }
              }
    But this code takes lots of time to execute...& also the system slows down.....
    Can Any one plz help me in this matter....
    Last edited by Eranga; 03-18-2011 at 04:17 AM. Reason: code tags added

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  3. #3
    asmitarnd is offline Member
    Join Date
    Mar 2011
    Posts
    22
    Rep Power
    0

    Default

    plz do try this code first with a fixed size array

  4. #4
    amirKhan is offline Member
    Join Date
    Mar 2011
    Posts
    3
    Rep Power
    0

    Default

    Quote Originally Posted by Eranga View Post
    Are you sure that you are not accessing none-existing indexes in the array?
    @eranga: I hv already written that it is tryin to acess.....out of bound indexes in first case.......
    The second case runs...but it makes slow.....

  5. #5
    amirKhan is offline Member
    Join Date
    Mar 2011
    Posts
    3
    Rep Power
    0

    Default

    Quote Originally Posted by asmitarnd View Post
    plz do try this code first with a fixed size array
    what will be the difference....
    I didnt got it....

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Quote Originally Posted by amirKhan View Post
    @eranga: I hv already written that it is tryin to acess.....out of bound indexes in first case.......
    The second case runs...but it makes slow.....
    What's the size of array. Could you post the complete source code to see?

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    And also, please use code tags next time when you are posting a code segment. Unformatted codes are really hard to read. If you don't know how to do that, please check my forum signature.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •