-
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.
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.
-
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?
-
ok thanku..... i think here also some one may help me...thats y i post it here...
-
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 [code] at the top of your block of code and the tag [/code] at the bottom, like so:
Code:
[code]
// your code block goes here.
// note the differences between the tag at the top vs the bottom.
[/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.