473,698 Members | 2,361 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
36 2070
VK 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
coordinate s of the mouse.

OK, you'll be helped if you promise _stop_ calling JavaScript as "Java"
or "Java Script". You don't say "Linux" while talking about Windows, do
you? And you don't say that your browser is called "Inter Net
Ex-Plorer", do you? ** I do not use ImpossiblyExasp erator; i *ripped* it out of my OS
kicking and screeming.

So: the language you are trying to use is called JavaScript - 10
characters without space. The variant of this language implemented in
Internet Explorer is called JScript - 7 characters without space.
Collectively it is reffered as "JavaScript/JScript programming". To
save time and space it is often said just "script": "my script doesn't
work" etc. - if it is clear by context what your are talking about
JavaScript/JScript programming. ** Well, that results in the question as to what "variant" will work
with the most browsers - and where i get programming inf concerning that
variant.
Yes, my script has problems - in fact, part of it that did work now
refuses to work, and i did not change it.


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

You cannot do real math without using additional libraries and highly
resource expensive algorithms. In the normal circumstances you are
limited by machine math which may be identical, close or far away from
the real math - depending on values and operations. This is true for
JavaScript (10 chars no space - remember? ;-) as well as for Java, C,
C++, C# and any other language for PC (Personal Computer). See for
instance:-
<http://www.jibbering.c om/faq/#FAQ4_6> and
<http://www.jibbering.c om/faq/#FAQ4_7>

The code you posted is adjusted for NN4.x (1998-99) Empires raised and
falled since then :-)

Here is the HTML Strict compliant code for current generation of
browsers. Now if you tell what kind of math do you want to do with
mouse coords, one could suggest a proper way.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN"
"http://www.w3.org/TR/html401/strict.dtd">
<html>
<head>
<title>test 024</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<style type="text/css">
html {
margin: 0px 0px;
padding: 0px 0px}

