Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / January 2007

Tip: Looking for answers? Try searching our database.

TurtleGraphics DrawLine Problem in program SmilingFace.java

Thread view: 
ryanshumaker@yahoo.com - 15 Jan 2007 20:30 GMT
Hi,

I am helping to tutor some students with java using the textbook "Java
Basics" by Lambert and Osborne.  One program calls for the use of
TurtleGraphics.  The students are able to get the drawcircle part to
work, but do not get the DrawLine portion to perform.  The program
called, SmilingFace, calls for a circle to get created (as a smiley
face), with two small circles for eyes, and three line segments to make
up the smile.  It uses a helper m

When run, the result is the "head" with the two "eyes", but the smile
does not get drawn.

Does anyone know what might be causing the problem?

Here is the code for the two classes, TestSmilingFace and SmilingFace.

SmilingFace.java:

import TurtleGraphics.*;
import java.awt.Color;

public class SmilingFace {

        private StandardPen pen;
        private double xPosition, yPosition;

        public SmilingFace(){
            xPosition = 0;
            yPosition = 0;
            pen = new StandardPen();
            pen.setColor(Color.yellow);

        }

        public SmilingFace (double x, double y) {
            this();
            xPosition = x;
            yPosition = y;
        }

        public void draw(){
            double radius = 25.0;

            drawCircle(xPosition, yPosition, radius);

            drawCircle(xPosition - radius / 2.5, yPosition + radius / 3, radius
/ 4);

            drawCircle(xPosition + radius / 2.5, yPosition + radius / 3, radius
/ 4);

            drawLine(xPosition - radius / 3, yPosition - radius / 2, xPosition +

                radius / 3, yPosition - radius / 2);

            drawLine(xPosition - radius / 3, yPosition - radius / 2, xPosition +

                radius / 3 - 5, yPosition - radius / 2 + 5);

            drawLine(xPosition + radius / 3, yPosition - radius / 2, xPosition +

                radius / 3 + 5, yPosition - radius / 2 + 5);

        }

        public void erase(){
            pen.setColor(Color.white);
            draw();
            pen.setColor(Color.yellow);
        }

        public void move(double x, double y) {
            xPosition = x;
            yPosition = y;
        }

        private void drawCircle (double x, double y, double r) {
            double side = 2.0 * Math.PI * r / 120;
            pen.up();
            pen.move(x + r, y - side / 2.0);
            pen.setDirection(90);
            pen.down();
            for (int i = 0; i < 120; i++) {
                pen.move(side);
                pen.turn(3);
            }
        }

        private void drawLine(double x1, double y1, double x2, double y2) {
    }
}

TestSmilingFace.java:

import TurtleGraphics.*;
import TerminalIO.*;

public class TestSmilingFace {
    public static void main(String [] args){

        KeyboardReader reader = new KeyboardReader();
        double x, y, radius;

        x = reader.readDouble("Initial x position: ");
        y = reader.readDouble("Initial y position: ");

        SmilingFace face = new SmilingFace(x, y);
        face.draw();

        while (true) {
            x = reader.readDouble("New x position: ");
            y = reader.readDouble("New y position: ");
            face.erase();
            face.move(x, y);
            face.draw();
        }
    }
}
Paul Hamaker - 16 Jan 2007 09:16 GMT
drawLine is empty ! :
 private void drawLine(double x1, double y1, double x2, double y2)
{        }
--
http://javalessons.com  Paul Hamaker, SEMM
Teaching ICT since 1987
ryanshumaker@yahoo.com - 17 Jan 2007 12:45 GMT
Thanks.  That's interesting.  I see that now but that's how it is
written in the text so I'm guessing it was a typo in the textbook.

Thanks again.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.