Java+with+Greenfoot+Lesson+1

=Java with Greenfoot Lesson 1: Hello Wombats! =

If you are familiar with Scratch and would like to learn more on programming. Java with Greenfoot is a great choice. In this lesson, we will test the water by looking at a sample Greenfoot project called “wombats”.  To open the sample Greenfoot project, do “Scenario”->”Open”  Browse to the Greenfoot directory and open “scenarios”, and select “wombats”. You will see a Greenfoot project that looks as followed.  If you’ve followed the Scratch series (if you have not, I would strongly recommend), then it should be quite obvious to you that the Greenfoot has similar interface to Scratch.  To “populate” the world, right click at the “wombatWorld” on the top of the Current Program panel. Then select “void populate” from the drop-down list.  You would see two bears and six leaves shown up in the world. Click the “Run” button to start the program. Once the program starts, these two bears will move about finding leaves to eat. Obviously, they are vegetarian grizzly bears. The game/program will end when all leaves are gone.  These two poor bears are too hungry; let’s give them more leaves. <span style="font-family: "Helvetica Neue",Helvetica,Helvetica,Arial,sans-serif; font-size: 14px;"> <span style="font-family: "Helvetica Neue",Helvetica,Helvetica,Arial,sans-serif; font-size: 14px;">An window would pop up, asking how many random leaves to add. Enter “10″ and click “OK”. <span style="font-family: "Helvetica Neue",Helvetica,Helvetica,Arial,sans-serif; font-size: 14px;"> <span style="font-family: "Helvetica Neue",Helvetica,Helvetica,Arial,sans-serif; font-size: 14px;">Ten leaves would be added randomly. <span style="font-family: "Helvetica Neue",Helvetica,Helvetica,Arial,sans-serif; font-size: 14px;"> <span style="font-family: "Helvetica Neue",Helvetica,Helvetica,Arial,sans-serif; font-size: 14px;">We are ready to run the program now. To run the program step by step, click “Act”. To run the program continuously, click “Run”. <span style="font-family: "Helvetica Neue",Helvetica,Helvetica,Arial,sans-serif; font-size: 14px;"> <span style="font-family: "Helvetica Neue",Helvetica,Helvetica,Arial,sans-serif; font-size: 14px;">You can view the Scenario Information by clicking the highlighted button. <span style="font-family: "Helvetica Neue",Helvetica,Helvetica,Arial,sans-serif; font-size: 14px;"> <span style="font-family: "Helvetica Neue",Helvetica,Helvetica,Arial,sans-serif; font-size: 14px;">Next, we can change the Actor’s image. Right click on the Wombat button and select “Set image” from the drop-down menu. <span style="font-family: "Helvetica Neue",Helvetica,Helvetica,Arial,sans-serif; font-size: 14px;"> <span style="font-family: "Helvetica Neue",Helvetica,Helvetica,Arial,sans-serif; font-size: 14px;">Select an image you like. I selected the Linux Penguin named “tux.png”. Click OK to save. <span style="font-family: "Helvetica Neue",Helvetica,Helvetica,Arial,sans-serif; font-size: 14px;"> <span style="font-family: "Helvetica Neue",Helvetica,Helvetica,Arial,sans-serif; font-size: 14px;">Also change the Leave’s image. I changed it to the image of a strawberry. <span style="font-family: "Helvetica Neue",Helvetica,Helvetica,Arial,sans-serif; font-size: 14px;"> <span style="font-family: "Helvetica Neue",Helvetica,Helvetica,Arial,sans-serif; font-size: 14px;"> <span style="font-family: "Helvetica Neue",Helvetica,Helvetica,Arial,sans-serif; font-size: 14px;">When done, click “Compile all” button to recompile the program. To compile a program just means to build a program executable. <span style="font-family: "Helvetica Neue",Helvetica,Helvetica,Arial,sans-serif; font-size: 14px;"> <span style="font-family: "Helvetica Neue",Helvetica,Helvetica,Arial,sans-serif; font-size: 14px;">To run the modified program, we will repopulate the world and restart the program. To populate the world, right click wombatWorld title above the program view and select “void populate” from the drop down list. Then click the “Run” button to run the program. Also, you can add more strawberries by selecting the “void randomLeaves(int howMany)” from the drop-down list. <span style="font-family: "Helvetica Neue",Helvetica,Helvetica,Arial,sans-serif; font-size: 14px;">
 * < [[image:http://shallwelearn.com/blog/wp-content/uploads/2009/06/061209-0431-greenfootle22.png caption="alt"]] ||< [[image:http://shallwelearn.com/blog/wp-content/uploads/2009/06/061209-0431-greenfootle32.png caption="alt"]] ||