Re: integers and arrays in Java - how?
- From: Evan Stratford <estratfo@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 30 Mar 2006 12:03:44 -0500
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
.
- Follow-Ups:
- Re: integers and arrays in Java - how?
- From: Robert Baer
- Re: integers and arrays in Java - how?
- References:
- integers and arrays in Java - how?
- From: Robert Baer
- integers and arrays in Java - how?
- Prev by Date: Re: integers and arrays in Java - how?
- Next by Date: Re: Using direct access in the constructor?
- Previous by thread: Re: integers and arrays in Java - how?
- Next by thread: Re: integers and arrays in Java - how?
- Index(es):
Relevant Pages
|
|