BFOIT - Introduction to Computer Programming

Java TurtleGraphics

Introduction

In this lesson you will use a Turtle object.  It has methods that correspond to procedures in Logo.  This will help you see and compare programs that you started out writing in Logo with similar programs written in Java.

TurtleGraphics in a Java Program

Like the approach I took in Extending Existing Classes, I've written a bunch of classes you can use to do TurtleGraphics in Java.  The class that you will extend is named 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 Logo.

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

To use the TurtleGraphics stuff, you will need to copy a few Java source code files to your computer and compile them.  The files you need are:

ArrowTurtle.java
BallTurtle.java
BoxTurtle.java
CrossTurtle.java
TGCanvas.java
TGFillOp.java
TGGraphicsOp.java
TGKeyHandler.java
TGLabelOp.java
TGLineOp.java
TGMouseHandler.java
TGPoint.java
TriangleTurtle.java
Turtle.java
TurtleGraphicsWindow.java
TurtlePixels.java
TurtleTurtle.java
CompileTGW.bat

Cross.java

To get you started, here is the JavaDoc documentation of the methods that are available.

And... here is a very simple program to draw an X axis and Y axis.  Copy it and paste it into a file named Cross.java, then compile and run it.

  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 

Summary


Back to Types of Arguments
Go to the Table of Contents
On to Control Flow