【发布时间】:2014-05-29 01:51:09
【问题描述】:
我最近买了一台新电脑,并将我的项目从旧电脑移到了新电脑。我对我的所有项目进行了编译,它们都运行良好,其中大多数仍然在我的新计算机上运行,但特别是一个项目不会显示我移动的自定义光标。我确保我将图片与项目一起移动只是为了排除这种情况。我重写了源以匹配我的新计算机上的新位置,但它仍然不会显示。它给了我错误信息:
Exception in thread "main" java.lang.IndexOutOfBoundsException: invalid hotSpot
at sun.awt.CustomCursor.<init>(Unknown Source)
at sun.awt.windows.WCustomCursor.<init>(Unknown Source)
at sun.awt.windows.WToolkit.createCustomCursor(Unknown Source)
at wtalfvn.Window.<init>(Window.java:32)
at wtalfvn.Main.main(Main.java:9)
我的旧电脑是 32 位的,我的新电脑是 64 位的,都在 Windows 7 上运行,我使用的是 eclipse Kepler,但是使用 Cursor 和 Toolkit 有关系吗?
这是我用来创建光标的代码
Image cursor = Toolkit.getDefaultToolkit().getImage("graphx/PNG/cursor.png");
Cursor c = Toolkit.getDefaultToolkit().createCustomCursor(cursor,new Point(this.getX(),this.getY()), "cursor");
this.setCursor(c);
编辑:这里是完整的代码,希望看到的人可以查看。
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Window extends JFrame{
Image ico= Toolkit.getDefaultToolkit().getImage("graphx/ico/icon.PNG");
TextBox tb=new TextBox();
public Window(){
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(800,600);
setVisible(true);
setFocusable(true);
getContentPane().setBackground(Color.BLACK);
setIconImage(ico);
setLocationRelativeTo(null);
setResizable(false);
setTitle("MYTITLE");
addKeyListener(new KeyAdapter(){
public void keyTyped(KeyEvent e) {
if (e.getKeyChar()==KeyEvent.VK_ESCAPE){
System.exit(0);
}
}
});
Image cursor = Toolkit.getDefaultToolkit().getImage( getClass().getResource("/graphx/PNG/cursor.png"));
Cursor c = Toolkit.getDefaultToolkit().createCustomCursor(cursor,new Point(this.getX(),this.getY()), "cursor");
setCursor(c);
}
}
【问题讨论】:
-
欢迎来到 Stack Overflow!考虑提供一个实际的runnable example that demonstrates your problem 将涉及更少的猜测工作和更好的响应
-
所有其他代码都可以正常工作,所以我决定不通过复制我的所有代码来打扰你们,只是为了找到罪魁祸首。窗口有效,自定义图标有效,除光标外一切正常。
-
问题是,我试图猜测
this.getX和this.getY的含义,对我来说,它们意味着组件位置,但这可能不是真的 -
我编辑了它,这样清楚一点吗?
-
是的,
getX和getY在这种情况下不适合用于光标的热点
标签: java eclipse mouse-cursor