Hi All,
In the programming in pascal language, I can configure with a
datatype/record written as
type
TStar = record
X, Y, Z: Longint; {3D location}
Size: Integer; {How big?}
StarColor: Integer;
Location: TPoint; {Screen location}
end;
var
gStarField: array[0..kNumOfStars] of tStar;
Do I have a similar design/code possibility that I can use in Java that
will duplicate that?
bH
Eric Sosman - 31 Jul 2006 18:41 GMT
bH wrote On 07/31/06 13:13,:
> Hi All,
> In the programming in pascal language, I can configure with a
[quoted text clipped - 14 lines]
>
> will duplicate that?
Use a class:
class TStar {
long X, Y, Z; // 3D location
int Size; // How big?
int StarColor;
TPoint Location; // Screen location
}
... and an array of references to it:
TStar[] gStarField = new TStar[kNumOfStars+1];
Let me raise a few stylistic points, though. First,
the usual convention in Java is to use an initial upper-case
letter in the name of a class or interface, but to begin
names of methods and variables with lower-case letters:
TStar and TPoint above are fine, but most of the other names
ought to change. Second, it might be a good idea to put
X,Y,Z (renamed x,y,z) into their own TPoint instance instead
of just letting them "float freely" in the TStar. Third, the
name kNumOfStars is badly misleading, both in Pascal and in
Java; consider changing it. Fourth, StarColor (starColor)
should probably be some kind of a Color object, possibly a
java.awt.Color, rather than a bare number.

Signature
Eric.Sosman@sun.com
Thomas Fritsch - 31 Jul 2006 18:52 GMT
> In the programming in pascal language, I can configure with a
> datatype/record written as
[quoted text clipped - 6 lines]
> Location: TPoint; {Screen location}
> end;
class TStar
{
long x, y, z;
int size;
int starColor;
java.awt.Point location;
}
> var
> gStarField: array[0..kNumOfStars] of tStar;
static final int NUM_STARS = 100;
TStar[] gStarArray = new TStar[NUM_STARS];
for (int i = 0; i < NUM_STARS; i++)
gStarArray[i] = new TStar();
> Do I have a similar design/code possibility that I can use in Java that
>
> will duplicate that?
As you obviously come from a procedural language, I assume that you
still have to grasp the general OO-concept (classes, objects, ...).
Hence you first need a good Java book or course with an OO-introduction,
too.

Signature
Thomas