-
March 4th, 2012, 09:51 AM
#1
how to extract specific information from an array list
hi it is me again my question now is that my professor ask me to store 4 different x and y values in an array list and i did in this way
Code:
private void createTargets()
{
double ax = 125;
double ay = 175;
double aradius = 7;
String input = JOptionPane.showInputDialog("Type an integer" +
" between 2 and 5");
int number = Integer.parseInt(input);
for(int i = 0; i < number; i++)
{
Target targ = new Target(ax, ay, aradius);
targets.add(targ);
Random rand = new Random();
ax = rand.nextInt(300) + 10;
}
}
now my problem is that i need to get the individual x or y coordinates to be able to draw some circles but i do not know hot to extract the x and y coord from the array list to use it later?? help please
-
March 5th, 2012, 05:51 AM
#2
Re: how to extract specific information from an array list
Why ask the user for a number and then do nothing with it?
You aren't directly storing the x and y co-ords in the ArrayList, you are storing them in a Target object and storing the Target object in the ArrayList. So you need to use one of the ArrayList's retrieval methods such as get(..) to get the Target object and then use whatever methods are available in the Target class to get the x and y values from it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|