Event Driven Programming - PowerPoint PPT Presentation

1 / 5
About This Presentation
Title:

Event Driven Programming

Description:

the program starts running and waits for something to happen ... usually then the program goes back to the waiting mode. Listeners ... – PowerPoint PPT presentation

Number of Views:76
Avg rating:3.0/5.0
Slides: 6
Provided by: garyg4
Category:

less

Transcript and Presenter's Notes

Title: Event Driven Programming


1
Event Driven Programming
  • Gary Greer

2
Event Driven Programming?
  • basic programming uses sequence, selection, and
    repetition
  • these methods are useful in producing programs
    that start, run and terminate
  • modern programs, however, are expected to
    continually run and react to the user
  • as it turns out, it is quite complex to write
    programs like this and so we turn to event driven
    programming

3
How Does it Work?
  • the program starts running and waits for
    something to happen
  • the programmer sets up a listener to listen for
    some event to happen
  • when the event happens (say a button gets
    pressed) a group of instructions are executed
  • usually then the program goes back to the waiting
    mode

4
Listeners
  • there are a number of software objects that can
    listen
  • buttons, menus, sliders, windows, timers, etc.
  • you can also listen for events from physical
    devices
  • mice, keyboards
  • when the event occurs, the listener calls a
    section of code defined by the user

5
An Example
  • //... Create components
  • JButton faceButton new JButton("Change Face")
  • //... Add Listeners
  • faceButton.addActionListener(new FaceAction())
  • /
  • inner listener class that does the eye action
  • /
  • class FaceAction implements ActionListener
  • public void actionPerformed(ActionEvent e)
  • drawing.faceChange()
Write a Comment
User Comments (0)
About PowerShow.com