View Single Post
  #1 (permalink)  
Old 08-06-2007, 03:42 AM
eNine eNine is offline
Member
 
Join Date: Aug 2007
Location: new yrok
Posts: 3
eNine is on a distinguished road
Help ArrayList.add()
Can someone please tellme what is wrong with my code? I'm new Java but I haven't had any trouble with ArrayList until I tried to write the code below. For some reason, the Rectangle2D 's are not being added to my arrayList.


import java.util.ArrayList;
import java.awt.geom.Rectangle2D;


public class Hat {
ArrayList<Rectangle2D.Double> rectangles = new ArrayList<Rectangle2D.Double>(5);

public Hat(){
}

Hat(double x, double y, double w, double h){
rectangles.add((new Rectangle2D.Double(x,y,w,h) ) );
}

public void countHats(){
System.out.println("There are "+ rectangles.size() +" in list");

}

public static void main(String[] args){
Hat h = new Hat();
int limit =5;
int randomLim = 100;
for(int i=0;i<limit;i++)
{
new Hat(Math.random()*randomLim,Math.random()*randomLi m,Math.random()*randomLim,Math.random()*randomLim) ;
}
h.countHats();
}

}

Reply With Quote
Sponsored Links