小编Kwa*_*aku的帖子

在Pharo Smalltalk中向后迭代一个集合

我是Pharo的新手,我正在尝试迭代OrderedCollection,但是从最后开始.

例如:

| c |
c := OrderedCollection new.
c add: (1).
c add: (2).
c add: (3).
c do: [ :each | Transcript show: each ; cr ]
Run Code Online (Sandbox Code Playgroud)

结果却是1 2 3我想要的3 2 1.

是否有可能或者我必须使用其他类型的收藏?

smalltalk squeak pharo

8
推荐指数
1
解决办法
500
查看次数

Smalltalk 按钮事件处理

我是 Squeak Smalltalk 的新手。如何捕获按钮单击事件并在单击按钮时执行一些代码。

我尝试了这段代码,但它不起作用!

我创建了一个新的按钮类:

SimpleButtonMorph subclass: #ButtonTest
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'test'
Run Code Online (Sandbox Code Playgroud)

在这个类中我写了这个方法:

handleMouseDown: event
^ true.
Run Code Online (Sandbox Code Playgroud)

我想在另一个 Morph 中使用按钮,所以我创建了新的 Morph 类:

RectangleMorph subclass: #RectangleMorphTest
instanceVariableNames: 'textField button stringLabel mouseAction'
classVariableNames: ''
poolDictionaries: ''
category: 'test'
Run Code Online (Sandbox Code Playgroud)

在Initialize方法中,我在RectangleMorph中编写了buttonMorph,矩形Morph的初始化方法:

initialize  
super initialize.
self bounds: ((0@0) extent: (400@400)).
self color: Color gray.

textField := TextFieldMorph new. 
textField color: Color lightYellow.
textField contents: 'text'.
textField bounds: ((25@25) extent: (300@75)).

button := ButtonTest new.
button borderWidth: 2.
button bounds: ((150@150) …
Run Code Online (Sandbox Code Playgroud)

oop smalltalk squeak

6
推荐指数
1
解决办法
1307
查看次数

如何在网页中多次播放相同的音频文件?

我想在 HTML 中播放声音文件两次

 <!DOCTYPE html >
<html>
<header>
<script>

var snd = new Audio("hello.wav"); 
snd.play();

snd = new Audio("hello.wav");
snd.play();
</script>
</header>

<body>
hello
</body>

</html>
Run Code Online (Sandbox Code Playgroud)

不过只能播放一次。

注意:此处介绍播放文件一次使用 Javascript 播放音频?

回答后编辑

要确定重复次数,请使用

var noOfRepetitions = 3;

myAudio = new Audio('hello.wav');

myAudio.addEventListener('ended', function() {
            noOfRepetitions = noOfRepetitions-1;
            if (noOfRepetitions > 0) {
                this.currentTime = 0;
                this.play()};
}, false);

myAudio.play();
Run Code Online (Sandbox Code Playgroud)

html javascript audio dom-events

4
推荐指数
1
解决办法
1853
查看次数

如何从整数序列构造String实例?

我想从Unicode代码点创建一个测试字符串

像这样的东西

 65 asCharacter asString,
 66 asCharacter asString,
 67 asCharacter asString,
 65 asCharacter asString,
769 asCharacter asString
Run Code Online (Sandbox Code Playgroud)

要么

String with: 65 asCharacter
       with: 66 asCharacter
       with: 67 asCharacter
       with: 65 asCharacter
       with: 769 asCharacter
Run Code Online (Sandbox Code Playgroud)

这有效

我正在寻找一种方法将整数值数组转换为类String的实例.

#(65 66 67 65 769)
Run Code Online (Sandbox Code Playgroud)

有内置的方法吗?我正在寻找这样的答案在Smalltalk实现中测试Unicode支持的正确方法是什么?一个,但对于字符串.

string unicode smalltalk squeak pharo

4
推荐指数
1
解决办法
119
查看次数

标签 统计

smalltalk ×3

squeak ×3

pharo ×2

audio ×1

dom-events ×1

html ×1

javascript ×1

oop ×1

string ×1

unicode ×1