Re: integers and arrays in Java - how?



Ian Shef wrote:
Sigmund Hansen <sigmunha@xxxxxxxxxxxxxxxxx> wrote in news:qsbXf.8452$zc1.6768
@amstwist00:

Oh yeah, I forgot:
to get the X and Y coordinates just use:

snippety snippety snip ...

Point p = e.getPoint();
int x = p.getX();
int y = p.getY();

snippety ...

The getX and getY functions will return the ints of the Point you got from the mouseEvent in Evan's code...


Wrong! Sorry, but I just got caught by this the other day.

The methods getX() and getY() in java.awt.Point each return a double !

Your code should look more like:

Point p = e.getPoint();
int x = p.x;
int y = p.y;

x and y are public int fields of Point.




Yeah I noticed that a bit later,
but figured it was a bit late to post another correction...
Didn't know they were public, but that might explain why it has integer coordinates whose get methods return doubles...

Anyway,
it doesn't apply to this because he's coding JavaScript...
(BTW, I haven't actually coded in years, so my memory on classes and functions in even the standard API is kind of nasty, and for that matter deprecated.
But I'm starting back up now, trying to learn some LWJGL and such, hopefully it will be fun, and not just time consuming (time being something I don't have a lot of))... ;)
.



Relevant Pages

  • Re: integers and arrays in Java - how?
    ... snippety snippety snip ... ... int x = p.getX; ... The getX and getY functions will return the ints of the Point you got ... The methods getX() and getYin java.awt.Point each return a double! ...
    (comp.lang.java)
  • Re: squeezing the use of memory
    ... it may be time consuming thing because of promoting byte to int. ... > Qick question about the use of int Vs. the use of short,char,byte ...
    (comp.lang.java.programmer)