kakihijau.googlepages.com introduction to greenfoot part-1
TRANSCRIPT
![Page 1: Kakihijau.googlepages.com Introduction To Greenfoot Part-1](https://reader035.vdocument.in/reader035/viewer/2022062409/5697bfcf1a28abf838ca9b84/html5/thumbnails/1.jpg)
kakihijau.googlepages.com
Introduction To
GreenfootPart-1
![Page 2: Kakihijau.googlepages.com Introduction To Greenfoot Part-1](https://reader035.vdocument.in/reader035/viewer/2022062409/5697bfcf1a28abf838ca9b84/html5/thumbnails/2.jpg)
2Introduction to Greenfoot
Eueung Mulyana | kakihijau.googlepages.com
Disclaimer
This document is intended to give a beginner an introductory material for the Greenfoot system. Greenfoot is a software framework made by Poul Henriksen and Michael Koelling at University of Kent / Deakin University. More information can be found at http://www.greenfoot.org
This document is available „AS IS“ free of charge for personal use and non-commercial redistribution. It may not be sold for profit or included in other packages which are sold for profit without written authorisation. This document is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; your use of the document is at your sole risk. Reusing and modifying (part of) this document is allowed, as long as you state explicitly that your work is based on the original document produced by the copyright holder: Eueung Mulyana. The author can be contacted via eueung-[at]-yahoo.com (http://kakihijau.googlepages.com).
![Page 3: Kakihijau.googlepages.com Introduction To Greenfoot Part-1](https://reader035.vdocument.in/reader035/viewer/2022062409/5697bfcf1a28abf838ca9b84/html5/thumbnails/3.jpg)
3Introduction to Greenfoot
Eueung Mulyana | kakihijau.googlepages.com
Introduction
„Greenfoot is a software tool designed to let beginners get experience with object-oriented programming. It supports development of graphical applications in the Java™ Programming Language“
Designed and implemented at the University of Kent and Deakin University
Copyright held by Poul Henriksen and Michael Koelling
More information at http://www.greenfoot.org
Part of the content of these slides is based on the Greenfoot Tutorial made by Michael Koelling, publicly accesible at the website
![Page 4: Kakihijau.googlepages.com Introduction To Greenfoot Part-1](https://reader035.vdocument.in/reader035/viewer/2022062409/5697bfcf1a28abf838ca9b84/html5/thumbnails/4.jpg)
4Introduction to Greenfoot
Eueung Mulyana | kakihijau.googlepages.com
Outline
Visual Interface Creating Objects Interaction with Objects Removing Objects Objects‘ Action Simulation „Run“ Scenario plane Scenario turtleGraphics Scenario ants Scenario lunarlander
![Page 5: Kakihijau.googlepages.com Introduction To Greenfoot Part-1](https://reader035.vdocument.in/reader035/viewer/2022062409/5697bfcf1a28abf838ca9b84/html5/thumbnails/5.jpg)
5Introduction to Greenfoot
Eueung Mulyana | kakihijau.googlepages.com
Visual Interface (scenario wombats)
![Page 6: Kakihijau.googlepages.com Introduction To Greenfoot Part-1](https://reader035.vdocument.in/reader035/viewer/2022062409/5697bfcf1a28abf838ca9b84/html5/thumbnails/6.jpg)
6Introduction to Greenfoot
Eueung Mulyana | kakihijau.googlepages.com
Visual Interface
Consists of 3 main parts
The world– The large canvas that covers the majority of the window– Has a title e.g. WombatWorld– The enviroment („the world“) where objects exist
Class display– Contains all Java classes involved in the scenario– 3 groups: World, Actor and other classes
Execution controls– Controls the action of each object: the „Act“ button– Controls simulation: „Run“, „Pause“, slider– Resets the scenario
![Page 7: Kakihijau.googlepages.com Introduction To Greenfoot Part-1](https://reader035.vdocument.in/reader035/viewer/2022062409/5697bfcf1a28abf838ca9b84/html5/thumbnails/7.jpg)
7Introduction to Greenfoot
Eueung Mulyana | kakihijau.googlepages.com
Creating Objects (1)
(Left-)Click on the Wombat or Leaf class to make it active
To create and place an object into the world :– Activate a class then shift+click somewhere in the World– Right-click a class (e.g. Wombat class) to open the class
context menu, select the „New Wombat()“ item then click somewhere in the World
![Page 8: Kakihijau.googlepages.com Introduction To Greenfoot Part-1](https://reader035.vdocument.in/reader035/viewer/2022062409/5697bfcf1a28abf838ca9b84/html5/thumbnails/8.jpg)
8Introduction to Greenfoot
Eueung Mulyana | kakihijau.googlepages.com
Creating Objects (2)
Classcontext menu
Creating 3 objects and placing them into the World
![Page 9: Kakihijau.googlepages.com Introduction To Greenfoot Part-1](https://reader035.vdocument.in/reader035/viewer/2022062409/5697bfcf1a28abf838ca9b84/html5/thumbnails/9.jpg)
9Introduction to Greenfoot
Eueung Mulyana | kakihijau.googlepages.com
Interaction with Objects (1) Methods of an
object can directly be invoked
„A method is a single action that an object can perform“
Right-click on one object to show its (object) context menu, where you can select a method to ask the object to do „something“
turnleft() move()
![Page 10: Kakihijau.googlepages.com Introduction To Greenfoot Part-1](https://reader035.vdocument.in/reader035/viewer/2022062409/5697bfcf1a28abf838ca9b84/html5/thumbnails/10.jpg)
10Introduction to Greenfoot
Eueung Mulyana | kakihijau.googlepages.com
Interaction with Objects (2)
The world where the wombats live (WombatWorld) is actually an object, too
But there may exist only one World object at a time
It functions as a container for Actor objects (e.g. Wombat, Leaf etc.)
Single method invocation is still possible for the World object; just right-click the title „WombatWorld“ and select a method from the menu
![Page 11: Kakihijau.googlepages.com Introduction To Greenfoot Part-1](https://reader035.vdocument.in/reader035/viewer/2022062409/5697bfcf1a28abf838ca9b84/html5/thumbnails/11.jpg)
11Introduction to Greenfoot
Eueung Mulyana | kakihijau.googlepages.com
Interaction with Objects (3)
populate() randomLeaves()
![Page 12: Kakihijau.googlepages.com Introduction To Greenfoot Part-1](https://reader035.vdocument.in/reader035/viewer/2022062409/5697bfcf1a28abf838ca9b84/html5/thumbnails/12.jpg)
12Introduction to Greenfoot
Eueung Mulyana | kakihijau.googlepages.com
Interaction with Objects (4)
A method may have one or more parameters You will be requested to give value(s) of the
parameter(s) when you invoke such a method Try the method setDirection() from a Wombat
object or the method randomLeaves() from the WombatWorld
A method may also return one value (or reference to an object) if it is invoked
Try foundLeaf() or getLeavesEaten() from a Wombat object
![Page 13: Kakihijau.googlepages.com Introduction To Greenfoot Part-1](https://reader035.vdocument.in/reader035/viewer/2022062409/5697bfcf1a28abf838ca9b84/html5/thumbnails/13.jpg)
13Introduction to Greenfoot
Eueung Mulyana | kakihijau.googlepages.com
Removing Objects (1)
An object can be removed by selecting item „Remove“ from the object context menu
Clicking the „Reset“ button or creating a new World object from the class context menu may remove all objects; however it actually depends on the constructor implementation of the World class (*)
![Page 14: Kakihijau.googlepages.com Introduction To Greenfoot Part-1](https://reader035.vdocument.in/reader035/viewer/2022062409/5697bfcf1a28abf838ca9b84/html5/thumbnails/14.jpg)
14Introduction to Greenfoot
Eueung Mulyana | kakihijau.googlepages.com
Removing Objects (2)
![Page 15: Kakihijau.googlepages.com Introduction To Greenfoot Part-1](https://reader035.vdocument.in/reader035/viewer/2022062409/5697bfcf1a28abf838ca9b84/html5/thumbnails/15.jpg)
15Introduction to Greenfoot
Eueung Mulyana | kakihijau.googlepages.com
Objects‘ Action
Each Actor object has a special method called act() Pressing the button „Act“ on the control panel
means asking Greenfoot to execute act() method for all objects in the world
An object acts by doing „whatever it wants to do“ e.g.:– Wombats move forward, if they find a leaf in their path,
they will eat it– Leaves do nothing
The action depends actually on how act() method is defined; that is, we can program object behaviors!!
![Page 16: Kakihijau.googlepages.com Introduction To Greenfoot Part-1](https://reader035.vdocument.in/reader035/viewer/2022062409/5697bfcf1a28abf838ca9b84/html5/thumbnails/16.jpg)
16Introduction to Greenfoot
Eueung Mulyana | kakihijau.googlepages.com
Simulation „Run“
A scenario can be run by clicking the „Run“ button
This equivalent to clicking the „Act“ button over and over again very quickly
The slider next to the „Act“ and „Run“ buttons sets the „running/simulation“ speed
Make an experiment with scenario wombats– Click „Reset“ if you have already some objects– Select Populate() from the WombatWorld menu– Click „Run“
![Page 17: Kakihijau.googlepages.com Introduction To Greenfoot Part-1](https://reader035.vdocument.in/reader035/viewer/2022062409/5697bfcf1a28abf838ca9b84/html5/thumbnails/17.jpg)
17Introduction to Greenfoot
Eueung Mulyana | kakihijau.googlepages.com
Simulation „Run“
Running wombats scenario
![Page 18: Kakihijau.googlepages.com Introduction To Greenfoot Part-1](https://reader035.vdocument.in/reader035/viewer/2022062409/5697bfcf1a28abf838ca9b84/html5/thumbnails/18.jpg)
18Introduction to Greenfoot
Eueung Mulyana | kakihijau.googlepages.com
Scenario plane (1)
Choose „Open ...“ from the „Scenario“ menu and select the plane scenario from the Greenfoot sample scenarios
Press the „Compile all“ button, if necessary
Instantiate a Plane object and place somewhere in the world
Run the scenario by pressing „Run“
Try to drag the ControlKnob object and observe the result
![Page 19: Kakihijau.googlepages.com Introduction To Greenfoot Part-1](https://reader035.vdocument.in/reader035/viewer/2022062409/5697bfcf1a28abf838ca9b84/html5/thumbnails/19.jpg)
19Introduction to Greenfoot
Eueung Mulyana | kakihijau.googlepages.com
Scenario plane (2)
![Page 20: Kakihijau.googlepages.com Introduction To Greenfoot Part-1](https://reader035.vdocument.in/reader035/viewer/2022062409/5697bfcf1a28abf838ca9b84/html5/thumbnails/20.jpg)
20Introduction to Greenfoot
Eueung Mulyana | kakihijau.googlepages.com
Scenario plane (3)
![Page 21: Kakihijau.googlepages.com Introduction To Greenfoot Part-1](https://reader035.vdocument.in/reader035/viewer/2022062409/5697bfcf1a28abf838ca9b84/html5/thumbnails/21.jpg)
21Introduction to Greenfoot
Eueung Mulyana | kakihijau.googlepages.com
Scenario turtleGraphics (1)
Choose „Open ...“ from the „Scenario“ menu and select the turtleGraphics scenario from the Greenfoot sample scenarios
Press the „Compile all“ button, if necessary Instantiate several turtle objects (CircleTurtle,
SquareTurtle, FlowerTurtle and SpiralTurtle) and place somewhere in the world
Run the scenario by pressing „Run“ Observe the result
![Page 22: Kakihijau.googlepages.com Introduction To Greenfoot Part-1](https://reader035.vdocument.in/reader035/viewer/2022062409/5697bfcf1a28abf838ca9b84/html5/thumbnails/22.jpg)
22Introduction to Greenfoot
Eueung Mulyana | kakihijau.googlepages.com
Scenario turtleGraphics (2)
![Page 23: Kakihijau.googlepages.com Introduction To Greenfoot Part-1](https://reader035.vdocument.in/reader035/viewer/2022062409/5697bfcf1a28abf838ca9b84/html5/thumbnails/23.jpg)
23Introduction to Greenfoot
Eueung Mulyana | kakihijau.googlepages.com
Scenario ants (1)
Choose „Open ...“ from the „Scenario“ menu and select the ants scenario from the Greenfoot sample scenarios
Press the „Compile all“ button, if necessary By default (standard Greenfoot 1.3 distribution)
you will have several objects, which are actually formed together as the World object is created; these objects are instances of the class AntHill and Food; other objects will be created „on-the-fly“
Run the scenario by pressing „Run“ Observe the result
![Page 24: Kakihijau.googlepages.com Introduction To Greenfoot Part-1](https://reader035.vdocument.in/reader035/viewer/2022062409/5697bfcf1a28abf838ca9b84/html5/thumbnails/24.jpg)
24Introduction to Greenfoot
Eueung Mulyana | kakihijau.googlepages.com
Scenario ants (2)
![Page 25: Kakihijau.googlepages.com Introduction To Greenfoot Part-1](https://reader035.vdocument.in/reader035/viewer/2022062409/5697bfcf1a28abf838ca9b84/html5/thumbnails/25.jpg)
25Introduction to Greenfoot
Eueung Mulyana | kakihijau.googlepages.com
Scenario lunarlander (1)
Choose „Open ...“ from the „Scenario“ menu and select the lunarlander scenario from the Greenfoot sample scenarios
Press the „Compile all“ button, if necessary By default you will have a Lander object, which
is actually formed together as the World object is created
Now you are ready to play the game; run the scenario by pressing „Run“
The rocket thrust can be controlled by pressing the „down“ key on the keyboard
![Page 26: Kakihijau.googlepages.com Introduction To Greenfoot Part-1](https://reader035.vdocument.in/reader035/viewer/2022062409/5697bfcf1a28abf838ca9b84/html5/thumbnails/26.jpg)
26Introduction to Greenfoot
Eueung Mulyana | kakihijau.googlepages.com
Scenario lunarlander (2)