given two integer variables 'a' and 'b' in a rectangle class, how do you draw a rectangle? I'm new to smalltalk and im studying it for a course. thanks!
相关问题
- Simple class definition error in smalltalk
- Which Smalltalk object should be passed to a C fun
- Squeak(smalltalk) subSrings ignores empty strings
- Smalltalk variables: why should I declare them?
- How to manage 2d array in Smalltalk?
相关文章
- Implementation Strategies for Object Orientation
- What is the difference between Seaside programmmin
- How to copy several Monticello commits from local
- Smalltalk ReferenceStream has problems with new in
- Is it possible to write shell command within Pharo
- Draw table in Pharo
- Double dispatch in Pharo
- How can I get all the methods in a Protocol?
Squeak uses Morphic as its default UI. So the simplest thing would be to create a Morph:
Evaluate all three lines at once. This creates a new
RectangleMorph
instance, sets its extent to aPoint
created from300
and200
(by sending the message@
to300
with an argument of200
), and also sends it theopenInWorld
message so it appears in the world. It will open in the top-left screen corner. We could have sent it theposition:
message with anotherPoint
argument, but you can as easily just grab it with your mouse pointer and move it anywhere you please.In your class you might use
a@b
to create the extent point (assuminga
andb
are the rectangle's width and height in pixels).Morphic is nice because it creates real objects that you can manipulate interactively, e.g. by cmd-clicking to bring up a Halo. If you don't want that, you can also paint on the screen directly. E.g.:
... where
Display
is a global Form instance (containing a Bitmap) refering to the whole Squeak display. But since that expression just puts pixels on the screen, they will be overwritten quickly. Morphs, in contrast, know how to redraw themselves whenever needed.It's also possible to create your own Morph subclass and implement a custom
drawOn:
method. But that would be overkill for something as simple as showing a rectangle.