I'm developing a small program which shows the screen co-ordinates of the mouse pointer in real time, displaying the co-ordinates in the format: "[x;y]"
我正在開發一個小程序,它實時顯示鼠標指針的屏幕坐標,以下列格式顯示坐標:“[x; y]”
Here is a small piece of code which for some reason returns an Illegal forward reference error:
這是一小段代碼,由於某種原因返回了非法的前向引用錯誤:
while(1=1)
{
mouse = MouseInfo.getPointerInfo();
xy = mouse.getLocation();
int x1 = xy.x;
int y1 = xy.y;
String a = "["+x1+";"+y1+"]";
jlbl.setText(a);
}
'mouse' is a PointerInfo object and 'xy' is a Point object which have been declared and have their relevant packages imported. The line "jlbl.setText(""+a);" gives the error, where 'jlbl' is a jLabel declared by NetBeans automatically.
'mouse'是一個PointerInfo對象,'xy'是一個Point對象,它已被聲明並導入了相關的包。行“jlbl.setText(”“+ a);”給出錯誤,其中'jlbl'是NetBeans自動聲明的jLabel。
Any reson to why this is happening?
為什么會發生這種情況有什么共鳴?
Thanks so much to all in advance, I greatly appreciate it.
非常感謝所有人,我非常感謝。
1 个解决方案
#1
0
Promoting OP's comment to answer ...
促進OP的評論回答......
Ah, by replacing the "1=1" with a boolean variable initialised as "true" when the program starts and "false" before it ends fixed that problem. I've also updated my JDK and JRE to the new JDK6 Update 23 and seems to be working fine. A bug maybe?
啊,通過在程序啟動時用一個初始化為“true”的布爾變量替換“1 = 1”,在結束之前用“false”替換修復該問題。我還將我的JDK和JRE更新為新的JDK6 Update 23,似乎工作正常。可能有一個bug?