Help with multiple file projects

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Herman

    Help with multiple file projects

    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_iX Value-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_iX Value,m_iYValue ,p.m_iXValue,p. m_iYValue);
    }

    // Outputs the coordinates - primarily for debugging
    public void dump()
    {
    System.out.prin tln("(" + 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(ArrayLi st List,Color cl)
    {
    if (List.contains( Point))
    {
    m_List = new ArrayList();
    m_List = List;
    }
    else
    {
    System.out.prin tln("Polygon constructor error");
    System.out.prin tln("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.setForeground Color(m_ForeCol our);
    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(ArrayInde xOutOfBoundsExc eption 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 setForegroundCo lor (java.awt.Color )
    location: class drawing.Canvas
    c.setForeground Color(m_ForeCol our);
    ^
    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
  • Dan Nuttle

    #2
    Re: Help with multiple file projects

    I can't see any immediate cause for the compile error. Both classes are in
    the same package, so you actually don't need to import Point in Polygon, but
    doing so doesn't hurt anything. I pulled your code into Eclipse, using JDK
    1.3.1, commented out things like references to objects in your drawing
    package, and the code compiled for me.

    So there's something else at work that you're not showing; unless there's
    some big difference between 1.3.1 and 1.4.0 that I don't know about; I
    don't think that's the case.


    Comment

    • Herman

      #3
      Re: Help with multiple file projects

      "Dan Nuttle" <d_nuttle@hotma il.com> wrote in message news:<x39wb.167 68$Rk5.2688@new sread1.news.atl .earthlink.net> ...[color=blue]
      > I can't see any immediate cause for the compile error. Both classes are in
      > the same package, so you actually don't need to import Point in Polygon, but
      > doing so doesn't hurt anything. I pulled your code into Eclipse, using JDK
      > 1.3.1, commented out things like references to objects in your drawing
      > package, and the code compiled for me.
      >
      > So there's something else at work that you're not showing; unless there's
      > some big difference between 1.3.1 and 1.4.0 that I don't know about; I
      > don't think that's the case.[/color]

      I compiled it in the BlueJ IDE and it worked fine. Someone mentioned
      that in order to compile using packages with the Sun SDK, you needed a
      makefile or something like that. Anyone know how to compile multiple
      ..java files into a package using the Sun SDK?

      Comment

      • hiwa

        #4
        Re: Help with multiple file projects

        herman404@hotma il.com (Herman) wrote in message news:<d647544a. 0311281041.2eaf [email protected] ogle.com>...[color=blue]
        > "Dan Nuttle" <d_nuttle@hotma il.com> wrote in message news:<x39wb.167 68$Rk5.2688@new sread1.news.atl .earthlink.net> ...[color=green]
        > > I can't see any immediate cause for the compile error. Both classes are in
        > > the same package, so you actually don't need to import Point in Polygon, but
        > > doing so doesn't hurt anything. I pulled your code into Eclipse, using JDK
        > > 1.3.1, commented out things like references to objects in your drawing
        > > package, and the code compiled for me.
        > >
        > > So there's something else at work that you're not showing; unless there's
        > > some big difference between 1.3.1 and 1.4.0 that I don't know about; I
        > > don't think that's the case.[/color]
        >
        > I compiled it in the BlueJ IDE and it worked fine. Someone mentioned
        > that in order to compile using packages with the Sun SDK, you needed a
        > makefile or something like that. Anyone know how to compile multiple
        > .java files into a package using the Sun SDK?[/color]

        If your class A that belongs to package P does refer to class B that
        also belongs to package P, then, when you compile A.java in the
        current directory P,

        javac -classpath .. A.java

        If you compile A.java in the current directory ../P, which is the root
        directory of package P,

        javac -classpath . A.java

        In order to learn classpath setting for Java package, read the J2SE
        basic documents for javac compiler.

        Comment

        Working...