Java中的整数和数组 - 如何? [英] integers and arrays in Java - how?

查看:40
本文介绍了Java中的整数和数组 - 如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Google并在Java中找到了一些整数引用。

但是int不仅不起作用,它还可以防止读取鼠标的X和Y

坐标。

我想做什么:

1 )将X和Y鼠标坐标放入一个我可以进行实际数学运算的变量。

到目前为止,我可以对值read进行数学运算。结果进入

a变量这是有用的*仅*用于显示。

如果我尝试int在那个数学中,所有值的值都为零

- 即使我没有计算的那些。

2)使用计算的整数值作为表的索引或数组。

使用HTML表格是可以接受的。作为查找的来源;

W(CalcFromX)和P(CalcFromX)将在屏幕上显示的结果值为




可以这样做,并且eXactly如何?

解决方案



Robert Baer写道:< blockquote class =post_quotes>我使用Google并在Java中找到了一些整数引用。


这个新闻组是关于JavaScript,而不是Java。这两个比汽车和地毯更常见。

但是int不仅不起作用,它还可以防止读取鼠标的X和Y
坐标。




您是如何尝试读取坐标的?这听起来像是你想要使用Java文档编写JavaScript。认识到语言之间的区别,你应该会发现更容易找到你需要的文件。


-

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


Robert Baer写道:

我使用Google并在Java中找到了一些整数引用。


JavaScript不是Java。

但是int不仅不起作用,它还可以防止读取鼠标的X和Y
坐标。


JavaScript中没有''int''类型。变量是无类型的,它们的值

有类型。通过访问鼠标事件的属性

来完成读取鼠标坐标。您可以在Quirksmode上阅读有关活动的信息:


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


我想做什么:
1)将X和Y鼠标坐标放入一个我可以做真正数学的变量上。


如果您正在寻找鼠标点击的坐标,请尝试使用

Quirksmode:


函数doSomething(e)

{

var posx = 0;

var posy = 0;

if (!e)var e = window.event;


//符合W3C标准的浏览器

if(e.pageX || e.pageY){

posx = e.pageX;

posy = e.pageY;


// MS IE兼容版本

} else if(e.clientX || e.clientY){

posx = e.clientX + document.body.scrollLeft;

posy = e.clientY + document.body.scrollTop;

}

// posx和posy包含相对于文档的鼠标位置

//用这个做点什么信息

}

通过正文点击事件调用它:


< body onclick =" doSomething(event); >


到目前为止,我可以对值read进行数学运算。并且结果进入了一个变量的变量。这对* *仅用于显示。
如果我尝试int在那个数学中,所有值的值都为零 -
即使是那些我不做计算的人。


如果没有看到代码,就无法说出发生了什么。


2)使用计算的整数值作为索引表格或数组。
使用HTML表格是可以接受的。作为查找的来源;
W(CalcFromX)和P(CalcFromX)将是在屏幕上显示的结果值。

可以这样做,和eXactly如何?




< title>点击coords< / title>

< style type =" text / css"> ;

#xx {宽度:100%;身高:100%;}

< / style>


< script type =" text / javascript">


函数clickCoords(e)

{

var coords = {x:0,y:0};


if(e.pageX || e.pageY){

coords = {x:e.pageX,y:e.pageY};

}否则if (e.clientX || e.clientY){

coords = {x:e.clientX + document.body.scrollLeft,

y:e.clientY + document.body .scrollTop};

}

返回坐标;

}


函数showClickXY(e)

{

var e = e || window.event

var coords = clickCoords(e);

document.getElementById(''xx'')。innerHTML = coords.x +'',''+ coords.y;

}


< / script>

< body onclick =" showClickXY(event); ">


< div>点击坐标:< span id =" xx">< / span>< / div>

< / body>

在上面的示例中,鼠标单击的坐标被传递给名为''coords''的

对象,其属性为x和y其值设置为鼠标点击的

位置。

-

Rob

RobG写道:

Robert Baer写道:

但是int不仅不起作用,它还可以防止读取鼠标的X和Y
坐标。



JavaScript中没有''int''类型。变量是无类型的,它们的值有类型。




不太正确。在JavaScript 2.0中有一个int类型,变量可以是严格的

类型。但是,这还没有在浏览器中实现



PointedEars


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?

解决方案


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/


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

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.scrollLeft;
posy = e.clientY + document.body.scrollTop;
}
// 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="doSomething(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.scrollLeft,
y: e.clientY + document.body.scrollTop};
}
return coords;
}

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

</script>
<body onclick="showClickXY(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


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


这篇关于Java中的整数和数组 - 如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