BFOIT

Introduction
to Programming

Java

Turtle Graphics


Introduction


Turtle Graphics in a Java Program

Like the approach I took in Lesson 18 (Extending Existing Classes), I've written a bunch of classes you can use to do Turtle Graphics in Java.  The class that you extend is called TurtleGraphicsWindow.  When you extend it, you inherit all of the methods it provides.  It gets you all of the graphics-oriented commands and operators you've been using in TG.

*NOTE*
This does not get you access to the full TurtleTalk language, just the graphics stuff.  If you look at Appendix B, the TurtleTalk Primitives, you will see that there is a lot more to TurtleTalk than its Graphics Procedures.

Here is the JavaDoc documentation of the methods that are available.

To use the Turtle Graphics stuff, you will need to download a few Java sourcecode files to your system and compile them.  The files you need are:

TGKeyHandler.java
TGMouseHandler.java
TGPoint.java
TGGraphicsOp.java
TGFillOp.java
TGLabelOp.java
TGLineOp.java
TGCanvas.java
Turtle.java
TurtleGraphicsWindow.java


cross.java

To get you started, here is a very simple program to draw an X axis and Y axis.


    class cross extends TurtleGraphicsWindow
    {

        public void myTurtleCmds( )
        {
            forward( 100 );
            back( 200 );
            forward( 100 );
            right( 90 );
            forward( 100 );
            back( 200 );
        }

        // program starts here
        public static void main ( String[ ] args )    
        {
            cross obj = new cross( );
            obj.myTurtleCmds( );
        }

    } // end class cross
    
Example 20.1

Type it in; compile it; run it.


Summary


Back to Table of Contents
Back to previous Lesson ( Types of Arguments )
On to next Lesson ( Control Flow )