[Newbies] Keyboard input - programming course

Bert Freudenberg bert at freudenbergs.de
Mon Jul 4 11:01:45 UTC 2011


On 04.07.2011, at 09:45, Stephen Woolerton wrote:

> Hi all,
> 
> We wish to use Squeak/Smalltalk for a beginner programming course and require the simplest way to get keyboard input.
> 
> First of all:-
> - is there a way in Squeak to get console input (analogous to system.in, in Java)? Line input would be ideal, rather than character by character.

There is a way, but it is complicated, platform-dependent, and very rarely used. Squeak provides its own user interface, the command line interface is only used for e.g. server apps.

> - how would one display a text label and a text field and obtain input from the text field (am thinking of Morphic)

	name := UIManager default request: 'Enter your name'.
	Transcript show: name; cr.

However, IMHO this is *not* the best way to introduce Squeak programming to beginners. It mimics procedural programming in a console.

Instead, just open a Workspace and begin evaluating expressions. There doesn't have to be a "program". In fact, there is no "main". Just send messages to objects. 

	3 + 4
	1234 / 56
	100 factorial
	'foo bar' asUppercase 

Then, make a Morph and send it messages. Evaluate each line individually to see its effect.

	joe := Morph new.
	joe openInWorld.
	joe position: 100 at 100.
	joe color: Color red.

From there I'd continue with inspectors and explorers. Squeak by Example is an excellent source for further exploration:

	http://squeakbyexample.org/

- Bert -




More information about the Beginners mailing list