Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / July 2006

Tip: Looking for answers? Try searching our database.

java substitute for a pascal type record needed.

Thread view: 
bH - 31 Jul 2006 18:13 GMT
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



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.