Lec 36 - Lec 35 Cont

Paintcomponentgc for shape s actions if preview

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: oked when a key has been typed •  Use KeyAdapter to easily make an instance of this interface Paint: Comparison with OCaml How does our treatment of shape drawing in Java compare with the OCaml GUI project? Java Design Summary public interface Shape { public void draw(Graphics gc); Interface describes what shapes can do } public class PointShape implements Shape { … } public class LineShape implements Shape { … } Classes describe how to draw themselves private class Canvas extends JPanel { public void paintComponent(Graphics gc) { super.paintComponent(gc); for (Shape s : actions) if (preview != null) } } s.draw((Graphics2D)gc); preview.draw((Graphics2D)gc); Canvas uses dynamic dispatch to draw the shapes type point = int * int! type shape = ! | Point of Gctx.color * int * point! | Line of Gctx.color * int * point * point! (* Repaint function for displaying the canvas. *)! let repaint (g:Gctx.t) : unit =! let actions = List.rev paint.shapes in! let drawit d = ! begin match d with! | Point (c,t,p) -> ! ! Gctx.draw_points (set_params g c t) p! | Line (c,t,p1,p2) -> ! Gctx.draw_line (set_params g c t) p1 p2! end in ! List.iter drawit actions CIS 120 ! Comparison with OCaml •  How does our treatment of shape drawing in the Java Paint example compare with the OCaml GUI project? •  Java: –  –  –  –  Interface Shape for drawable objects Classes implement that int...
View Full Document

This note was uploaded on 10/23/2012 for the course CIS 121 taught by Professor Tannen during the Spring '09 term at UPenn.

Ask a homework question - tutors are online