Lec 36 - Lec 35 Cont

Paintcomponentgc for shape s actions if preview

Info icon This 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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern