smalltalk中图像上的鼠标事件

时间:2016-06-02 11:48:34

标签: smalltalk squeak

我在小谈中有以下课程

Object subclass: #SnookerBall
    instanceVariableNames: 'image type position'
    classVariableNames: ''
    poolDictionaries: ''
    category: 'mmn16'

initialize
    self initialize.
    image := ImageMorph new image: (Form fromFileNamed: 'ball_1.gif').
    image position:100@100.

现在我想在图像上实现鼠标事件。 基本上我需要模拟一个斯诺克球。 所以我需要鼠标事件(点击,拖动等)并让它看起来像动画。

请帮忙 先谢谢你了

好的我已经编辑了一个SnookerBall类

ImageMorph subclass: #SnookerBall
    instanceVariableNames: ''
    classVariableNames: ''
    poolDictionaries: ''
    category: 'Snooker'

并初始化方法

initialize
    self image: (Form fromFileNamed: 'ball_1.gif');
    extent:40@40;
    position:0@0.

我试图执行:

b:=SnookerBall new.
b openInWorld.

我有一个错误:MessageNotUnderstood:UndefinedObject>> hasPositiveExtent

请帮助

1 个答案:

答案 0 :(得分:2)

您可以尝试Morph>>on:send:to:

SnookerBall>>
initialize
    "..."
    image on: #click send: #ballClicked to: self

ballClicked
    "pop up a modal dialog"
    self inform: 'Ball was clicked'

...在单击ImageMorph时调用SnookerBall对象上的ballClicked

查看EventHandler>>on:send:to:以查看on的可能参数:#mouseDown,#mouseMove,#click,...

如果您需要为生成的消息提供参数,请考虑Morph>>on:send:to:withValue: