canvas
procedure to create a panel for drawing on.
(define c (canvas 400 500)) |
There are several methods available for drawing on a canvas. They all require
that you use the "graphics context" of the canvas which you get using
(.bufferg$ c)
The graphical operations you can use are:
(define g (.bufferg$ c)) (.setColor g (color R G B)) (.drawLine g x1 y1 x2 y2) (.drawRect g x1 y1 w h) (.drawOval g x1 y1 w h) (.drawArc g x1 y1 w h a d) (.fillRect g x1 y1 w h) (.fillOval g x1 y1 w h) (.fillArc g x1 y1 w h a d) |
(.setFont g (Helvetica 12)) (.drawString g x y str) |
(define p (java.awt.Polygon.)) (.addPoint p x1 y1) (.addPoint p x2 y2) ... (.drawPolygon g p) (.fillPolygon g p) |
The following program uses many of the methods shown above to
draw a face when the user presses the
"draw face" button.