By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,078 Members | 1,733 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,078 IT Pros & Developers. It's quick & easy.

integers and arrays in Java - how?

P: n/a
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?

Mar 30 '06 #1
Share this Question
Share on Google+
17 Replies


P: n/a

"Robert Baer" <ro********@earthlink.net> wrote in message
news:ci******************@newsread2.news.pas.earth link.net...
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 didn't understand your question at all. Perhaps you can post an SSCCE?
http://mindprod.com/jgloss/sscce.html

Be sure to specify what results you expected your program to produce,
and what results you actually got, and how they differed.

- Oliver

Mar 30 '06 #2

P: n/a
On Thu, 30 Mar 2006 10:20:56 GMT, Robert Baer
<ro********@earthlink.net> 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
Mar 30 '06 #3

P: n/a
Oliver Wong wrote:

"Robert Baer" <ro********@earthlink.net> wrote in message
news:ci******************@newsread2.news.pas.earth link.net...
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 didn't understand your question at all. Perhaps you can post an
SSCCE? http://mindprod.com/jgloss/sscce.html

Be sure to specify what results you expected your program to produce,
and what results you actually got, and how they differed.

- Oliver

I *thought* i mentioned what i wanted to do, as well as "int" not
only does not work, it kills the reading of mouse XY coordinates.
And i would have no clue as if the code was compilable or not, and i
do not think i care, since the jave code is a part of an HTML web page.
However, i will copy the code i have across from my other OS drive later.

Mar 31 '06 #4

P: n/a
Evan Stratford wrote:
On Thu, 30 Mar 2006 10:20:56 GMT, Robert Baer
<ro********@earthlink.net> 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.
Mar 31 '06 #5

P: n/a
"Robert Baer" <ro********@earthlink.net> wrote in message
news:nN******************@newsread2.news.pas.earth link.net...
Oliver Wong wrote:

"Robert Baer" <ro********@earthlink.net> wrote in message
news:ci******************@newsread2.news.pas.earth link.net...
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 didn't understand your question at all. Perhaps you can post an
SSCCE? http://mindprod.com/jgloss/sscce.html

Be sure to specify what results you expected your program to produce,
and what results you actually got, and how they differed.

- Oliver

I *thought* i mentioned what i wanted to do, as well as "int" not only
does not work, it kills the reading of mouse XY coordinates.
And i would have no clue as if the code was compilable or not, and i do
not think i care, since the jave code is a part of an HTML web page.
However, i will copy the code i have across from my other OS drive
later.


Since the code is "part of an HTML web page", might you be talking about
JavaScript, rather than Java?

- Oliver

Mar 31 '06 #6

P: n/a
Robert Baer wrote:
Evan Stratford wrote:
On Thu, 30 Mar 2006 10:20:56 GMT, Robert Baer
<ro********@earthlink.net> 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...
Mar 31 '06 #7

P: n/a
Robert Baer wrote:
Evan Stratford wrote:
On Thu, 30 Mar 2006 10:20:56 GMT, Robert Baer
<ro********@earthlink.net> 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.


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...
Mar 31 '06 #8

P: n/a
Robert Baer 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?

Here is the code i have so far:
<html code starts here; this is altered to help protect some>
<head>
<title>Test page</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="style.css">
</head>

<!--
var with "Netscape" makes Netscape happy
adding "int" or "integer" in any way totally kills operation
-->
<SCRIPT LANGUAGE="JavaScript">
<!--
var isNav = (navigator.appName.indexOf("Netscape") !=-1);
function handlerMM(e){
Xmm = (isNav) ? e.pageX : event.clientX;
Ymm = (isNav) ? e.pageY : event.clientY;
document.dataholder.mmX.value=((Xmm-173)/6.8+1938);
document.dataholder.mmY1.value=Ymm;
document.dataholder.mmY2.value=Xmm;
document.dataholder.mmZ.value=((Xmm-173)/6.8+1938);
}
if (isNav) {
document.captureEvents(Event.MOUSEMOVE);
}
document.onmousemove = handlerMM;
// -->
</SCRIPT>

<body>
<center>
<form name="dataholder">
<table border=1>
<tr>
<td><i>Year(wide)</i></td>
<td><input type="text" size=9 name="mmX" value="0"></td>
<td><i>Year(narrow)</i></td>
<td><input type="number" size=3.8 name="mmX" value="0"></td>
<td><i>Number of wells</i></td>
<td><input type="text" size=5 name="mmY1" value="0"></td>
<td><i>Production BBLs</i></td>
<td><input type="text" size=5 name="mmY2" value="0"></td>
<td><i>Z value</i></td>
<td><input type="text" size=9 name="mmZ" value="0"></td>
</tr>
</table>
</form>
</div>

<!--
This code *used to* work, showing a calculated year in the first 2
boxes; the width
of the second box was made narrow to visually "truncate" the
numbers to integer.
I have no idea as to why they no longer work.
I added "Z value" and *that* works (!!). Go figure.
-->

