473,394 Members | 1,073 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

integers and arrays in Java - how?

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
17 3558

"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
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
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
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
"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
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
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
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
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
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
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
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
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
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
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
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Elijah Bailey | last post by:
I have two char arrays of size k. I want to know which one is bigger (exactly like for instance I compare two ints/longs/etc.). What is the fastest way to do this? k <= 10 usually for my...
16
by: aruna | last post by:
Given a set of integers, how to write a program in C to sort these set of integers using C, given the following conditions a. Do not use arrays b. Do not use any comparison function like if/then...
15
by: Paul Morrison | last post by:
Hi all, I need to come up with some differences between arrays in Java and C, I have searched Google and so far all I have found is the following: Arrays in Java are reference types with...
3
by: John Bend | last post by:
Hello. Can anyone please suggest some good tutorial links where Java Vectors and Arrays are explained and compared? I'm a proficient programmer but fairly new to Java. Whilst I understand...
1
by: Rob Griffiths | last post by:
Can anyone explain to me the difference between an element type and a component type? In the java literature, arrays are said to have component types, whereas collections from the Collections...
36
by: Robert Baer | last post by:
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...
1
by: susheela s | last post by:
Hi, Im doing a multiplication of two large integers which are store in arrays(such as 2345 is in array as 2 in a, 3 in a and so on)like this im storing integers in two arrays.The logic i have used...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.