5
嗯,简单的问题:我有一个单独的对象,它扩展了scala.swing.Panel
,我想通过简单的鼠标单击来响应它。但是......好吧,它不起作用。既然斯卡拉是这样一种新语言,为特定问题寻找信息并不容易。也许你可以帮助:斯卡拉在扩展面板中的摆动反应
import scala.swing._
import scala.swing.event._
import java.awt.{Graphics2D, Color}
object GamePanel extends Panel {
val map: TileMap = new TileMap(10, 10)({
(x, y) =>
if (x == y) new Wood
else if (x == 5) new Water
else new Grass
})
reactions += {
case MouseClicked(src, pt, mod, clicks, pops) => {
selectedTile = (pt.x/map.tw, pt.y/map.th)
println("Clicked")
repaint
}
}
var selectedTile = (0, 0)
override def paint(g: Graphics2D) = {
map.draw(g)
g.setColor(Color.red)
g.drawRect(selectedTile._1 - 1, selectedTile._2 - 1, 33, 33)
}
}
感谢收听。
非常感谢您的帮助! – 2010-11-06 09:30:54