• Post Reply Bookmark Topic Watch Topic
  • New Topic

Not sure on 2 lines  RSS feed

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there

I'm having a browse through java examples on the net to get familiar with it all again. I came across these 2 lines in a programme but i'm not sure what they do - could some one explain:

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

im probably not going to be much help (just came back to java after 2 yrs out), but to me its to do with x/y coordinates on screen, of an object in array "cars". "p" some variable that you havent included and could be alot of things.
I believe with no "offset" the "cars[j]" doesnt show correctly on screen, and offset.x (left to right) / offset.y (up to down) changes the coordinates.

rg.

ps i really probably am way off and completely wrong, but i tried
 
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are probably right, Richard, but the question is more complicated than it first appears.

There is obviously an object called "offset" with two public fields (bad practice that), x and y which you are setting. Another object called p (bad naming) again with two public fields.
Thre is obviously an array called cars, and you are getting whichever car is at that particular index j, and using its public getIntX() and getIntY() methods (better practice) you are doing a little arithmetic and setting the fields of the offset object.

The suggestion that you are using the coordinates from the car array to set those in the offset object is probably correct, but you would have to examine the javadoc pages (if there actually are any) or the code in the offset and p objects to confirm that is correct.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!