|

楼主 |
发表于 2003-7-21 13:29
|
显示全部楼层
不好意思,能不能麻烦再看看下例
public class LineTest
{
public static void main(String args[])
{
Line line = new Line(0,0,10,20);
line.moveVertical(10);
line.moveHorizontal(20);
System.out.println(line.startPoint.toString() + "," + line.endPoint.toString());
}
}
public class Line
{
Point startPoint, endPoint;
public Line(int x1, int y1, int x2, int y2)
{
startPoint = new Point (x1, y1);
endPoint = new Point (x2,y2);
}
public Line()
{
this (0,0,0,0);
}
public void moveVertical(int distance)
{
startPoint.incrY(distance);
endPoint.incrY(distance);
}
public void moveHorizontal(int distance)
{
startPoint.incrX(distance);
endPoint.incrX(distance);
}
}
public class Point
{
private int x,y;
public Point(int x,int y)
{
this.x = x;
this.y = y;
}
public void incrX(int d)
{
x += d;
}
public void incrY(int d)
{
y += d;
}
public String toString()
{
return x + "/" + y;
}
}
LineTest.java:12: class Line is public, should be declared in a file named Line.java
public class Line
^
LineTest.java:39: class Point is public, should be declared in a file named Point.java
public class Point
^
2 errors
Exit code: 1
There were errors |
|