1 of 9

Event-Driven Programming

2 of 9

What does it mean to be “event-driven”?

  • Program statements are executed when triggered rather than through the sequential flow of control
    • Important in applications focused around user interaction, because different users will interact with the application in different ways
  • What are some examples of “events”?

3 of 9

The Lo-fi MP3 Player Project

  • The application produced by this project will be a lightweight MP3 player that plays the songs your group has created in EarSketch.
  • Events in this example:
    • User clicks “Play”
    • User clicks “Pause”
    • User clicks “Random Song”
    • User clicks the button to play Airport
    • User clicks the button to play Vibes
    • User clicks the button to play Last Day

4 of 9

Code Breakdown

  • In the project templates provided, there is pre-written HTML to set up the buttons. You are free to change this code to fit your team’s chosen design

5 of 9

Code Breakdown

  • To execute code statements based on events (user interaction), we add the “onclick” event to the buttons in order to execute specific functions when they are clicked.

6 of 9

Code Breakdown

  • onclick=”songSelect(1)” executes the songSelect() functions with an input of 1
    • This function is currently incomplete and will be addressed in a future sprint

7 of 9

Code Breakdown

  • onclick=”pause” executes the pause() function, which doesn’t need any input arguments

8 of 9

Sprint #1 Design Tasks

  • Student groups should produce a mockup on paper of what they want their interface for the Lo-fi MP3 player to look like
  • Additionally, student groups should produce a list of user stories: general explanations of the features of their application from the perspective of the user
    • Consider the list of events that should be handled as part of the application

9 of 9

Sprint #1 Coding Tasks

This sprint should focus the setup of initial project infrastructure.

  • Any design elements from their mockups that the group has chosen to implement should be reflected in their script
  • One functional button that plays a song when clicked
  • A list in the script containing the song file names
    • All songs must be present in the project directory