Copyright © 1997-2013 Curt Hill Turtles The beginning of media computation.

Slides:



Advertisements
Similar presentations
Introduction to Eclipse. Start Eclipse Click and then click Eclipse from the menu: Or open a shell and type eclipse after the prompt.
Advertisements

KompoZer. This is what KompoZer will look like with a blank document open. As you can see, there are a lot of icons for beginning users. But don't be.
Introducing Java CSC1401. Course Goals Teaching programming concepts In a “real” language.
8-May-15 Additional control structures. 2 The if-else statement The if-else statement chooses which of two statements to execute The if-else statement.
Computer Science 1000 LOGO I. LOGO a computer programming language, typically used for education an old language (1967) the basics are simple: move a.
MT311 Tutorial Li Tak Sing( 李德成 ). Uploading your work You need to upload your work for tutorials and assignments at the following site:
Road Map Introduction to object oriented programming. Classes
Lecture 2. Review To play with Turtle, we need to download and install followings: 1.JDK 6 2.Dr. Java 3.Sample program (e.g. BookClass)
Classes and Objects in Java
1 The First Step Learning objectives write Java programs that display text on the screen. distinguish between the eight built-in scalar types of Java;
04-Intro-Object-Oriented-In-Java1 Barb Ericson Georgia Institute of Technology Sept 2009 Introduction to Object-Oriented Programming in Java.
1 eclipse Tips. 2 What is eclipse? Eclipse is a popular IDE (Integrated Development Environment) that we will use to create, compile, execute, and test.
by Chris Brown under Prof. Susan Rodger Duke University June 2012
Java Programming, 3e Concepts and Techniques Chapter 2 - Part 2 Creating a Java Application and Applet.
Introduction to Programming Writing Java Beginning Java Programs.
Karel J Robot An introduction to BlueJ and Object- Oriented Programming.
Multiple Forms, Container Controls, AddHandler This presentation is based on the Forms and ContainerControls VB Projects 1.
Greenfoot. Getting Started Open the Greenfoot download site: Select Greenfoot
TOPIC 3 INTRODUCTION TO PROGRAMMING 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B.
Copyright © 2009 Curt Hill The Picture Object Getting and displaying.
Copyright © Curt Hill Java Looking at our first console application in Eclipse.
Methods in Java CSC1401. Overview In this session, we are going to see how to create class-level methods in Java.
Introduction to Eclipse CSC 216 Lecture 3 Ed Gehringer Using (with permission) slides developed by— Dwight Deugo Nesa Matic
Debugging. 2 © 2003, Espirity Inc. Module Road Map 1.Eclipse Debugging  Debug Perspective  Debug Session  Breakpoint  Debug Views  Breakpoint Types.
1. 2 Reference... Student stu; Reference of Student stu When the reference is created it points to a null value. Before access the reference, objects.
Copyright © Curt Hill First Window Builder Program Easy GUIs in Eclipse.
Digital Stories Using Microsoft Photo Story 3 for Windows Carrie Roth (248)
Methods in Java. Program Modules in Java  Java programs are written by combining new methods and classes with predefined methods in the Java Application.
Copyright © Curt Hill Generic Classes Template Classes or Container Classes.
Jens Dalsgaard Nielsen Jan Dimon Bendtsen Dept. of Electronic Systems Basic Programming INS-basis GF, PDP and HST.
Setting Up Eclipse. What is Eclipse? Eclipse is a free, downloadable software that allows us to create, compile, and run JAVA programs.
EIE375 BlueJ: Getting Started Dr Lawrence Cheung.
Java development environment and Review of Java. Eclipse TM Intergrated Development Environment (IDE) Running Eclipse: Warning: Never check the “Use this.
Applications Development
Introduction to Programming Writing Java Beginning Java Programs.
Copyright Curt Hill Variables What are they? Why do we need them?
VARIABLES Programmes work by manipulating data placed in memory. The data can be numbers, text, objects, pointers to other memory areas, and more besides.
Copyright © Curt Hill More Components Varying the input of Dev-C++ Windows Programs.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
Copyright © 2004 – 2013 Curt Hill Java Debugging In Eclipse.
Copyright © Curt Hill Tortoise SVN A Subversion Client.
Computer Science I Programming in Java (programming using Processing IN Java, using IntelliJ IDE) Classwork/Homework: copy your Processing projects over.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
1 Class 1 Lecture Topic Concepts, Definitions and Examples.
Objective You will be able to define the basic concepts of object-oriented programming with emphasis on objects and classes by taking notes, seeing examples,
Copyright © – Curt Hill Building Windows Applications in wxDev-C++
Copyright © Curt Hill Simple I/O Input and Output using the System and Scanner Objects.
CompSci 42.1Intro to Java Anatomy of a Class & Terminology Running and Modifying a Program.
How to install JavaCV in Eclipse. Make sure to download and install all these before you proceed Eclipse for Java EE developers (current is Juno)
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
Getting and displaying
More methods, more capabilities
Eclipse Navigation & Usage.
Creating and Modifying Text part 2
Important terms Black-box testing White-box testing Regression testing
Important terms Black-box testing White-box testing Regression testing
Organizing common actions
Concepts From Alice Switching to Java Copyright © Curt Hill.
Other displays Saving Arrays Using fors to process
Methods Again Parameter Passage
Java IDE Dwight Deugo Nesa Matic Portions of the notes for this lecture include excerpts from.
Developing Java Applications with NetBeans
First Window Builder Program
Java Looking at our first console application in Eclipse
Developing Java Applications with NetBeans
Additional control structures
The beginning of media computation Followed by a demo
Methods Coding in Java Copyright © Curt Hill.
Presentation transcript:

