getting around the null problem with a silly canvas for World

svn: r7093
This commit is contained in:
Matthias Felleisen 2007-08-13 23:52:23 +00:00
parent 377b8b17e1
commit a811f769d7
3 changed files with 45 additions and 1 deletions

View File

@ -0,0 +1,43 @@
package draw;
import geometry.*;
import colors.*;
public class SillyCanvas extends Canvas {
private int x = 20;
private int y = 20;
private boolean warning() {
return super.drawString(new Posn(x,y),"This is a Dummy Canvas.");
}
SillyCanvas(int w, int h) {
super(w,h);
if ((w < x) || (h < y))
throw new RuntimeException("SillyCanvas: bad size");
}
public boolean drawCircle(Posn p, int r, AColor c) {
return super.drawCircle(p,r,c) && warning();
}
public boolean drawDisk(Posn p, int r, AColor c) {
return super.drawDisk(p,r,c) && warning();
}
public boolean drawRect(Posn p, int width, int height, AColor c) {
return super.drawRect(p,width,height,c) && warning();
}
public boolean drawLine(Posn p0, Posn p1, AColor c) {
return super.drawLine(p0,p1,c) && warning();
}
public boolean drawString(Posn p, String s) {
return super.drawString(p,s) && warning();
}
public boolean show() {
return super.show() && warning();
}
}

View File

@ -1,7 +1,7 @@
package draw;
public abstract class World {
protected Canvas theCanvas = null; // can I do better here?
protected Canvas theCanvas = new SillyCanvas(600,600); // can I do better here?
/**
*@author Matthias Felleisen, Kathy Gray

View File

@ -19,5 +19,6 @@
(build-path draw-path file)
#f #f)))))
(javac "Canvas.java")
(javac "SillyCanvas.java")
(javac "World.java")))))