title: Java question: trying to create and draw a random number of objects
body: <p>I'm a Java novice taking a beginning programming class and I'm trying to finish my homework assignment (due tomorrow!) and I've been banging my head against the wall trying to figure out what I'm doing wrong. </p>
  
  <p>Here's the basic assignment:</p>
  
  <ol>
  <li><p>create a Building class that takes parameters for x and y location - this I have done no problem</p></li>
  <li><p>use a Panel class to draw a random number of Buildings - this is where I am having the trouble. </p></li>
  </ol>
  
  <p>I have done this kind of thing many times in Actionscript and Javascript but for some reason I cannot get it to work in Java.</p>
  
  <p>my strategy has been:
  create a random number r (done)
  set a 'for' loop to run from 0 to r
  call the constructor for a new Building
  add that Building to an Array (or an ArrayList)
  draw the Building
  end for loop</p>
  
  <p>I have tried multiple variations of this (using an Array instead of an ArrayList for ex) but here is my current code:</p>
  
  <p>here is my code:</p>
  
  <pre><code>public class CityPanel extends JPanel
  {
   private Bldg bldg
   ArrayList&lt;Bldg&gt; bs = new ArrayList&lt;Bldg&gt;();
  
  
   //------------------------------------------------------------------------
   //Constructor; Creates five building objects
   //------------------------------------------------------------------------
  
   public CityPanel()
   {
  
  
  
    setPreferredSize (new Dimension(430, 400));
    setBackground (new Color(0x46, 0x82, 0xb4));
   }
  
   //------------------------------------------------------------------------
   //Draws this panel by requesting each object draw itself.
   //------------------------------------------------------------------------
  
   public void paintComponent (Graphics page)
   {
    int b = (int) Math.floor(Math.random() * 10);
  
    for( int i = 0; i &lt; b; i++ ) {
     intArr[i] = new Integer( i );
     bldg = new Bldg(100*i, 300);
     bs.add(bldg);
     super.paintComponent(page);
     bldg.draw(page);
     System.out.print(bs.get(i).toString());
    }
  }
  </code></pre>
  
  <p>when I run the main program (a City class that draws the panels etc) I get an empty frame.</p>
  
  <p>if I just put in a constructor function without the 'for' loop I get the Building(s) to draw, so the problem lies somewhere in my 'for' loop and the way I'm trying to make and/or store the objects.</p>
  
  <p>when I google "java creating multiple objects" or "random" or what-have-you I get a lot or results but nothing relevant!</p>
  
  <p>sorry for the long post - I'm not sure how to ask the question!</p>
  
  <p>thanks in advance.
  b</p>