The scenario was working just fine but when I finished writing some code and clicked compile it got stuck in just a blank screen that tells me the world is being constructed.
I tried compiling again and then restarting but it's still the same


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | /** * Autumn. A world with some leaves. * * @author Michael Kölling * @version 0.1 */ public class MyWorld extends World { /** * Create the world and objects in it. */ public MyWorld() { super ( 600 , 400 , 1 ); setUp(); } /** * Create the initial objects in the world. */ private void setUp() { addLeaves(); } private void addLeaves() { addObject( new Block(), 300 , 200 ); int i= 0 ; int x=Greenfoot.getRandomNumber(getWidth()); int y=Greenfoot.getRandomNumber(getHeight()); while (i< 18 ); { addObject( new Leaf(),x,y); } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | import greenfoot.*; /** * A block that bounces back and forth across the screen. * * @author Michael Kölling * @version 0.1 */ public class Block extends Actor { private int delta = 2 ; /** * Move across the screen, bounce off edges. Turn leaves, if we touch any. */ public void act() { move(); checkEdge(); checkMouseClick(); checkLeaf(); World world = getWorld(); Leaf leaf = (Leaf) getOneIntersectingObject(Leaf. class ); leaf.turn( 9 ); if (leaf!= null ) { } } /** * Move sideways, either left or right. */ private void move() { setLocation(getX()+delta, getY()); } /** * Check whether we are at the edge of the screen. If we are, turn around. */ private void checkEdge() { if (isAtEdge()) { delta = -delta; // reverse direction } } /** * Check whether the mouse button was clicked. If it was, change all leaves. */ private void checkMouseClick() { if (Greenfoot.mouseClicked( null )) { // do this when the mouse is clicked. currently: nothing. } } private void checkLeaf() { Leaf leaf = (Leaf) getOneIntersectingObject(Leaf. class ); if (leaf!= null ) { } else { turn ( 9 ); } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | import greenfoot.*; /** * A floating leaf that blows across the screen. * * @author Michael Kölling * @version 1.0 */ public class Leaf extends Actor { private int speed; GreenfootImage img1 = new GreenfootImage( "leaf-green.png" ); GreenfootImage img2 = new GreenfootImage( "leaf-brown.png" ); /** * Create the leaf. */ public Leaf() { setImage(img1); speed = Greenfoot.getRandomNumber( 3 ) + 1 ; // random speed: 1 to 3 setRotation(Greenfoot.getRandomNumber( 360 )); } /** * Move around. */ public void act() { if (isAtEdge()) { turn( 180 ); } move(speed); if (Greenfoot.getRandomNumber( 100 ) < 50 ) { turn(Greenfoot.getRandomNumber( 5 ) - 2 ); // -2 to 2 } } /** * Change the image to another leaf image. This toggles back and * forth between two images. */ public void changeImage() { if (getImage() == img1) { setImage(img2); } else { setImage(img1); } } } |