CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2012
    Posts
    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

  2. #2
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    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 code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured