Results 1 to 7 of 7
  1. #1
    selomojemalo is offline Member
    Join Date
    May 2013
    Posts
    10
    Rep Power
    0

    Default Hello, new here, new in java and need help :)

    Hey guys
    doing something with combo boxes and need help


    private String[] fileName = {"ajolie.jpg", "elongoria.jpg", "ewatson.jpg", "jalba.jpg", "mbelluci.jpg"};

    private Icon[] pictures = {new ImageIcon(getClass().getResource(fileName[ i ]))};


    question is how to make for loop to loop trought filename to put index in to pictures

    sry for my english, hope u understends me

  2. #2
    monkeyjr97 is offline Senior Member
    Join Date
    Nov 2012
    Posts
    258
    Rep Power
    2

    Default Re: Hello, new here, new in java and need help :)

    Java Code:
    private Icon[] pictures = new Icon[100] // change this 100 to suit how many icons you want to store
    
    for(int i = 0; i < fileName.length; i++) {
    
    pictures[i] = new ImageIcon(getClass().getResource(fileName[ i ]));
    i think that's what you are looking for.

  3. #3
    selomojemalo is offline Member
    Join Date
    May 2013
    Posts
    10
    Rep Power
    0

    Default Re: Hello, new here, new in java and need help :)

    i think it is, but still it wont work
    this is a code and i need to put those underline parenthesis coz of error (thay dont have sense to me?)
    Hello, new here, new in java and need help :)-untitled.png
    and still whan run a program get this error
    Hello, new here, new in java and need help :)-error.png

  4. #4
    monkeyjr97 is offline Senior Member
    Join Date
    Nov 2012
    Posts
    258
    Rep Power
    2

    Default Re: Hello, new here, new in java and need help :)

    Your for loop isnt inside a method body. Put the for loop inside a method.
    Last edited by monkeyjr97; 05-13-2013 at 11:44 PM.

  5. #5
    selomojemalo is offline Member
    Join Date
    May 2013
    Posts
    10
    Rep Power
    0

    Default Re: Hello, new here, new in java and need help :)

    i put it in constructor but stil geting that error
    Hello, new here, new in java and need help :)-.png

  6. #6
    selomojemalo is offline Member
    Join Date
    May 2013
    Posts
    10
    Rep Power
    0

    Default Re: Hello, new here, new in java and need help :)

    working now, needed to create new method tnx mate

  7. #7
    selomojemalo is offline Member
    Join Date
    May 2013
    Posts
    10
    Rep Power
    0

    Default Re: Hello, new here, new in java and need help :)

    have a new problem, now it wont show icons, i supose that i need to run method addPics() in counstractor? or i need to do something else?
    Hello, new here, new in java and need help :)-b.png
    i was trying to cool it from ather class bat it wont work

Posting Permissions

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