- created a Canvas class and implementation

so that world can become an abstract class 
  (well, we will pretend it is one; I have 
  to ask Kathy how to do this)
 

svn: r497
This commit is contained in:
Matthias Felleisen 2005-07-30 02:11:50 +00:00
parent 5bb5c7aee7
commit c9046e4e44
3 changed files with 55 additions and 43 deletions

View File

@ -24,7 +24,7 @@ public class World {
public native boolean clearLine(Posn p0, Posn p1, Color c); public native boolean clearLine(Posn p0, Posn p1, Color c);
public native boolean sleepForAWhile(int s); // public native boolean sleepForAWhile(int s);
public native boolean bigBang(double s); public native boolean bigBang(double s);

View File

@ -1,29 +1,38 @@
This `draw' package provides libraries for modeling in a visual world. It This `draw' package provides libraries for modeling in a visual world. It
consists of two sets of classes: consists of two sets of classes:
- World and Posn - World
- Color with five subclasses: +----------+ +----------+
+ Blue | World | +->| Canvas |
+ Green +----------+ | +----------+
+ Red | Canvas c |--+ +----------+
+ White +----------+ | draw |
+ Yellow +----------+ | clear |
+----------+
+-------+ // start the clock and make this world the current one
| Color | boolean bigBang(double s)
+-------+
/ \
---
|
------------------------------------------
| | | | |
+-------+ +-------+ +-------+ +-------+ +-------+
| Blue | | Green | | Red | | White | | Yellow|
+-------+ +-------+ +-------+ +-------+ +-------+
// process a tick of the clock in this world
World onTick()
The _World_ class has the following class interface: // process a keystroke event in this world
World onKeyEvent(String ke)
// stop this world's clock
World endOfWorld()
// draw this world
boolean draw()
// erase this world
boolean erase()
// view the last World that onTick or onKeyEvent or bigBang created
World lastWorld()
- Canvas
// create the visual aspect // create the visual aspect
boolean start(int width, int height) boolean start(int width, int height)
@ -58,29 +67,32 @@ The _World_ class has the following class interface:
// clear a line from p0 to p1, use color c // clear a line from p0 to p1, use color c
boolean clearLine(Posn p0, Posn p1, Color c) boolean clearLine(Posn p0, Posn p1, Color c)
// wait for s seconds (roughly) - Posn
boolean sleepForAWhile(int s)
// start the clock and make this world the current one +----------+
boolean bigBang(double s) | Posn |
+----------+
| int x |
| int y |
+----------+
// process a tick of the clock in this world - Color with five subclasses:
World onTick() + Blue
+ Green
+ Red
+ White
+ Yellow
// process a keystroke event in this world +-------+
World onKeyEvent(String ke) | Color |
+-------+
|
/ \
---
|
------------------------------------------
| | | | |
+-------+ +-------+ +-------+ +-------+ +-------+
| Blue | | Green | | Red | | White | | Yellow|
+-------+ +-------+ +-------+ +-------+ +-------+
// stop this world's clock
World endOfWorld()
// draw this world
boolean draw()
// erase this world
boolean erase()
// view the last World that onTick or onKeyEvent or bigBang created
World lastWorld()
_Posn_ is the usual class: it combines two integers, x and y, and makes the
available via the selectors Posn.x and Posn.y.

View File

@ -16,7 +16,7 @@
#f #f))))) #f #f)))))
(javac "Posn.java") (javac "Posn.java")
(javac "Color.java") (javac "Color.java")
; (javac "ICanvas.java") (javac "Canvas.java")
(javac "World.java") (javac "World.java")
(javac "Red.java") (javac "Red.java")
(javac "White.java") (javac "White.java")