GUI Programming Joseph Sant Sheridan College. Agenda Elements of GUI programming Component-Based...

13
GUI Programming Joseph Sant Sheridan College

Transcript of GUI Programming Joseph Sant Sheridan College. Agenda Elements of GUI programming Component-Based...

Page 1: GUI Programming Joseph Sant Sheridan College. Agenda Elements of GUI programming Component-Based Programming. Event-Based Programming. A process using.

GUI Programming

Joseph Sant

Sheridan College

Page 2: GUI Programming Joseph Sant Sheridan College. Agenda Elements of GUI programming Component-Based Programming. Event-Based Programming. A process using.

Agenda

• Elements of GUI programming

• Component-Based Programming.

• Event-Based Programming.

• A process using a powerful IDE.

Page 3: GUI Programming Joseph Sant Sheridan College. Agenda Elements of GUI programming Component-Based Programming. Event-Based Programming. A process using.

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.

Page 4: GUI Programming Joseph Sant Sheridan College. Agenda Elements of GUI programming Component-Based Programming. Event-Based Programming. A process using.

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)

Page 5: GUI Programming Joseph Sant Sheridan College. Agenda Elements of GUI programming Component-Based Programming. Event-Based Programming. A process using.

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

Page 6: GUI Programming Joseph Sant Sheridan College. Agenda Elements of GUI programming Component-Based Programming. Event-Based Programming. A process using.

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.

Page 7: GUI Programming Joseph Sant Sheridan College. Agenda Elements of GUI programming Component-Based Programming. Event-Based Programming. A process using.

Event Listeners.

• Event Listeners are objects or functions or methods that code a response to a specific event.

Page 8: GUI Programming Joseph Sant Sheridan College. Agenda Elements of GUI programming Component-Based Programming. Event-Based Programming. A process using.

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.

Page 9: GUI Programming Joseph Sant Sheridan College. Agenda Elements of GUI programming Component-Based Programming. Event-Based Programming. A process using.

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.

Page 10: GUI Programming Joseph Sant Sheridan College. Agenda Elements of GUI programming Component-Based Programming. Event-Based Programming. A process using.

Layout

• Different schemes can be used to arrange the components on a screen.– Linear– Table– Grid– Others

Page 11: GUI Programming Joseph Sant Sheridan College. Agenda Elements of GUI programming Component-Based Programming. Event-Based Programming. A process using.

Layouts

Linear TableGrid

Page 12: GUI Programming Joseph Sant Sheridan College. Agenda Elements of GUI programming Component-Based Programming. Event-Based Programming. A process using.

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.

Page 13: GUI Programming Joseph Sant Sheridan College. Agenda Elements of GUI programming Component-Based Programming. Event-Based Programming. A process using.

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?