svn: r9447

This commit is contained in:
Matthias Felleisen 2008-04-24 02:16:40 +00:00
parent 65467c8483
commit 538e960133
3 changed files with 70 additions and 69 deletions

View File

@ -2,7 +2,7 @@
@(require scribble/manual) @(require scribble/manual)
@title[#:tag "draw"]{Draw: draw.*} @title[#:tag "Jdraw"]{Draw: draw.*}
Add Add
@verbatim[#:indent 3]{ @verbatim[#:indent 3]{
@ -18,61 +18,74 @@ import geometry.*;
+-----------------------------------+ +-----------------------------------+
| abstract World | | abstract World |
+-----------------------------------+ +---------------------------------------+ +-----------------------------------+
| Canvas theCanvas |------>| Canvas | | Canvas theCanvas |----+
+-----------------------------------+ +---------------------------------------+ +-----------------------------------+ |
| boolean bigBang(int,int,double) | +---------------------------------------+ | boolean bigBang(int,int,double) | |
| boolean endOfTime(String) | | boolean show() | | boolean endOfTime(String) | |
| World endOfWorld(String) | | boolean close() | | World endOfWorld(String) | |
| | | boolean drawCircle(Posn,int,IColor) | | | |
| | | boolean drawDisk(Posn,int,IColor) | | | |
| abstract World onTick() | | boolean drawRect(Posn,int,int,IColor) | | abstract World onTick() | |
| abstract World onKeyEvent(String) | | boolean drawLine(Posn,Posn,IColor) | | abstract World onKeyEvent(String) | |
| abstract boolean draw() | | boolean drawString(Posn,String) | | abstract boolean draw() | |
+-----------------------------------+ +---------------------------------------+ +-----------------------------------+ |
} |
v
+---------------------------------------+
| Canvas |
+---------------------------------------+
+---------------------------------------+
| boolean show() |
| boolean close() |
| boolean drawCircle(Posn,int,IColor) |
| boolean drawDisk(Posn,int,IColor) |
| boolean drawRect(Posn,int,int,IColor) |
| boolean drawLine(Posn,Posn,IColor) |
| boolean drawString(Posn,String) |
+---------------------------------------+}
Methods in these classes may fail due to the unavailability of the physical Methods in these classes may fail due to the unavailability of the physical
devices, inappropriate uses, etc. In those cases, they fail with an devices, inappropriate uses, etc. In those cases, they fail with an
exception. exception.
@section[#:tag "world"]{World} @section[#:tag "Jworld"]{World}
The abstract @scheme[World] class exports the following methods. The abstract @tt{World} class exports the following methods.
@; ----------------------------------------------------------------------------- @; -----------------------------------------------------------------------------
bigBang(int width,int height,double speed) bigBang(int width,int height,double speed)
Initializes the world, associates it with a @scheme[width] x Initializes the world, associates it with a @tt{width} x
@scheme[height] <a href="#canvas">@scheme[Canvas]</a>, displays @tt{height} <a href="#canvas">@tt{Canvas}</a>, displays
this canvas, enables keyevents, and finally starts the clock at a rate of this canvas, enables keyevents, and finally starts the clock at a rate of
one tick per @scheme[speed] seconds. If it succeeds with all of its one tick per @tt{speed} seconds. If it succeeds with all of its
actions, the method produces @scheme[true]. actions, the method produces @tt{true}.
@bold{Note}: @scheme[width], @scheme[height] and @bold{Note}: @tt{width}, @tt{height} and
@scheme[speed] must be a positive. @tt{speed} must be a positive.
@; ----------------------------------------------------------------------------- @; -----------------------------------------------------------------------------
The canvas in @scheme[World] is called The canvas in @tt{World} is called
@scheme[theCanvas]. @tt{theCanvas}.
References to a "canvas" in conjunction with the @scheme[World] class References to a "canvas" in conjunction with the @tt{World} class
denote this default canvas. denote this default canvas.
@; ----------------------------------------------------------------------------- @; -----------------------------------------------------------------------------
endOfTime() endOfTime()
Displays the given message, stops the clock and, if it succeeds, produces Displays the given message, stops the clock and, if it succeeds, produces
@scheme[true]. After the end of time, events no longer trigger calls @tt{true}. After the end of time, events no longer trigger calls
to @scheme[onTick] or @scheme[onKeyEvent]. The canvas remains visible. to @tt{onTick} or @tt{onKeyEvent}. The canvas remains visible.
@; ----------------------------------------------------------------------------- @; -----------------------------------------------------------------------------
endOfWorld(String msg) endOfWorld(String msg)
Displays the given message, stops the clock and, if it succeeds, produces the Displays the given message, stops the clock and, if it succeeds, produces the
last @scheme[World]. After the end of the world, events no longer trigger calls last @tt{World}. After the end of the world, events no longer trigger calls
to @scheme[onTick] or @scheme[onKeyEvent] (see below). The canvas to @tt{onTick} or @tt{onKeyEvent} (see below). The canvas
remains visible. remains visible.
@; ----------------------------------------------------------------------------- @; -----------------------------------------------------------------------------
@ -82,79 +95,78 @@ A derived concrete class must supply definitions for the following methods:
onTick() onTick()
Invoked for every tick of the clock. Its purpose is to create a Invoked for every tick of the clock. Its purpose is to create a
@scheme[World] whose differences with @scheme[this] one represent @tt{World} whose differences with @tt{this} one represent
what happened during the amount of time it takes the clock to tick. what happened during the amount of time it takes the clock to tick.
@; ----------------------------------------------------------------------------- @; -----------------------------------------------------------------------------
onKeyEvent(String key) onKeyEvent(String key)
Invoked for every keyboard event associated with the canvas. Its purposes Invoked for every keyboard event associated with the canvas. Its purposes
is to create a @scheme[World] whose differences with is to create a @tt{World} whose differences with
@scheme[this] one represent what happens due to the user's use of the @tt{this} one represent what happens due to the user's use of the
keyboard. The latter is represented with the string-valued argument keyboard. The latter is represented with the string-valued argument
@scheme[key]. @tt{key}.
@; ----------------------------------------------------------------------------- @; -----------------------------------------------------------------------------
draw() draw()
Invoked <em>after</em> one of the two event handlers has been called. Its Invoked <em>after</em> one of the two event handlers has been called. Its
purpose is to present @scheme[this World ] graphically on its purpose is to present @tt{this World} graphically on its
canvas. If it succeeds, its result is @scheme[true.] canvas. If it succeeds, its result is @tt{true}.
A program may, in principle, start several instances of (subclasses of) A program may, in principle, start several instances of (subclasses of)
@scheme[World]. If it does, the event handlers are called in a unpredictable @tt{World}. If it does, the event handlers are called in a unpredictable
order. order.
@section[#:tag "canvas"]{Canvas} @section[#:tag "canvas"]{Canvas}
To create an instance of the @scheme[Canvas] class, a program must supply To create an instance of the @tt{Canvas} class, a program must supply
two @scheme[int] values: one for the width of the canvas and one for its two @tt{int} values: one for the width of the canvas and one for its
height. The canvas is a rectangle, whose borders are parallel to the computer height. The canvas is a rectangle, whose borders are parallel to the computer
screen's borders. A program can use the following methods on instances of screen's borders. A program can use the following methods on instances of
@scheme[Canvas:] @tt{Canvas}]
show() show()
Initializes the canvas to a white area, enables the drawing methods, and Initializes the canvas to a white area, enables the drawing methods, and
finally displays the canvas. If it succeeds, it produces finally displays the canvas. If it succeeds, it produces
@scheme[true]. Invoking the method a second time without calling @tt{true}. Invoking the method a second time without calling
@scheme[close] before has no effect. @tt{close} before has no effect.
close() close()
Hides the canvas and erases the current content. If it succeeds, it Hides the canvas and erases the current content. If it succeeds, it
produces @scheme[true]. produces @tt{true}.
Closing the Canvas using the display controls does not fully hide the Closing the Canvas using the display controls does not fully hide the
canvas; it is still necessary to invoke @scheme[close] before canvas; it is still necessary to invoke @tt{close} before
@scheme[show] is re-enabled. @tt{show} is re-enabled.
drawCircle(Posn p,int r,IColor c)> drawCircle(Posn p,int r,IColor c)>
Draws a circle on @scheme[this Canvas] at @scheme[p] with radius Draws a circle on @tt{this}Canvas] at @tt{p} with radius
@scheme[r] and color @scheme[c]. If it succeeds, it produces @tt{r} and color @tt{c}. If it succeeds, it produces
@scheme[true]. @tt{true}.
drawDisk(Posn p,int r,IColor c) drawDisk(Posn p,int r,IColor c)
Draws a disk on @scheme[this Canvas] at @scheme[p] with radius Draws a disk on @tt{this}Canvas] at @tt{p} with radius
@scheme[r] and color @scheme[c]. If it succeeds, it produces @tt{r} and color @tt{c}. If it succeeds, it produces
@scheme[true]. @tt{true}.
drawRect(Posn p,int w,int h,IColor c) drawRect(Posn p,int w,int h,IColor c)
Draws a solid rectangle on @scheme[this Canvas] at @scheme[p] with Draws a solid rectangle on @tt{this}Canvas] at @tt{p} with
width @scheme[w], height @scheme[h], and color @scheme[c]. The width @tt{w}, height @tt{h}, and color @tt{c}. The
rectangle's lines are parallel to the canvas's borders. If it succeeds, it rectangle's lines are parallel to the canvas's borders. If it succeeds, it
produces @scheme[true]. produces @tt{true}.
drawLine(Posn p0,Posn p1,IColor c) drawLine(Posn p0,Posn p1,IColor c)
Draws a line on @scheme[this Canvas] from @scheme[p0] to Draws a line on @tt{this}Canvas] from @tt{p0} to
@scheme[p1] using color @scheme[c]. If it succeeds, it produces @tt{p1} using color @tt{c}. If it succeeds, it produces
@scheme[true]. @tt{true}.
drawString(Posn p,String s) drawString(Posn p,String s)
Draws the string @scheme[s] at @scheme[p] on @scheme[this Draws the string @tt{s} at @tt{p} on @tt{this}Canvas]. If it succeeds, it produces @tt{true}.
Canvas]. If it succeeds, it produces @scheme[true].

View File

@ -1,11 +0,0 @@
<html>
<head>
<title>Teachpacks for How to Design Classes</title>
</head>
<body bgcolor="#ffffff" text="#000000" link="#009900" vlink="#007700" alink="#cc0000">
<h1>Teachpacks for "How to Design Classes"</h1>
<ul>
{ LIBLINKS ; libraries should be set before processing this file }</ul>
{(include "foot.tinc")}