ch14 - Alice in Action with Java Chapter 14 Events and GUIs...

Info iconThis preview shows pages 1–13. Sign up to view the full content.

View Full Document Right Arrow Icon
Alice in Action with Java Chapter 14 Events and GUIs
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Alice in Action with Java 2 Objectives Use Java’s event classes to model user events Design and build listener classes to handle user events Design and build applications that have simple graphical user interfaces (GUIs)
Background image of page 2
Alice in Action with Java 3 Events and GUIs Event: an occurrence during program execution Examples: mouse clicks and key presses Event handler: a mechanism that manages events A method is written to provide responsive behavior A method is then associated with the event Event-driven program: program directed by events Chapter goals Write event-driven programs in Java Build graphical user interfaces (GUIs) Handle events generated by GUIs
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Alice in Action with Java 4 Introduction: Miles to Kilometers and Vice Versa Elements of user story for MilesKmsConverter Open a window Display two boxes: “Miles:” and “Kilometers:” User enters numerical data into either box If Miles box is selected, program returns kilometers value If Kilometers box is selected, program returns miles value User clicks the Close button to quit the application Storyboard: sketch that captures a program element Example: storyboard can be used to represent a GUI Transition diagram: shows GUI’s response to events
Background image of page 4
Alice in Action with Java 5 Introduction: Miles to Kilometers and Vice Versa (continued)
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Alice in Action with Java 6 Introduction: Miles to Kilometers and Vice Versa (continued)
Background image of page 6
Alice in Action with Java 7 Introduction: Miles to Kilometers and Vice Versa (continued)
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Alice in Action with Java 8 Introduction: Miles to Kilometers and Vice Versa (continued) Three user events that must be handled The user clicks the window’s Close button The user enters a number in the “Miles:” text box The user enters a number in the “Kilometers:” text box Java provides components to build GUIs Example: JTextField for an input box Listener : class used to store event handlers Listeners used in MilesKmConverter program KmsListener and MilesListener Contain methods to handle event (provide conversion)
Background image of page 8
Alice in Action with Java 9 Introduction: Miles to Kilometers and Vice Versa (continued)
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Alice in Action with Java 10 Introduction: Miles to Kilometers and Vice Versa (continued)
Background image of page 10
Alice in Action with Java 11 Java GUI Components, Events, and Listeners Four parts to MilesKmsConverter MilesKmsConverter constructor Lines 9-27: constructs the GUI MilesListener class Lines 29-43: handles user events in the “Miles:” box KmsListener class Lines 45-59: handles user events in “Kilometers:” box main() method Lines 65-69: flow begins when the program is run
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Alice in Action with Java 12 The main() Method First line: call to MilesKmsConverter constructor Builds a MilesKmsConverter object Stores a reference to an object named self Second line:
Background image of page 12
Image of page 13
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/27/2008 for the course INSY 3300 taught by Professor Wang during the Spring '08 term at UT Arlington.

Page1 / 65

ch14 - Alice in Action with Java Chapter 14 Events and GUIs...

This preview shows document pages 1 - 13. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online