0

我可以将光标从系统更改为一个,但无法显示我创建的光标,而且我完全不知道我做错了什么,它不会给我任何异常。这是我的代码:

class CustomWin extends MainFrame{

title = "SdC2 Launcher"
cursor = defineCursor
iconImage = defineIcon
visible = true

contents = new BoxPanel(Orientation.Vertical){
  contents += new Label("Label de prueba")
  contents += new Label("Label de prueba")
  val lab = new Label("Label de prueba")
  lab cursor = defineCursor
  contents += lab
}

preferredSize = new Dimension(300,300)
centerOnScreen
pack
open

private val defineCursor = {
  val hotspot = new Point(0, 0)
   //val image = ImageIO.read(new File("images/cursor.png"))
  val image = new ImageIcon("/images/cursor2.gif")
  toolkit.createCustomCursor(image.getImage(), hotspot, "MainCursor")
}

private val defineIcon: Image = new ImageIcon(getClass().getResource("/images/cursor.png")).getImage()
}
4

1 回答 1

1

我怀疑您遇到了初始化顺序问题。即,在您调用cursor = defineCursorandlab cursor = defineCursor时,defineCursor仍然是nullval您应该在构造函数代码中使用它们的位置之前初始化s。

于 2013-09-07T15:06:00.903 回答