Introduzione. GreenFoot è uno strumento software progettato per permettere ai principianti di fare esperienza con laprogrammazione orientata. The Greenfoot Programmers’ Manual is licensed under a. Creative Commons Attribution-Non-Commercial UK: England & Wales License. Contents 1. 2. 3. 4. Opening the Code editor for a class displays all of the programming instructions for the class. Programming instructions are organized into methods in the class.
|Published (Last):||8 December 2014|
|PDF File Size:||17.44 Mb|
|ePub File Size:||18.99 Mb|
|Price:||Free* [*Free Regsitration Required]|
Copyright, licensing and redistribution. Installing on Mac OS X. Installing on other systems. Open a Greenfoot project. Find out about the scenario. Place objects into the world. Create a new world.
Invoke a world method. Change the behaviour of an object. Find out about Greenfoot classes. Create a new class. Make you own scenarios. Greenfoot is a software tool designed to let beginners get experience with object-oriented programming. More information about Greenfoot is available at www.
This tutorial is intended for people who want to familiarise themselves with Greenfoot. It aims at being brief, rather than complete, and focuses on functionality of the Greenfoot environment. It does not attempt to teach Java. It assumes that the reader knows some Java already, or is getting some support while working through the second half of this tutorial.
All of the activities described here assume working with an existing scenario, and discuss how to use and make modification to that scenario. The Greenfoot system and this tutorial are available ‘as is’, free of charge to anyone for use and non-commercial re-distribution. Disassembly of the system is prohibited. No part of the Greenfoot system or its documentation may be sold for profit or included in a package that is sold for profit without written authorisation of the authors.
The Greenfoot software can be downloaded from www.
Three different versions are available: You must have Java 5 a. Generally, updating to the latest stable non-beta Java release is recommended. You need a version that is named JDK.
For Microsoft Windows systems, download the Windows version of the installer. Double-click the installer file, and greeenfoot the instructions. The installation follows a standard installation process. The download file is a zip file. Your browser may unpack that file automatically for you. If not, double-click the zip file to unpack it.
The resulting folder greenvoot the Greenfoot application and sample scenarios. Both can be placed anywhere you like.
Greenfoot | Discuss | Programmer Manual
The Installer for all other systems is an executable jar file. You can run the installer greengoot opening a command line, and typing. On some systems, double-clicking the jar file may also work. If not, install and set up java first.
They are distributed together with this tutorial. Each scenario will appear as one folder in your file system.
You may have opened this tutorial from within the Greenfoot application. If not, then you need to start Greenfoot now. Nanual should see something like Figure 1 on screen except that you will not see any leaves or wombats in the world yet. Since we have a scenario here that has to do with wombats see Footnote 1we see a wombat world.
Towards the right side of the window is the class display.
Here you can see all Java classes that are involved in the project. The other classes belong to the wombat scenario, and will be different if you manuwl different scenarios. Most scenarios will, when you click this button, display some information regarding the scenario. This information typically tells you the purpose of the scenario, how to run it, what you can do with it, and maybe some suggestions how you could modify it yourself.
Control-click the Wombat class in the class display. You will see a pop-up menu.
Then click anywhere in the world. You have just created a wombat in Java terms: Wombats eat leaves, so lets put some leaves into the world as well. Right-click the Leaf class and place the leaf. There is a shortcut to placing several objects a bit quicker: Make sure the Leaf class is selected, then hold down the Shift key and click into the world several times.
You will place one object of the selected class at every click. Each object now acts — that is: In our example, leaves are defined to do nothing, while wombats move forward. Wombats also like to eat leaves. If they happen to come across a leaf in their path, they will eat it. This is programmed to clicking the Act button rpogrammer and over again, very quickly. Clicking it stops the whole show.
The slider next to the Act and Run buttons sets the speed. Instead of just running the whole scenario, you can also invoke single methods. A method is a single action that an object can perform. Make sure you have a wombat in the world, and the scenario is not running.
Then right-click on the wombat, and you see that objects in the world also have a pop-up menu Figure 2. You can select any of the methods shown here to ask the wombat to do something.
Try, for example, turnLeft. Selecting this from the menu tells the wombat to turn to its left. Some methods give you an answer. This method is called every time you click the Act button. If you have many objects in the world that you do not want anymore, and you want to start all over, there is one easy option: This is usually done by clicking the ‘Reset’ button at the bottom of the screen. You will get a new, empty world. The old world is discarded and with it all the objects that were in it — you can only have one world at a ptogrammer.
We have seen that objects in the world have methods which you can invoke via a pop-up menu. The world itself is also an object with methods vreenfoot you can manuual. We have seen in the previous section how you can create new worlds.
Now we want to invoke a method of the world object. Note that this is the title above the world’s display, not the class name in the right hand panel. It is a method that creates several leaves and wombats and places them into the world.
You can then grenfoot the scenario. This method places some leaves in the world at random locations. Note that this method has some words between the parenthesis after its name: It means that you must specify some additional bit of information when you invoke this method. A dialogue will pop up that lets you mznual a value for this parameter.
Enter a number — say: You may notice, if you count, that it sometimes appears as programmr fewer than the specified number of leaves were created. This is because some leaves may be at the same location, and are lying on top of each other. The remainder of this tutorial assumes that readers are familiar with some basics of Java programming.
It is not intended as a first activity for mmanual students. You can program your own objects — wombats, or anything else you like — by writing some Java code for the class of the object. Double-click the Wombat class in the class display. A text editor opens and you will see the Java source code for the Wombat class.
Add the following method to the Wombat class:.