Copyright © Curt Hill Turtles The beginning of media computation.

What is a turtle? It will show up as a icon in a window We direct the turtle to move forward or backward as well as turn left or right –Among other things When it moves it may leave a line as a trail It is a line drawing tool Copyright © Curt Hill

A Turtle in a World Copyright © Curt Hill

Two Objects There are two objects that are needed for this –A world –A turtle The world provides the window and background –The sandbox for one or more turtles The turtle –Our drawing object Copyright © Curt Hill

What is an object? In Java there are two kinds of variables –Primitives and objects A primitive represents one simple value –An int containing 4 –The character ‘A’ An object bundles one or more values into one Copyright © Curt Hill

Objects Objects have properties and methods A property is a variable that may be a variable or another object A method is a means to make the object do something –Obtain or change property values –A constructor is a kind of method that initializes the object Copyright © Curt Hill

Primitive Life Cycle We declare We assign values to them They are only known in the method that they are used within –Such as the main method Objects have a slightly different life cycle Copyright © Curt Hill

Object Life Cycle Declare the handle Allocate (or instantiate) using new or assignment –Declaration makes primitives exist but objects need another step Assign and use the values Copyright © Curt Hill

Terminology An object is a kind of variable A class is a type of object Example: String s = “S”; String is the class s is the object “S” is the value Copyright © Curt Hill

Declaration Objects are declared just like primitives Class_Name Variable_name ; Example: Turtle george; george is now an object handle Cannot be used until allocated An import statement may be needed to bring the class name within the scope Copyright © Curt Hill

Two ways to initialize Assign from an existing object Turtle george = sam; where sam is an existing turtle Use the new keyword Turtle bob=new Turtle(myWorld); The Turtle(myWorld) part is a constructor myWorld is the world that the turtle will be in Copyright © Curt Hill

Constructors Recall that a constructor is a special method of a class It has the same name as the class It is often overloaded by different sets of parameters One of the constructors is always executed for a newly created object It initializes the new object Copyright © Curt Hill

Preparation Eclipse knows about the Java Runtime Environment (JRE) This includes all Java standard objects such as Scanner It does not know about Turtles because they are not standard Java items Eclipse will allow new items to be added to a single project or to the JRE –It is easier to just modify the JRE Copyright © Curt Hill

JRE Modification Download TurtleGraphics.jar from class web site –Remember where you put it Select Window and then Preferences Choose preferences Open Java and Installed JREs in preferences Edit the JRE Click Add External JARs Find the downloaded TurtleGraphics.jar Copyright © Curt Hill

Lab Computers Some of you may be running Eclipse in a computer lab Sometimes these are periodically cleaned –Every night –During a reboot In such cases you should put the TurtleGraphics.jar file on your space: –Flash drive –Your space on another drive Copyright © Curt Hill

Downloading Copyright © Curt Hill

Window Preferences Copyright © Curt Hill

Preferences Copyright © Curt Hill

Open Java in Preferences Copyright © Curt Hill

Choose Installed JREs Copyright © Curt Hill

Select and Edit Copyright © Curt Hill

After Edit Button Copyright © Curt Hill

Add External Jar Copyright © Curt Hill

Finishing up Once TurtleGraphics.jar has been selected select the OK or Finish button until back at the main Eclipse window This modifies the JRE and we should not need to do it a second time One more thing may be needed, the forbidden access error needs to be disabled Copyright © Curt Hill

Java Errors Copyright © Curt Hill

Import Statement We have told Eclipse that we need TurtleGraphics to be part of the JRE There are a large number of things in the JRE that require an import to be used The import for this is: import turtlegraphics.*; This follows the package statement Copyright © Curt Hill

Creating a World Each World will become a screen Turtles must be created within a world Create the world: World myWorld = new World(); –World is class name –myWorld is variable name and could be any name, but will be used with Turtle constructor –World() is the constructor Copyright © Curt Hill

Creating Turtles Once myWorld has been made we can make turtles Create a turtle: Turtle sam = new Turtle(myWorld); –Turtle is a class name –sam is the name of one turtle –myWorld is the name of the previously created world We may create as many as we like Copyright © Curt Hill

Turtle Methods Making a turtle to exist is no big deal –We would like the turtle to do something –This takes methods For now just two forward(200); –Moves forward 200 pixels turn(90) –Turn right 90 degrees –Left uses a negative Copyright © Curt Hill

Eclipse Again One of the very many advantages of Eclipse over DrJava is the code completion option When we type in the name of a variable, that is a class, and then a dot –Eclipse suggests some methods that could be used See the following screen: Copyright © Curt Hill

Code Completion Copyright © Curt Hill

Forward chosen Copyright © Curt Hill

The new code Copyright © Curt Hill

Fill in the value Copyright © Curt Hill

Getting Started Create a new project Create a new class Add import Add five lines of code within main Copyright © Curt Hill

Whole but Short Program Copyright © Curt Hill package turtle; import turtlegraphics.*; public class FirstTurtle { public static void main(String[] args) { World w = new World(); Turtle t = new Turtle(w); t.forward(100); t.turn(90); t.forward(100); }

Run It After the program is complete run it A image similar to the next screen should occur Copyright © Curt Hill

The Run Copyright © Curt Hill

One last thought Do not name your project or class or package the same thing as any class you will use In particular do not use: –Turtle –World –Color –Picture –Among others If you do you may not be able to use any of these objects Copyright © Curt Hill

Try It Now we have a glorified etch-a- sketch –Soon we will have much more Create a new program Put in the commands to draw a square –4 forwards –4 turns of 90 I will and you can follow me in this Copyright © Curt Hill