Re: integers and arrays in Java - how?



Robert Baer wrote:
Evan Stratford wrote:

On Thu, 30 Mar 2006 10:20:56 GMT, Robert Baer
<robertbaer@xxxxxxxxxxxxx> wrote:


I used Google and found some references for integer in Java.
But "int" not only does not work, it also prevents reading X and Y coordinates of the mouse.
What i would like to do:
1) Get X and Y mouse coordinates into a variable that i can do real math on.
So far, i can do math on the values "read" and that result goes into a "variable" that is useful *only* for display.
If i try "int" in that math, the values are then zero for everything - even those where i do no calculation.
2) Use the calculated integer values as an index to a table or array.
It is acceptable to use an HTML "table" as the source for the lookup; W(CalcFromX) and P(CalcFromX) would be the resulting values to be displayed on the screen somewhere.

Can this be done, and eXactly how?


I'm taking a broad guess here, seeing as how your description is
vague, but...what you probably want is something along the lines of
this:

public MyClass implements MouseMotionListener {

// constructors and other methods...

// MouseMotionListener methods
public void mouseMoved(MouseEvent e) {
Point p = e.getPoint();
doSomeCalculation(p);
}

public void mouseDragged(MouseEvent e) {
/* more stuff here if necessary */
}

}

Alternatively, if called from within a class that extends some
subclass of java.awt.Component:

public MyClass extends JFrame {
public MyClass( /* parameters */) {
addMouseMotionListener(new MouseMotionListener() {
public void mouseMoved(MouseEvent e) {
Point p = e.getPoint();
doSomeCalculation(p);
}
public void mouseDragged(MouseEvent e) {
/* ... */
}
});
}

}

The doSomeCalculation(Point p) method could provide, say, a mapping
from regions to elements of a table, e.g. with the java.awt.Rectangle
contains() method.

Hope this helps; if not, you might want to be more specific!

Evan Stratford
1B CompSci/SoftEng option
University of Waterloo
WHat you gave might be useful to someone, but "class"? and "method"? and why bother to create what might be some kind of a function if a calculation is neededin only one place?
The "do some calculation" bit is what is troubling; "int" does not work and kills reading of mouse XY coordinates.
I will copy across the HTML / Java code i have from the OS and drive it is on, for show.

Can't you just grab the coordinates from the Point?
Method is another name for member function...
What exactly do you mean by "'class'?"?
Don't you know what a class is?
Anyway,
if you don't want to use a function, then just put the content of the function where he used one...
.



Relevant Pages

  • Re: integers and arrays in Java - how?
    ... If i try "int" in that math, the values are then zero for everything - even those where i do no calculation. ... public void mouseDragged{ ... The "do some calculation" bit is what is troubling; "int" does not work and kills reading of mouse XY coordinates. ...
    (comp.lang.java)
  • Re: integers and arrays in Java - how?
    ... If i try "int" in that math, the values are then zero for everything - even those where i do no calculation. ... public void mouseDragged{ ... The "do some calculation" bit is what is troubling; "int" does not work and kills reading of mouse XY coordinates. ...
    (comp.lang.java)
  • Re: integers and arrays in Java - how?
    ... If i try "int" in that math, the values are then zero for everything - even those where i do no calculation. ... public void mouseDragged{ ... The "do some calculation" bit is what is troubling; "int" does not work and kills reading of mouse XY coordinates. ...
    (comp.lang.java)
  • Re: integers and arrays in Java - how?
    ... If i try "int" in that math, the values are then zero for everything - even those where i do no calculation. ... public void mouseDragged{ ... The "do some calculation" bit is what is troubling; "int" does not work and kills reading of mouse XY coordinates. ...
    (comp.lang.java)
  • Re: imageObserver -- still dont understand
    ... public boolean imageUpdate(Image img, int infoflags, int x, int y, ... I added that imageUpdate method after reading about it online, ... need it for imageObserver to work. ... public void paint{ ...
    (comp.lang.java.programmer)