Re: integers and arrays in Java - how?
- From: Robert Baer <robertbaer@xxxxxxxxxxxxx>
- Date: Fri, 31 Mar 2006 10:54:42 GMT
Evan Stratford wrote:
On Thu, 30 Mar 2006 10:20:56 GMT, Robert BaerWHat 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?
<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
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.
.
- Follow-Ups:
- Re: integers and arrays in Java - how?
- From: Sigmund Hansen
- Re: integers and arrays in Java - how?
- From: Sigmund Hansen
- Re: integers and arrays in Java - how?
- References:
- integers and arrays in Java - how?
- From: Robert Baer
- Re: integers and arrays in Java - how?
- From: Evan Stratford
- integers and arrays in Java - how?
- Prev by Date: Re: integers and arrays in Java - how?
- Next by Date: Re: integers and arrays in Java - how?
- Previous by thread: Re: integers and arrays in Java - how?
- Next by thread: Re: integers and arrays in Java - how?
- Index(es):
Relevant Pages
|
|