body {
margin: 10px 10px;
padding: 0px 0px;
font: 1em Verdana, sans-serif;
color: #000000;
background-color: #FFFFFF}

form {
margin: 10px 10px;
padding: 5px 5px;
border: thin outset;
background-color: #EEEEEE}

form fieldset {
margin: 10px 10px;
padding: 10px 10px}

form fieldset legend {
margin: 0px 0px;
padding: 5px 5px;
cursor: default;
font-weight: bold}

form fieldset label {
float: left;
clear: left;
width: 20ex;
margin: 5px 0px;
padding: 0px 0px;
text-align: right}

form fieldset label:first-letter {
text-decoration: underline}

form fieldset input {
float: left;
width: 20ex;
margin: 5px 0px;
padding: auto auto;
font: 1em Verdana, sans-serif}

form fieldset button {
float: left;
margin: auto 5px;
padding: auto auto;
font: 1em Verdana, sans-serif}

form fieldset button:first-letter {
text-decoration: underline}
</style>

<script type="text/javascript">
function init() {
if ('undefined' == typeof mmX) {
mmX = document.forms['frm01'].elements['mmX'];
mmY = document.forms['frm01'].elements['mmY'];
}
W3 = ('undefined' != typeof document.body.a ddEventListener );
IE = ('undefined' != typeof document.body.a ttachEvent);
}

function start() {
if (W3) {
document.body.a ddEventListener ('mousemove',sh owCoords,true);
}
else if (IE) {
document.body.a ttachEvent('onm ousemove',showC oords);
}
else {
/*NOP*/
}
}

function stop() {
if (W3) {
document.body.r emoveEventListe ner('mousemove' ,showCoords,tru e);
}
else if (IE) {
document.body.d etachEvent('onm ousemove',showC oords);
}
else {
/*NOP*/
}
}

function showCoords(evt) {
var e = evt || event;
mmX.value = e.clientX;
mmY.value = e.clientY;
}

window.onload = init;
</script>

</head>

<body>
<!-- Pretty-print is adjusted to the "phantom nodes" issue -->
<form name="frm01" method="post" action=""
><fieldset><leg end>Mouse Coords</legend
><label for="mmX">X Coord:</label
><input type="text" name="mmX" id="mmX"

accesskey="x">< br
><label for="mmY">Y Coord:</label
><input type="text" name="mmY" id="mmY"

accesskey="y"></fieldset
><fieldset><leg end>Controls</legend
><button type="button" accesskey="w"

onClick="start( )">Watch</button
><button type="button" accesskey="u"

onClick="stop() ">Unwatch</button></fieldset
</form>

</body>
</html>

Apr 6 '06 #31
Here is the code i have so far, with comments.
***
<html_would_sta rt_here_but_mod ified_for_sanit y>
<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="JavaS cript">
<!--
var isNav = (navigator.appN ame.indexOf("Ne tscape") !=-1);
function handlerMM(e){
Xmm = (isNav) ? e.pageX : event.clientX;
Ymm = (isNav) ? e.pageY : event.clientY;
document.dataho lder.mmX.value= ((Xmm-173)/6.8+1938);
document.dataho lder.mmY1.value =Ymm;
document.dataho lder.mmY2.value =Xmm;
document.dataho lder.mmZ.value= ((Xmm-173)/6.8+1938);
}
if (isNav) {
document.captur eEvents(Event.M OUSEMOVE);
}
document.onmous emove = handlerMM;
// -->
</SCRIPT>

<body>
<center>
<form name="dataholde r">
<table border=1>
<tr>
<td><i>Year(wid e)</i></td>
<td><input type="text" size=9 name="mmX" value="0"></td>
<td><i>Year(nar row)</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>Producti on 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.
How can anybody produce working code with that crap happening?
-->

<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 -->
<div style="position : absolute; height: 316px; width: 697px; top: 100px;
left: 20px; "
<style="heigh t: 316px; width: 697px; top: 100px; left: 20px; " >
<img src="Arkansas.g if" alt="" usemap="#AK" style="border-style:none" >
</div>

</body>
</html>
***
Please note the problem with the first 2 display boxes ceasing to
work, and tell me what the he77 is going on.
Once i have a (calculated) year, i would like to "look-up" two
"values" (from a table of some sort): number of wells, and production.
Now those "values" may not be strictly numeric - there is the
possibility of entries like "123,456!" or "83,331#" or "3,551" (no
quotes) and i would want to display or show them "as-is".
Since JavaScript is supposed to be typeless, i would assume that is
not a problem.
The array or table will have about 65 years worth of data.
Apr 6 '06 #32
Lee wrote:
Robert Baer said:

<td><input type="text" size=9 name="mmX" value="0"></td>
<td><i>Year(nar row)</i></td>
<td><input type="number" size=3.8 name="mmX" value="0"></td>
<td><i>Number of wells</i></td>

You've got two fields named "mmX". That's not going to work
the way you want. Give one of them a different name and
assign its value separately.

I will certainly try that; thanks.
However, that does not help explain why it used to work.
I wanted to show mmX in two places, and that is what *did* happen
until recently.
And that *certainly* does not explain why mmY does not work.
Apr 7 '06 #33
Robert Baer wrote:
Here is the code i have so far, with comments.
***
<html_would_sta rt_here_but_mod ified_for_sanit y>
<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="JavaS cript">
<!--
var isNav = (navigator.appN ame.indexOf("Ne tscape") !=-1);
function handlerMM(e){
Xmm = (isNav) ? e.pageX : event.clientX;
Ymm = (isNav) ? e.pageY : event.clientY;
document.dataho lder.mmX.value= ((Xmm-173)/6.8+1938);
document.dataho lder.mmY1.value =Ymm;
document.dataho lder.mmY2.value =Xmm;
document.dataho lder.mmZ.value= ((Xmm-173)/6.8+1938);
}
if (isNav) {
document.captur eEvents(Event.M OUSEMOVE);
}
document.onmous emove = handlerMM;
// -->
</SCRIPT>

<body>
<center>
<form name="dataholde r">
<table border=1>
<tr>
<td><i>Year(wid e)</i></td>
<td><input type="text" size=9 name="mmX" value="0"></td>
<td><i>Year(nar row)</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>Producti on 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.
How can anybody produce working code with that crap happening?
-->

<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 -->
<div style="position : absolute; height: 316px; width: 697px; top: 100px;
left: 20px; "
<style="heigh t: 316px; width: 697px; top: 100px; left: 20px; " >
<img src="Arkansas.g if" alt="" usemap="#AK" style="border-style:none" >
</div>

</body>
</html>
***
Please note the problem with the first 2 display boxes ceasing to
work, and tell me what the he77 is going on.
Once i have a (calculated) year, i would like to "look-up" two
"values" (from a table of some sort): number of wells, and production.
Now those "values" may not be strictly numeric - there is the
possibility of entries like "123,456!" or "83,331#" or "3,551" (no
quotes) and i would want to display or show them "as-is".
Since JavaScript is supposed to be typeless, i would assume that is
not a problem.
The array or table will have about 65 years worth of data.

Using Google to search for JavaScript, i found http://www.w3schools.com
which seems to give JavaScript help.
Looking in their JS Math, i found "Math Object Methods" with cryptic
numbers ?rating? FireFox, Netscape, and IE.
It appears that *none* of the "methods" work.

One would think that Google is giving bad information, and that site
does not cover JavaScript.
Apr 7 '06 #34
Robert Baer said on 07/04/2006 2:04 PM AEST:
[...]
Using Google to search for JavaScript, i found http://www.w3schools.com
which seems to give JavaScript help.
It offers tutorials on a variety of web technologies. Their stuff is OK
but don't treat it as authoritative. It has many eccentricities and is
plain wrong on some things. Use with caution.

Looking in their JS Math, i found "Math Object Methods" with cryptic
numbers ?rating? FireFox, Netscape, and IE.
The Math object is a native, built-in ECMAScript object. The numbers
for each browser provided by w3schools is the version that supported
that particular property/method.

It appears that *none* of the "methods" work.
As far as I know, they all work in modern browsers. Remember that they
are properties/methods of the Math object, so abs() is used thusly:

var x = -5;
alert( Math.abs(x) ); // shows '5'
Similarly for other methods.
One would think that Google is giving bad information, and that site
does not cover JavaScript.


Google is good. Some may agree with your opinion of w3schools, but they
might also be called cynics. ;-)
--
Rob
Group FAQ: <URL:http://www.jibbering.c om/FAQ>
Apr 7 '06 #35
RobG wrote:
Robert Baer said on 07/04/2006 2:04 PM AEST:
[...]
Using Google to search for JavaScript, i found http://www.w3schools.com
which seems to give JavaScript help.

It offers tutorials on a variety of web technologies. Their stuff is OK
but don't treat it as authoritative. It has many eccentricities and is
plain wrong on some things. Use with caution.

Looking in their JS Math, i found "Math Object Methods" with cryptic
numbers ?rating? FireFox, Netscape, and IE.

The Math object is a native, built-in ECMAScript object. The numbers
for each browser provided by w3schools is the version that supported
that particular property/method.

It appears that *none* of the "methods" work.

As far as I know, they all work in modern browsers. Remember that they
are properties/methods of the Math object, so abs() is used thusly:

var x = -5;
alert( Math.abs(x) ); // shows '5'
Similarly for other methods.
One would think that Google is giving bad information, and that site
does not cover JavaScript.

Google is good. Some may agree with your opinion of w3schools, but they
might also be called cynics. ;-)

