Starting Out With Programming Logic & Design - Chapter15_GUI Applications

Embed Size (px)

DESCRIPTION

Starting Out With Programming Logic & Design - Chapter15_GUI Applications

Citation preview

Chapter 14

Starting Out with Programming Logic & Design

Second Edition

by Tony GaddisChapter 15: GUI Applications & Event-Driven ProgrammingCopyright 2010 Pearson Education, Inc. Publishing as Pearson Addison-WesleyCopyright 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley15-2Chapter Topics15.1 Graphical User Interfaces15.2 Designing the User Interface for a GUI Program15.3 Writing Event HandlersCopyright 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley215-315.1 Graphical User InterfacesA Graphical User Interface (GUI) allows the user to interact with the operating system and other programs using graphical elements such as icons, buttons, and dialog boxesMuch of the work of a GUI is done through dialog boxes, which are small windows that display information and allow the user to perform actionsIn a command line interface, the programs determine the order in which things happenIn a GUI, the user can determine the order this is called event drivenCopyright 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley315-415.1 Graphical User InterfacesFigure 15-3 A GUI program

Copyright 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley415-515.1 Graphical User InterfacesCreating a GUI ProgramMost of the steps are the sameBut, the programmer also designs the GUI elements that make up each windowThis includes the flow from window to windowFigure 15-4 A user interface flow diagram

Copyright 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley515-615.2 Designing the User Interface for a GUI InterfaceGUI development also includes the programs windows and all the graphical componentsIn the past, this was a cumbersome processNewer languages allow for easier developmentUsing Microsoft Visual StudioVisual BasicC++C#Using NetBeans and JBuilderJavaCopyright 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley615-715.2 Designing the User Interface for a GUI InterfaceMost IDEs have a toolbox for easy developmentFigure 15-5 Visually constructing a window in Visual Basic

Copyright 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley715-815.2 Designing the User Interface for a GUI InterfaceComponents are items that appear in a programs graphical user interfaceButton: causes an action to occur when clickedLabel: can display textText Box: Allows the user to enter a single line of inputCheck Box: Allows one or more options to be selected Radio Button: Allows only one option to be selectedCombo Box: A dropdown list of items that the user can select an item from, or enter inputList Box: A list from which the user can select an itemSlider: Allows the user to select a value from a range

Copyright 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley815-915.2 Designing the User Interface for a GUI InterfaceFigure 15-7 Various components in a GUI window

Copyright 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley915-1015.2 Designing the User Interface for a GUI InterfaceComponent names are used to identify the components in the program, in the same way variable names are used

Figure 15-8 Components and their namesCopyright 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley1015-1115.2 Designing the User Interface for a GUI InterfaceProperties can be set on components to modify how it appears on the screenSets things like color, size, and positionA summary of constructing a windowSketch the windowCreate the necessary components and name themSet the components properties to the desired valuesCopyright 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley1115-1215.3 Writing Event HandlersEvent handlers are written to control the GUIAfter the windows are designed, event handlers are coded to respond to events when an action occurs, such as clicking a buttonEvent: an action that takes place within a programEvent handlers: a module that automatically executes when a specific event occursCopyright 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley1215-1315.3 Writing Event HandlersHow to write the event handler moduleModule ComponentName_EventName()The statements that appear hereare executed when the event occurs.End Module

//an event handler that closes a windowModule exitButton_Click()CloseEnd Module

Copyright 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley13