1 / 22

Programming Languages 2nd edition Tucker and Noonan

Programming Languages 2nd edition Tucker and Noonan. Chapter 16 Event-Driven Programming Of all men’s miseries the bitterest is this, to know so much and to have control over nothing. Herodotus (484-432 BC). Contents. 16.1 Event-Driven Control 16.2 Event Handling

jgladys
Download Presentation

Programming Languages 2nd edition Tucker and Noonan

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Programming Languages2nd editionTucker and Noonan Chapter 16 Event-Driven Programming Of all men’s miseries the bitterest is this, to know so much and to have control over nothing. Herodotus (484-432 BC)

  2. Contents 16.1 Event-Driven Control 16.2 Event Handling 16.3 Three Examples 16.4 Other Applications

  3. A conventional model of computation has the program prescribe the exact order of input. • Programs terminate once the input is exhausted. • Event-driven programs do not control the sequence in which input events occur.

  4. Examples • GUI applications: Model-View-Controller design • Embedded applications: • cell phones • car engines • airplanes

  5. 16.1 Event-Driven Control • Computation as interaction [Stein] • Computation is a community of persistent entities coupled together by their ongoing interactive behavior ... Beginning and end, when present, are special cases that can often be ignored.

  6. Imperative and Event-Driven Paradigms Contrasted Figure 16.1

  7. Input to an event-driven program comes from autonomous event sources. Eg: human, robot sensors, engine sensors.

  8. Properties • An event-driven program has no perceived stopping point. • The traditional read-eval-print loop does not explicitly appear. • An application processes an input and exits.

  9. Model-View-Controller (MVC) • Model: the object being implemented. Ex: game, calculator. • Controller: input mechanisms. Ex: buttons, menus, combo boxes. • View: output.

  10. Ex: Tic-Tac-Toe Model • Whose turn is it? • State of the board. • Has someone won? • Are there no empty squares?

  11. Events in Java • Subclasses of AWTEvent • Event sources in Swing are subclasses of JComponent • Program must listen for events • Ex: for a JButton b • b.addActionListener(listener)

  12. Java Class AWTEvent and Its Subclasses* Figure 16.2

  13. Java EventListener Class Interface and Its Subclasses* Figure 16.4

  14. Java GUI Application • A GUI application is a program that runs in its own window and communicates with users using buttons, menus, mouse clicks, etc. • A GUI application often has a paint method, which is invoked whenever the application needs to repaint itself.

  15. 16.3.2 Designing a Java Applet • Can convert previous application • An applet runs inside a web browser • Differences • Extend JApplet • Lacks a main method • Method init replaces constructor

  16. Tic-Tac-Toe • State of the board • Whose turn: X or O • Whether game is over

  17. private int player = -1; // Current player: EX, or OH • private int[ ] board = new int[9];

  18. Elements of a Typical ATM Machine Transaction User Interface Figure 16.25

  19. Overall Design of a Home Security System Figure 16.26

More Related