Does that mean one cannot do a simple-minded y = abs(x) ?
Apr 8 '06 #36
Robert Baer said on 08/04/2006 4:49 PM AEST:
RobG wrote:
Robert Baer said on 07/04/2006 2:04 PM AEST: [...]
It appears that *none* of the "methods" work.


As far as I know, they all work in modern browsers. Remember that
they are properties/methods of the Math object, so abs() is used thusly:

var x = -5;
alert( Math.abs(x) ); // shows '5'
Similarly for other methods. [...]

Does that mean one cannot do a simple-minded y = abs(x) ?


Yes. abs is a method of the Maths object. If you have lots of Math
functions to call, you could use 'with' but it's use is generally
frowned upon because it obfuscates code, e.g.:

with (Math){
alert(
abs(-5) + '\n' +
sqrt(5) + '\n' +
pow(3,4)
);
}

--
Rob
Group FAQ: <URL:http://www.jibbering.c om/FAQ>
Apr 9 '06 #37

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 into longs and comparing, but then I face the high endian/low endian problem on some machines.
16
3382
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
6994
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 programmer. This is an 8 mark question in an old exam paper, so I am assuming there are
3
7065
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
8703
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
3580
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 is useful *only* for display. If i try "int" in that math, the values are then zero for everything...
1
4672
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 element.. // 123 is stored as no={1,2,3} public: large operator *(large& x){ // overload...
0
9157
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9027
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8861
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7725
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6518
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3046
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
3
2001
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.