<table align="center">
<tr>
<td align=center>
<center>
<div><i>&copy 2006 Oil 4 Less LLC</i></div>
</center>
</td>
</tr>
</table>

<!-- style and then img src as seperate items makes IE happy; GIF
is 90% BMP -->
<div style="position: absolute; height: 316px; width: 697px; top: 100px;
left: 20px; "
<style="height: 316px; width: 697px; top: 100px; left: 20px; " >
<img src="Arkansas.gif" alt="" usemap="#AK" style="border-style:none" >
</div>

</body>
</html>
Mar 31 '06 #9

P: n/a
Robert Baer wrote:
Robert Baer 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?

Here is the code i have so far:
<html code starts here; this is altered to help protect some>
<head>
<title>Test page</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="style.css">
</head>

<!--
var with "Netscape" makes Netscape happy
adding "int" or "integer" in any way totally kills operation
-->
<SCRIPT LANGUAGE="JavaScript">
<!--
var isNav = (navigator.appName.indexOf("Netscape") !=-1);
function handlerMM(e){
Xmm = (isNav) ? e.pageX : event.clientX;
Ymm = (isNav) ? e.pageY : event.clientY;
document.dataholder.mmX.value=((Xmm-173)/6.8+1938);
document.dataholder.mmY1.value=Ymm;
document.dataholder.mmY2.value=Xmm;
document.dataholder.mmZ.value=((Xmm-173)/6.8+1938);
}
if (isNav) {
document.captureEvents(Event.MOUSEMOVE);
}
document.onmousemove = handlerMM;
// -->
</SCRIPT>

<body>
<center>
<form name="dataholder">
<table border=1>
<tr>
<td><i>Year(wide)</i></td>
<td><input type="text" size=9 name="mmX" value="0"></td>
<td><i>Year(narrow)</i></td>
<td><input type="number" size=3.8 name="mmX" value="0"></td>
<td><i>Number of wells</i></td>
<td><input type="text" size=5 name="mmY1" value="0"></td>
<td><i>Production BBLs</i></td>
<td><input type="text" size=5 name="mmY2" value="0"></td>
<td><i>Z value</i></td>
<td><input type="text" size=9 name="mmZ" value="0"></td>
</tr>
</table>
</form>
</div>

<!--
This code *used to* work, showing a calculated year in the first 2
boxes; the width
of the second box was made narrow to visually "truncate" the
numbers to integer.
I have no idea as to why they no longer work.
I added "Z value" and *that* works (!!). Go figure.
-->

<table align="center">
<tr>
<td align=center>
<center>
<div><i>&copy 2006 Oil 4 Less LLC</i></div>
</center>
</td>
</tr>
</table>

<!-- style and then img src as seperate items makes IE happy; GIF
is 90% BMP -->
<div style="position: absolute; height: 316px; width: 697px; top: 100px;
left: 20px; "
<style="height: 316px; width: 697px; top: 100px; left: 20px; " >
<img src="Arkansas.gif" alt="" usemap="#AK" style="border-style:none" >
</div>

</body>
</html>


Yeah,
this is JavaScript,
which basically has nothing to do with Java...
I believe there is some Object Orientation in it,
but not as advanced as Java's.
I'd recommend you go to the comp.lang.javascript group instead, or a
similar one...
Apr 2 '06 #10

P: n/a
Sigmund Hansen <si******@student.hf.uio.no> 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.

--
Ian Shef 805/F6 * These are my personal opinions
Raytheon Company * and not those of my employer.
PO Box 11337 *
Tucson, AZ 85734-1337 *
Apr 3 '06 #11

P: n/a
Ian Shef wrote:
Sigmund Hansen <si******@student.hf.uio.no> 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))... ;)
Apr 3 '06 #12

P: n/a
Oliver Wong wrote:
"Robert Baer" <ro********@earthlink.net> wrote in message
news:nN******************@newsread2.news.pas.earth link.net...
Oliver Wong wrote:

"Robert Baer" <ro********@earthlink.net> wrote in message
news:ci******************@newsread2.news.pas.earth link.net...

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 didn't understand your question at all. Perhaps you can post an
SSCCE? http://mindprod.com/jgloss/sscce.html

Be sure to specify what results you expected your program to
produce, and what results you actually got, and how they differed.

- Oliver


I *thought* i mentioned what i wanted to do, as well as "int" not
only does not work, it kills the reading of mouse XY coordinates.
And i would have no clue as if the code was compilable or not, and i
do not think i care, since the jave code is a part of an HTML web page.
However, i will copy the code i have across from my other OS drive
later.


Since the code is "part of an HTML web page", might you be talking
about JavaScript, rather than Java?

- Oliver

I have been sick since Saturday, and that is why i have not posted
anything.
From others, i discovered that you are correct; Java Script.
Apr 6 '06 #13

