简体   繁体   English

如何在Smalltalk中创建一个窗口

[英]How to create a window in smalltalk

I am trying to make a window show up, but i keep getting a message not understood error. 我试图显示一个窗口,但我不断收到一条消息,消息无法理解。 The snippet: 片段:

Window new
  label: 'Hello';
  open

You can use this: 您可以使用此:

ScheduledWindow new
    label: 'Hello';
    open

Or to open larger: 或打开更大:

ScheduledWindow new
    label: 'Hello';
    openIn: (20@20 extent: 300@300)

I suspect, however, that this isn't what you really want to do since it's hard to work with a window that's built this way. 但是,我怀疑这不是您真正想要做的,因为使用这种方式构建的窗口很难使用。 Can you explain more about what you want to do? 您能否进一步说明您想做什么?

Ok, for a game like that you want to use a custom control. 好的,对于这样的游戏,您想要使用自定义控件。 You start by creating a subclass of View for your game and override the displayOn: method to display the view. 首先,为游戏创建View的子类,然后重写displayOn:方法以显示视图。 You can add the view to the UIPainter canvas using a ViewHolder. 您可以使用ViewHolder将视图添加到UIPainter画布。 Set the View: property to be the name of a method that returns your custom view. 将View:属性设置为返回您的自定义视图的方法的名称。

To intercept mouse clicks, you'll need to have a custom controller for your view. 要拦截鼠标单击,您需要为视图使用自定义控制器。 You'll subclass Controller or one of its subclasses to create the Controller. 您将继承Controller或其子类之一以创建Controller。 A method called defaultControllerClass in the View returns the name of the controller class. 视图中称为defaultControllerClass的方法返回控制器类的名称。 In the controller, you can intercept mouse events. 在控制器中,您可以拦截鼠标事件。

I suggest that you load an example game to get you started. 我建议您加载一个示例游戏以入门。 Open the Parcel Manager, and select Toys from the list. 打开包裹管理器,然后从列表中选择玩具。 You should see SpiderSolitaire there. 您应该在那里看到SpiderSolitaire。 This is a game written for VisualWorks that displays a custom view, does some simple animation on that view, and intercepts mouse events. 这是为VisualWorks编写的游戏,它显示一个自定义视图,在该视图上做一些简单的动画,并拦截鼠标事件。 That should serve as a good example to use. 那应该是一个很好的例子。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM