Computer Science 225
Advanced Programming
Spring 2020, Siena College
Lecture 15: Event-Driven Programming: Dragging
Date: Monday, February 24, 2020
Agenda
- Announcements
- Problem Set 3 is due tonight, regular late policies apply
- This week: optional exam review instead of lab meetings (first hour)
- Exam 1: be in RB 202 at 7:00 Wednesday evening unless you've
made other arrangements
- Event-driven programming
- In-class exercices (10 points), work in small groups
You will receive an invitation to create a repository that contains
two of today's examples. Your tasks are to enhance them as follows:
- Modify the SpiralLines example so it chooses a random
color for each spiral, but keep using those same colors for the
entire spiral.
Also think about these variations (but they're not required):
- choose a new random color for every line, not every spiral
- choose a new random color for every line every time (on
each mouse event)
- Modify the DragABall example so the program initially
draws two different colored circles at random locations within
the graphics window. Then the user can drag either ball.
Some additional considerations:
- what if you also always want to have the circle being
dragged drawn on top of the other circle?
- what if you want to make the functionality so that when
you press the mouse in a location inside both circles, you
always drag the one which is drawn on top?
- or how about if you want to drag both circles when the
initial press point is on both?
Commit and push your code when you are finished. Be sure the names
of everyone who worked together is in the README.md file and in
both programs.
Terminology
- event-driven program
- listeners
- event handlers
- absolute move
- translate/relative move
Examples