Results 1 to 4 of 4
  1. #1
    theone3nu is offline Member
    Join Date
    Oct 2008
    Posts
    17
    Rep Power
    0

    Default Plz solve this....

    Hi, I want to add extra elements in the existing two dimensional array after a specified condition.Please see the following example and answer my Question.
    Java Code:
    class ArrayDemo{
    int[][] arr ={{32,535{,{64,535},{0,-9}};
    ArrayList list = new ArrayList();
    initLevel();
    public void level(){
    for(int i =0;i<list.size();i++){
    list.move();
    if(somecondition){
    // I want to add the elements to arr like this and should call initLevel method
    Line 10 // arr = {{32,535{,{64,535},{0,-9},{32,-9}};
    initLevel();
    }
    }
    }
    public void initLevel(){
    for(int i =0;i<arr.length;i++){
    list.add(new Blue(arr[0],arr[i]); // Blue is another class and move method is in it.
    }
    }
    }
    How to add elements in the above program at line 10 . Please Post your Solution. Thank You.
    Last edited by theone3nu; 01-08-2009 at 05:04 PM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    You can find solutions here in your cross-post: New To Java - How to add elements in the existing Array...

    Question though: what does this have to do with Java 2D?

  3. #3
    theone3nu is offline Member
    Join Date
    Oct 2008
    Posts
    17
    Rep Power
    0

    Default

    ok thanku..... i think here also some one may help me...thats y i post it here...

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Again, as was mentioned in the cross-post, you should read up on the Collections class including ArrayLists, as you can't simply add elements to an array which is fixed in size.

    Also as was mentioned in the cross-post when posting your code, please use code tags so that your code will retain its formatting and be readable. To do this, you will need to paste already formatted code into the forum, highlight this code, and then press the "code" button at the top of the forum Message editor prior to posting the message. Another way is to place the tag &#91;code] at the top of your block of code and the tag &#91;/code] at the bottom, like so:

    Java Code:
    &#91;code]
      // your code block goes here.
      // note the differences between the tag at the top vs the bottom.
    &#91;/code]
    Finally, this really should be in the new to java forum as it has nothing to do with Java2D -- painting in 2 dimensions with Java graphics.

Similar Threads

  1. Solve my program
    By Mika in forum New To Java
    Replies: 7
    Last Post: 01-21-2009, 06:20 AM
  2. Plz solve this....
    By theone3nu in forum New To Java
    Replies: 9
    Last Post: 12-23-2008, 09:42 AM
  3. please I need your help to solve these problems
    By edge_5050@hotmail.com in forum New To Java
    Replies: 2
    Last Post: 12-17-2008, 08:34 PM
  4. Solve my Problem
    By kyo in forum New To Java
    Replies: 1
    Last Post: 12-16-2008, 02:22 PM
  5. Help mi solve my error
    By Deon in forum New To Java
    Replies: 3
    Last Post: 01-11-2008, 05:26 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
  •