By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,541 Members | 1,106 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,541 IT Pros & Developers. It's quick & easy.

Help with multiple file projects

P: n/a
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_iYV alue);
}

// 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
Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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.
Jul 17 '05 #2

P: n/a
"Dan Nuttle" <d_******@hotmail.com> wrote in message news:<x3******************@newsread1.news.atl.eart hlink.net>...
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.


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?
Jul 17 '05 #3

P: n/a
he*******@hotmail.com (Herman) wrote in message news:<d6**************************@posting.google. com>...
"Dan Nuttle" <d_******@hotmail.com> wrote in message news:<x3******************@newsread1.news.atl.eart hlink.net>...
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.


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?


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.
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.