Results 1 to 4 of 4
- 06-01-2010, 05:05 PM #1
Member
- Join Date
- Mar 2010
- Posts
- 9
- Rep Power
- 0
Passing an Array index into a function?
Hey, I'm trying to make a simple function that returns a value according to what was chosen by the user in a text field.
So it's something like this:
Java Code:float getModifier(JList list[]) { int selected = list[?].getSelectecValue( ); //Obviously gives a compiler error, don't know how to pass the index into the function correctly switch(selected) case 1: return blahblahblah //etc...etc.. }
- 06-01-2010, 05:10 PM #2
so somewhere you call
.... object.getModifier(list[])
than you receive it in the getModifier method, where you would put a value where you have the ? and you shouldn't need to call getSelectecValue() (getSelectedValue), unless the array is holding objects.
hm.:rolleyes: ~ Sno ~ :rolleyes:
'-~ B.S. Computer Science ~-'
- 06-01-2010, 05:43 PM #3
Couple of suggestions:
Do the array de-referencing before or in the call to the function and pass a JList reference.
...object.getModifier(list[ix])
Pass the needed index as an int parameter to the function.
...object.getModifier(list[], ix)
- 06-01-2010, 08:51 PM #4
Member
- Join Date
- Mar 2010
- Posts
- 9
- Rep Power
- 0
Similar Threads
-
Example for passing string to a function.?
By mlibot in forum New To JavaReplies: 1Last Post: 03-19-2010, 07:36 AM -
Array Index out of bounds
By leapinlizard in forum New To JavaReplies: 5Last Post: 04-29-2009, 06:11 AM -
how use string array while passing to a function
By sks9s9 in forum New To JavaReplies: 2Last Post: 02-03-2009, 01:44 PM -
Passing a Vector object to a function
By evapisces in forum New To JavaReplies: 4Last Post: 09-27-2008, 04:18 AM -
problems with array index
By mary in forum New To JavaReplies: 2Last Post: 08-01-2007, 05:30 PM
Bookmarks