P: n/a
Sigmund Hansen wrote:
Robert Baer wrote:
Evan Stratford wrote:
On Thu, 30 Mar 2006 10:20:56 GMT, Robert Baer
<ro********@earthlink.net> 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...

No, i have no clue what a "calss" is, or how to do what you mentioned.
Apr 6 '06 #14

P: n/a
Sigmund Hansen wrote:
Robert Baer wrote:
Evan Stratford wrote:
On Thu, 30 Mar 2006 10:20:56 GMT, Robert Baer
<ro********@earthlink.net> 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.

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...

I will try that, but am not enthused as "int" seems to not work but
worse, kill everything else JavaScript wise..
Apr 6 '06 #15

P: n/a
Sigmund Hansen wrote:
Robert Baer wrote:
Robert Baer 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?

Here is the code i have so far:
<html code starts here; this is altered to help protect some>
<head>
<title>Test page</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="style.css">
</head>

<!--
var with "Netscape" makes Netscape happy
adding "int" or "integer" in any way totally kills operation
-->
<SCRIPT LANGUAGE="JavaScript">
<!--
var isNav = (navigator.appName.indexOf("Netscape") !=-1);
function handlerMM(e){
Xmm = (isNav) ? e.pageX : event.clientX;
Ymm = (isNav) ? e.pageY : event.clientY;
document.dataholder.mmX.value=((Xmm-173)/6.8+1938);
document.dataholder.mmY1.value=Ymm;
document.dataholder.mmY2.value=Xmm;
document.dataholder.mmZ.value=((Xmm-173)/6.8+1938);
}
if (isNav) {
document.captureEvents(Event.MOUSEMOVE);
}
document.onmousemove = handlerMM;
// -->
</SCRIPT>

<body>
<center>
<form name="dataholder">
<table border=1>
<tr>
<td><i>Year(wide)</i></td>
<td><input type="text" size=9 name="mmX" value="0"></td>
<td><i>Year(narrow)</i></td>
<td><input type="number" size=3.8 name="mmX" value="0"></td>
<td><i>Number of wells</i></td>
<td><input type="text" size=5 name="mmY1" value="0"></td>
<td><i>Production BBLs</i></td>
<td><input type="text" size=5 name="mmY2" value="0"></td>
<td><i>Z value</i></td>
<td><input type="text" size=9 name="mmZ" value="0"></td>
</tr>
</table>
</form>
</div>

<!--
This code *used to* work, showing a calculated year in the first 2
boxes; the width
of the second box was made narrow to visually "truncate" the
numbers to integer.
I have no idea as to why they no longer work.
I added "Z value" and *that* works (!!). Go figure.
-->

<table align="center">
<tr>
<td align=center>
<center>
<div><i>&copy 2006 Oil 4 Less LLC</i></div>
</center>
</td>
</tr>
</table>

<!-- style and then img src as seperate items makes IE happy;
GIF is 90% BMP -->
<div style="position: absolute; height: 316px; width: 697px; top:
100px; left: 20px; "
<style="height: 316px; width: 697px; top: 100px; left: 20px; " >
<img src="Arkansas.gif" alt="" usemap="#AK" style="border-style:none" >
</div>

</body>
</html>


Yeah,
this is JavaScript,
which basically has nothing to do with Java...
I believe there is some Object Orientation in it,
but not as advanced as Java's.
I'd recommend you go to the comp.lang.javascript group instead, or a
similar one...

Thanks.
Apr 6 '06 #16

P: n/a
"Robert Baer" <ro********@earthlink.net> wrote in message
news:c_***************@newsread3.news.pas.earthlin k.net...
Oliver Wong wrote:
Since the code is "part of an HTML web page", might you be talking
about JavaScript, rather than Java?
I have been sick since Saturday, and that is why i have not posted
anything.


Hope you're feeling better now.
From others, i discovered that you are correct; Java Script.


Okay, you can probably ignore most of the advice you've received here
(e.g. "class" is a concept which only exists in Java, and not in
JavaScript). Probably best if you repost your question at a JavaScript
newsgroup like comp.lang.javascript.

- Oliver

Apr 6 '06 #17

P: n/a
Oliver Wong wrote:
"Robert Baer" <ro********@earthlink.net> wrote in message
news:c_***************@newsread3.news.pas.earthlin k.net...
Oliver Wong wrote:
Since the code is "part of an HTML web page", might you be talking
about JavaScript, rather than Java?

I have been sick since Saturday, and that is why i have not posted
anything.

Hope you're feeling better now.
From others, i discovered that you are correct; Java Script.

Okay, you can probably ignore most of the advice you've received here
(e.g. "class" is a concept which only exists in Java, and not in
JavaScript). Probably best if you repost your question at a JavaScript
newsgroup like comp.lang.javascript.

- Oliver

Thanks!
Apr 6 '06 #18

This discussion thread is closed

Replies have been disabled for this discussion.