Help with multiple file projects

From: Herman (herman404_at_hotmail.com)
Date: 11/23/03


Date: 23 Nov 2003 12:07:04 -0800

Hi everyone, I have a multiple file project for a class assignment.
It consists of a class Point, then a class Polygon which uses the
Point object, then a class Picture that uses the Polygon object.
Unfortunately, I cannot compile Polygon.java, because it cannot
recgonise the Point object. Any ideas? (I'm using the Sun SDK 1.4.2)
 Thanks! (By the way, the drawing package and Canvas class were
created by my instructor to make drawing to Graphics easier)

Point.java:
**
 * Point.java
 * ----------
 * Defines the base class for the drawing exercises
 */

package csc812;

import drawing.*;

class Point
{
        private int m_iXValue;
        private int m_iYValue;

        // Default constructor
        public Point()
        {
                this.m_iXValue = 0;
                this.m_iYValue = 0;
        }

        // values constructor
        public Point(int x,int y)
        {
                this.m_iXValue = x;
                this.m_iYValue = y;
        }

        // Copy constructor
        public Point(Point P)
        {
                this.m_iXValue = P.m_iXValue;
                this.m_iYValue = P.m_iYValue;
        }

        // Calculates the distance between this and a given point
        public double distance(Point p)
        {
                return Math.sqrt((m_iXValue-p.m_iXValue)*(m_iXValue-p.m_iXValue) +
(m_iYValue-p.m_iYValue)*(m_iYValue-p.m_iYValue));
        }

        // Draws a line between this and the given point
        public void DrawLine(Point p,Canvas c)
        {
                c.drawLine(m_iXValue,m_iYValue,p.m_iXValue,p.m_iYValue);
        }

        // Outputs the coordinates - primarily for debugging
        public void dump()
        {
                System.out.println("(" + m_iXValue + "," + m_iYValue + ")");
        }
}

Polygon.java:
/**
 * Polygon.java
 * ------------
 * This class uses the Point class to draw a polygon based on the
given points
 * One critical assumption we make is that element 0 of the array list
is the
 * starting point of the drawing
 *
 */

package csc812;

import java.lang.*;
import java.util.*;
import java.awt.Color;
import drawing.*;
import csc812.Point;

class Polygon extends Point
{
        // Declare an ArrayList, since we cannot predetermine how many
elements we will have
        private ArrayList m_List;
        // foreground colour is part of the polygon
        private Color m_ForeColour;

        // Default constructor
        public Polygon()
        {
                m_List = new ArrayList();
                m_ForeColour = Color.BLACK;
        }

        // Constructor
        public Polygon(ArrayList List,Color cl)
        {
                if (List.contains(Point))
                {
                        m_List = new ArrayList();
                        m_List = List;
                }
                else
                {
                        System.out.println("Polygon constructor error");
                        System.out.println("The ArrayList passed is not of type Point, so
cannot construct object");
                }
                m_ForeColour = cl;
        }

        // Copy constructor
        public Polygon(Polygon p)
        {
                m_List = new ArrayList();
                m_List = p.m_List;
                m_ForeColour = p.m_ForeColour;
        }

        // Draws the polygon
        public void Display(Canvas c)
        {
                // Declare array for use
                Point [] pArray = new Point[m_List.size()];
                pArray = m_List.toArray();

                c.setForegroundColor(m_ForeColour);
                for (int i = 0;i < pArray.length;i++)
                {
                        try
                        {
                                Point p1 = new Point(pArray[i]);
                                Point p2 = new Point(pArray[i+1]);
                                p1.DrawLine(p2,g);
                        }
                        catch(ArrayIndexOutOfBoundsException e)
                        {
                                break;
                        }
                }
        }

        // Sets foreground colour
        public void SetColour(Color f)
        {
                m_ForeColour = f;
        }

        // Output for debugging
        public void Dump()
        {
                // Declare array for use
                Point [] pArray = new Point[m_List.size()];
                pArray = m_List.toArray();

                for (int i = 0;i < pArray.length;i++)
                {
                        Point p = new Point(pArray[i]);
                        p.Dump();
                }
        }
}

Error messages:
Polygon.java:19: cannot resolve symbol
symbol : class Point
location: package csc812
import csc812.Point;
              ^
Polygon.java:21: cannot resolve symbol
symbol : class Point
location: class csc812.Polygon
class Polygon extends Point
                      ^
Polygon.java:38: cannot resolve symbol
symbol : variable Point
location: class csc812.Polygon
                if (List.contains(Point))
                                  ^
Polygon.java:63: cannot resolve symbol
symbol : class Point
location: class csc812.Polygon
                Point [] pArray = new Point[m_List.size()];
                ^
Polygon.java:63: cannot resolve symbol
symbol : class Point
location: class csc812.Polygon
                Point [] pArray = new Point[m_List.size()];
                                      ^
Polygon.java:66: cannot resolve symbol
symbol : method setForegroundColor (java.awt.Color)
location: class drawing.Canvas
                c.setForegroundColor(m_ForeColour);
                 ^
Polygon.java:71: cannot resolve symbol
symbol : class Point
location: class csc812.Polygon
                                Point p1 = new Point(pArray[i]);
                                ^
Polygon.java:71: cannot resolve symbol
symbol : class Point
location: class csc812.Polygon
                                Point p1 = new Point(pArray[i]);
                                               ^
Polygon.java:72: cannot resolve symbol
symbol : class Point
location: class csc812.Polygon
                                Point p2 = new Point(pArray[i+1]);
                                ^
Polygon.java:72: cannot resolve symbol
symbol : class Point
location: class csc812.Polygon
                                Point p2 = new Point(pArray[i+1]);
                                               ^
Polygon.java:73: cannot resolve symbol
symbol : variable g
location: class csc812.Polygon
                                p1.DrawLine(p2,g);
                                               ^
Polygon.java:92: cannot resolve symbol
symbol : class Point
location: class csc812.Polygon
                Point [] pArray = new Point[m_List.size()];
                ^
Polygon.java:92: cannot resolve symbol
symbol : class Point
location: class csc812.Polygon
                Point [] pArray = new Point[m_List.size()];
                                      ^
Polygon.java:97: cannot resolve symbol
symbol : class Point
location: class csc812.Polygon
                        Point p = new Point(pArray[i]);
                        ^
Polygon.java:97: cannot resolve symbol
symbol : class Point
location: class csc812.Polygon
                        Point p = new Point(pArray[i]);
                                      ^
15 errors



Relevant Pages

  • Help with multiple file projects
    ... It consists of a class Point, then a class Polygon which uses the ... created by my instructor to make drawing to Graphics easier) ... Error messages: ... Polygon.java:19: cannot resolve symbol ...
    (comp.lang.java.programmer)
  • PLEASE HELP - Does J2ME include java.lang.Math
    ... I get error messages as: ... symbol: method log (int) ...
    (comp.lang.java.programmer)