473,563 Members | 2,797 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
36 2033

Robert Baer wrote:
I used Google and found some references for integer in Java.
This newsgroup is about JavaScript, not Java. The two have little more
in common than cars and carpets.
But "int" not only does not work, it also prevents reading X and Y
coordinates of the mouse.


How are you trying to read the coordinates? It sounds like you are
trying to write JavaScript using Java documentation. Recognise the
distinction between the languages and you should find it much easier to
find the documentation you need.

--
David Dorward
http://dorward.me.uk/

Mar 30 '06 #2
Robert Baer wrote:
I used Google and found some references for integer in Java.
JavaScript is not Java.
But "int" not only does not work, it also prevents reading X and Y
coordinates of the mouse.
There is no 'int' type in JavaScript. Variables are typeless, their values
have types. Reading mouse co-ordinates is done by accessing the properties
of a mouse event. You can read about events at Quirksmode:

<URL:http://www.quirksmode. org/js/introevents.htm l>

What i would like to do:
1) Get X and Y mouse coordinates into a variable that i can do real math
on.
If you are looking for the co-ordinates of a mouse click, try this from
Quirksmode:

function doSomething(e)
{
var posx = 0;
var posy = 0;
if (!e) var e = window.event;

// W3C compliant browsers
if (e.pageX || e.pageY) {
posx = e.pageX;
posy = e.pageY;

// MS IE compliant version
} else if (e.clientX || e.clientY) {
posx = e.clientX + document.body.s crollLeft;
posy = e.clientY + document.body.s crollTop;
}
// posx and posy contain the mouse position relative to the document
// Do something with this information
}
Call it from a body click event:

<body onclick="doSome thing(event);">

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.
Without seeing the code, it is impossible to say what is going on.

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?


<title>Click coords</title>
<style type="text/css">
#xx {width: 100%; height: 100%;}
</style>

<script type="text/javascript">

function clickCoords(e)
{
var coords = {x:0, y:0};

if (e.pageX || e.pageY) {
coords = {x: e.pageX, y: e.pageY};
} else if (e.clientX || e.clientY) {
coords = {x: e.clientX + document.body.s crollLeft,
y: e.clientY + document.body.s crollTop};
}
return coords;
}

function showClickXY(e)
{
var e = e || window.event
var coords = clickCoords(e);
document.getEle mentById('xx'). innerHTML = coords.x + ', ' + coords.y;
}

</script>
<body onclick="showCl ickXY(event);">

<div>Click coords: <span id="xx"></span></div>
</body>
In the above example, the coordinates of the mouse click are passed to an
object called 'coords' with properties x and y whose values are set to the
location of the mouse click.
--
Rob
Mar 30 '06 #3
RobG wrote:
Robert Baer wrote:
But "int" not only does not work, it also prevents reading X and Y
coordinates of the mouse.


There is no 'int' type in JavaScript. Variables are typeless, their
values have types.


Not quite true. There is an `int' type, and variables can be strictly
typed, in JavaScript 2.0. However, that is not implemented in a browser
yet.
PointedEars
Mar 30 '06 #4
Thomas 'PointedEars' Lahn said the following on 3/30/2006 12:42 PM:
RobG wrote:
Robert Baer wrote:
But "int" not only does not work, it also prevents reading X and Y
coordinates of the mouse.

There is no 'int' type in JavaScript. Variables are typeless, their
values have types.


Not quite true. There is an `int' type, and variables can be strictly
typed, in JavaScript 2.0. However, that is not implemented in a browser
yet.


And as such, even mentioning it is useless other than a waste of
bandwidth and time for anybody who reads it.

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Mar 30 '06 #5
David Dorward wrote:
Robert Baer wrote:
I used Google and found some references for integer in Java.

This newsgroup is about JavaScript, not Java. The two have little more
in common than cars and carpets.

But "int" not only does not work, it also prevents reading X and Y
coordinates of the mouse.

How are you trying to read the coordinates? It sounds like you are
trying to write JavaScript using Java documentation. Recognise the
distinction between the languages and you should find it much easier to
find the documentation you need.

I am adding Java in HTML to do things that HTML apparently cannot do.
Will get the code i have been working with (in another OS on a
different drive) and post it.
Mar 31 '06 #6
RobG wrote:
Robert Baer wrote:
I used Google and found some references for integer in Java.

JavaScript is not Java.
But "int" not only does not work, it also prevents reading X and Y
coordinates of the mouse.

There is no 'int' type in JavaScript. Variables are typeless, their
values have types. Reading mouse co-ordinates is done by accessing the
properties of a mouse event. You can read about events at Quirksmode:

<URL:http://www.quirksmode. org/js/introevents.htm l>

What i would like to do:
1) Get X and Y mouse coordinates into a variable that i can do real
math on.

If you are looking for the co-ordinates of a mouse click, try this from
Quirksmode:

function doSomething(e)
{
var posx = 0;
var posy = 0;
if (!e) var e = window.event;

// W3C compliant browsers
if (e.pageX || e.pageY) {
posx = e.pageX;
posy = e.pageY;

// MS IE compliant version
} else if (e.clientX || e.clientY) {
posx = e.clientX + document.body.s crollLeft;
posy = e.clientY + document.body.s crollTop;
}
// posx and posy contain the mouse position relative to the document
// Do something with this information
}
Call it from a body click event:

<body onclick="doSome thing(event);">

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.

Without seeing the code, it is impossible to say what is going on.

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?

<title>Click coords</title>
<style type="text/css">
#xx {width: 100%; height: 100%;}
</style>

<script type="text/javascript">

function clickCoords(e)
{
var coords = {x:0, y:0};

if (e.pageX || e.pageY) {
coords = {x: e.pageX, y: e.pageY};
} else if (e.clientX || e.clientY) {
coords = {x: e.clientX + document.body.s crollLeft,
y: e.clientY + document.body.s crollTop};
}
return coords;
}

function showClickXY(e)
{
var e = e || window.event
var coords = clickCoords(e);
document.getEle mentById('xx'). innerHTML = coords.x + ', ' + coords.y;
}

</script>
<body onclick="showCl ickXY(event);">

<div>Click coords: <span id="xx"></span></div>
</body>
In the above example, the coordinates of the mouse click are passed to
an object called 'coords' with properties x and y whose values are set
to the location of the mouse click.

What you have given looks like it may be very useful; i had no idea
that different browsers would have to be treated differently.
I do know that there are webpages that are browser *hostile* (causes
them to hang and requires a power off reset); those &^%#$&#$ pages work
only with InfuriatingExas perator.
Can the Mafia be hired for a hit on M$?
Better yet, can a few good programmers be hired to make an OS like
Windows that accepts all the programs that WinQQ without the bloat and bugs?
The next task would be a decent bug-free browser that follows all of
the standards.
Mar 31 '06 #7
Thomas 'PointedEars' Lahn wrote:
RobG wrote:

Robert Baer wrote:
But "int" not only does not work, it also prevents reading X and Y
coordinate s of the mouse.


There is no 'int' type in JavaScript. Variables are typeless, their
values have types.

Not quite true. There is an `int' type, and variables can be strictly
typed, in JavaScript 2.0. However, that is not implemented in a browser
yet.
PointedEars

-->THAT<-- explains why "int" does not work, and possibly why it
kills the mouse coordinates.
Will get my HTML with Jave code from my othe OS and drive for posting.
Mar 31 '06 #8
Randy Webb wrote:
Thomas 'PointedEars' Lahn said the following on 3/30/2006 12:42 PM:
RobG wrote:
Robert Baer wrote:

But "int" not only does not work, it also prevents reading X and Y
coordinates of the mouse.

There is no 'int' type in JavaScript. Variables are typeless, their
values have types.

Not quite true. There is an `int' type, and variables can be strictly
typed, in JavaScript 2.0. However, that is not implemented in a browser
yet.

And as such, even mentioning it is useless other than a waste of
bandwidth and time for anybody who reads it.

Incorrect; the info explained why i had so much trouble.
Mar 31 '06 #9
Robert Baer said the following on 3/31/2006 6:28 AM:
Randy Webb wrote:
Thomas 'PointedEars' Lahn said the following on 3/30/2006 12:42 PM:
RobG wrote:

Robert Baer wrote:

> But "int" not only does not work, it also prevents reading X and
> Y coordinates of the mouse.

There is no 'int' type in JavaScript. Variables are typeless, their
values have types.
Not quite true. There is an `int' type, and variables can be strictly
typed, in JavaScript 2.0. However, that is not implemented in a browser
yet.

And as such, even mentioning it is useless other than a waste of
bandwidth and time for anybody who reads it.

Incorrect; the info explained why i had so much trouble.


You had trouble because you were using, or attempting to use, a feature
that is not part of the language. Not because of a feature that might be
in a future release of the language unless you were reading a draft copy
of JavaScript2.0 in which case you should have known it wasn't in use yet.

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Mar 31 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
885
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 application. I tried bcmp / a loop for comparison, but it seems they are very slow compared to comparing longs...Any ideas? I tried splitting the array...
16
3372
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 or switch-case c. you can use pointers only d. you cannot use any of the loops either.
15
6970
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 automatic allocation of memory. In C, arrays are groups of variables of the same type in adjacent memory. Allocation for dynamic arrays is handled by the...
3
7058
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 arrays I don't fully understand Vectors and when to use them. Many thanks.
1
8692
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 Framework are said to have an element type. http://java.sun.com/docs/books/jls/second_edition/html/arrays.doc.html
17
3572
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 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...
1
4665
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 is explained with code below, class large{ int no; //array is used to store the large number. Each digit of a the number is stored as an...
0
7665
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7583
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7642
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7950
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6255
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2082
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1200
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
924
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.