Results 1 to 3 of 3
  1. #1
    Johanis is offline Senior Member
    Join Date
    Oct 2010
    Posts
    139
    Rep Power
    0

    Question Displays every second item off array

    Java Code:
    private void BirdActionPerformed(java.awt.event.ActionEvent evt) {                                     
            String[] tower = new String[56];
             String plus = "";
                 
                for (int ry = 0 ; ry < 1 ; ry++)
                {
                  tower [ry] = data4[ry].getId()+"\t"+data4[ry].getWetnam()+spaces(data4[ry].getWetnam())+data4[ry].getNaam()+spaces(data4[ry].getNaam());
                  plus = plus+tower[ry]+"\n\n";
                }
               textArea1.setText(plus);
        }
    It only displays every second item in the array. for egg:
    1 Struthio camelus Ostrich

    3 Gyps coprotheres Cape Vulture

    5 Torgos tracheliotus Lappetfaced Vulture

    7 Circaetus gallicus Blackbreasted Snake Eagle

    9 Podica senegalensis African Finfoot

    11 Cursorius temminckii Temminck's Courser

    13 Pterocles gutturalis Yellowthroated Sandgrouse

    15 Coracias caudata Lilacbreasted Roller

    and it should be displaying 1-16.
    Does anyone know where I have gone wrong?

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,435
    Blog Entries
    7
    Rep Power
    20

    Default Re: Displays every second item off array

    Quote Originally Posted by Johanis View Post
    Java Code:
                for (int ry = 0 ; ry < 1 ; ry++)
    I don't know if it matters much but this loop only runs once (for ry having the value zero).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    Johanis is offline Senior Member
    Join Date
    Oct 2010
    Posts
    139
    Rep Power
    0

    Default Re: Displays every second item off array

    Java Code:
    int lengte = data4.length;
             String[] tower = new String[lengte];
             String plus = "";
             int ry = 0;
             for(ry = 0; ry<lengte; ry++)
             {
    
                  tower [ry]  = data4[ry].getId()+"\t"+data4[ry].getWetnam()+spaces(data4[ry].getWetnam())+data4[ry].getNaam()+spaces(data4[ry].getNaam());
                  plus = plus+tower[ry]+"\n\n";
             }
            textArea1.setText(plus);
    Changed it to this and it works now :)

Similar Threads

  1. Help me displays an image
    By dinhtrieu08t4 in forum AWT / Swing
    Replies: 4
    Last Post: 10-07-2011, 04:58 PM
  2. Removing an Item from an array
    By chris1 in forum New To Java
    Replies: 3
    Last Post: 04-25-2011, 06:59 AM
  3. access array list item from draw
    By trishtren in forum New To Java
    Replies: 8
    Last Post: 04-19-2011, 12:34 PM
  4. Getting an item from an array
    By ile4 in forum New To Java
    Replies: 9
    Last Post: 01-13-2011, 03:42 PM
  5. Get item from string array and pack with blank space
    By firewalll in forum New To Java
    Replies: 2
    Last Post: 09-02-2009, 07:38 AM

Posting Permissions

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