GUI Programming
Joseph Sant
Sheridan College
Agenda
• Elements of GUI programming
• Component-Based Programming.
• Event-Based Programming.
• A process using a powerful IDE.
GUI Programming - Components
• GUI programming is done using pre-built components such as textboxes, buttons, radio buttons etc.
• Programmer will set and programmatically reset properties of these components.
• The components are capable of detecting events that happen to them (such as someone clicking on them). The programmer might attach an event listener to the component to perform a task when a specific event occurs.
Event-Driven Component Programming
• Layout appropriate components on a container component.
• Some components might allow the user to trigger an action. The programmer might want the program to perform some task when that action occurs (e.g. someone clicking on a button)
Event-Driven Component Programming
GoDo this.Do this.Do this.
If button clicked do this
If radiobutton clicked do this
If slider moved do this
Go
Sequential Event-Driven
Event-Driven Programming.
• In standard sequential programming, the programmer is in control of what is done and when it is done.
• In event-driven programming the programmer is still in control of what is done but loses control over when it is done.
• The user is in control of when a task is done.
Event Listeners.
• Event Listeners are objects or functions or methods that code a response to a specific event.
Event-Driven Component Programming
EXAMPLEA button on a calculator program might add the
numbers in two text fields when clicked.
• The programmer would have to attach an event listener to the click event of a button.
• The event listener contains code that• parses the two text fields.• add the numbers together.• resets another field to the result of the addition.
Components/Widgets
• There are many components that can be used to develop GUI applications:– Text boxes– Radio Buttons– List Boxes– Combo boxes
• Containers are used to display several components or other container classes.– Frames.– Panels.
Layout
• Different schemes can be used to arrange the components on a screen.– Linear– Table– Grid– Others
Layouts
Linear TableGrid
Developing GUI programs using a powerful IDE.
• Create a Android Application project.
• Add an Activity.
• Drag or select components from the pallette and position them on the form.
• Context menus for a given control typically allow you to select a number of possible listeners for a given event.
Questions?
• What is a listener?
• When are listener methods executed.
• Can you write a listener that never executes in a given program?
• Are layouts and containers the same thing?