change my first line to
01.int[] maxObjs = { 2, 6, 4, 3, 10};
/** * Act - do whatever the CircutBuildAndDisplay wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { if(getWorld() instanceof CircutWorld) { cw = (CircutWorld) getWorld(); if(!dothisonce) { int[] maxObjs = { 2, 6, 4, 3, 10}; int[][] objsGrid = {{5, 5, 5, 5, 5}, {5, 5, 5, 5, 5}, {5, 5, 5, 5, 5}, {5, 5, 5, 5, 5}, {5, 5, 5, 5, 5} }; for (int myObj = 0; myObj < 5; myObj++) { for (int myCt = 0; myCt < maxObjs[myObj]; myCt++) { int x = Greenfoot.getRandomNumber(5); int y = Greenfoot.getRandomNumber(5); while (objsGrid[x][y] != 5) { x = Greenfoot.getRandomNumber(5); y = Greenfoot.getRandomNumber(5); } objsGrid[x][y] = myCt; } } for (int y = 0; y < 5; y++) { for (int x = 0; x < 5; x++) { switch(objsGrid[x][y]) { case 0: cw.addObject(new Light(), (x+2)*64,(y+2)*64); break; case 1: cw.addObject(new Wire(), (x+2)*64,(y+2)*64); break; case 2: cw.addObject(new Diode(), (x+2)*64,(y+2)*64); break; case 3: cw.addObject(new Resistor(), (x+2)*64,(y+2)*64); break; case 4: cw.addObject(new EmptyCircuitArea(), (x+2)*64,(y+2)*64); break; } } } dothisonce = true; } } GreenfootImage img = new GreenfootImage(Integer.toString(cw.numberOfObjects()),21,Color.BLACK,Color.white); setImage(img); setLocation(250,50); }