- modified World so that it contains a specific Canvas

deleted the canvas methods 
  made it abstract so that programmers _must_ override 
  the essential methods

svn: r502
This commit is contained in:
Matthias Felleisen 2005-07-30 16:52:06 +00:00
parent e8eeca4601
commit d844256e25
3 changed files with 42 additions and 113 deletions

View File

@ -35,6 +35,7 @@
(lower (cdr s))))))))
(list->string (lower (string->list s)))))
#|
(define/provide (start-int-int-native this accs gets privates x y)
(start x y))
@ -69,7 +70,8 @@
(define/provide (sleepForAWhile-int-native this accs gets privates s)
(sleep-for-a-while s))
|#
(define/provide (bigBang-double-native this accs gets privates i)
(big-bang i this)
(on-tick-event
@ -93,17 +95,19 @@
(define (keyevent->string ke)
(if (char? ke) (string ke) (symbol->string ke)))
#|
(define/provide (draw-native this accs gets privates)
#t)
(error 'draw "abstract method"))
(define/provide (erase-native this accs gets privates)
#t)
(error 'erase "abstract method"))
(define/provide (onTick-native this accs gets privates)
this)
(error 'onTick "abstract method"))
(define/provide (onKeyEvent-java.lang.String-native this accs gets privates ke)
this)
(error 'onKeyEvent "abstract method"))
|#
(define last-world #f)

View File

@ -1,44 +1,22 @@
package draw;
public class World {
public abstract class World {
public native boolean start(int width, int height);
Canvas theCanvas = new Canvas();
public native boolean stop();
public native boolean bigBang(double s);
public native boolean endOfTime();
public native World endOfWorld();
public native boolean drawCircle(Posn p, int r, Color c);
public native World lastWorld();
public native boolean drawDisk(Posn p, int r, Color c);
public abstract World onTick();
public native boolean drawRect(Posn p, int width, int height, Color c);
public abstract World onKeyEvent(String ke);
public native boolean drawLine(Posn p0, Posn p1, Color c);
public abstract boolean draw();
public native boolean drawString(Posn p, String s);
public native boolean clearCircle(Posn p, int r, Color c);
public native boolean clearDisk(Posn p, int r, Color c);
public native boolean clearRect(Posn p, int width, int height, Color c);
public native boolean clearLine(Posn p0, Posn p1, Color c);
// public native boolean sleepForAWhile(int s);
public native boolean bigBang(double s);
public native World onTick();
public native World onKeyEvent(String ke);
public native boolean draw();
public native boolean erase();
public native boolean endOfTime();
public native World endOfWorld();
public native World lastWorld();
public abstract boolean erase();
}

View File

@ -1,7 +1,6 @@
This `draw' package provides libraries for modeling in a visual world. It
consists of two sets of classes:
- World
+----------+ +----------+
| World | +->| Canvas |
@ -11,70 +10,18 @@ consists of two sets of classes:
+----------+ | clear |
+----------+
// start the clock and make this world the current one
boolean bigBang(double s)
- abstract class World
// process a tick of the clock in this world
World onTick()
- class Canvas
// process a keystroke event in this world
World onKeyEvent(String ke)
- class Posn
// 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
boolean start(int width, int height)
// tear down the canvas and shut down the program
boolean stop()
// draw a circle at p, paint circle c
boolean drawCircle(Posn p, int r, Color c)
// draw a solid disk at p, fill with color c
boolean drawDisk(Posn p, int r, Color c)
// draw a width x height rectangle at p, fill with color c
boolean drawRect(Posn p, int width, int height, Color c)
// draw a line from p0 to p1, use color c
boolean drawLine(Posn p0, Posn p1, Color c)
// draw a string at position p
boolean drawString(Posn p, String s)
// clear a circle at p, paint circle c
boolean clearCircle(Posn p, int r, Color c)
// clear a solid disk at p, fill with color c
boolean clearDisk(Posn p, int r, Color c)
// clear a width x height rectangle at p, fill with color c
boolean clearRect(Posn p, int width, int height, Color c)
// clear a line from p0 to p1, use color c
boolean clearLine(Posn p0, Posn p1, Color c)
- Posn
+----------+
| Posn |
+----------+
| int x |
| int y |
+----------+
+----------+
| Posn |
+----------+
| int x |
| int y |
+----------+
- Color with five subclasses:
+ Blue
@ -83,16 +30,16 @@ consists of two sets of classes:
+ White
+ Yellow
+-------+
| Color |
+-------+
|
/ \
---
|
------------------------------------------
| | | | |
+-------+ +-------+ +-------+ +-------+ +-------+
| Blue | | Green | | Red | | White | | Yellow|
+-------+ +-------+ +-------+ +-------+ +-------+
+-------+
| Color |
+-------+
|
/ \
---
|
------------------------------------------
| | | | |
+-------+ +-------+ +-------+ +-------+ +-------+
| Blue | | Green | | Red | | White | | Yellow|
+-------+ +-------+ +-------+ +-------+ +-------+