You are on page 1of 27

Event Programming

Lecture 1- Introduction
Introduction
Objectives
• Program
• Programming
• Algorithm
• IDE
• Event
• Event Driven Programming
• Applications
Program
Photosynthesis
Program is a sequence of instructions expressed in a specific programming
language.

• The programming language has:


Syntax
• These are grammatical rules for forming instructions.
Example: int x;

Semantics
• These are the meaning / interpretations of instructions.
Example: int x; // Declaration of variable x that will accept integers
Program…
Algorithm
Photosynthesis
Algorithm is a set of executable steps.

• They describe the solution to a problem in terms of the data needed to


represent the problem instance and the set of steps necessary to produce
the intended result.
• Programming languages must provide a way to represent both the
process and the data. They include:
• Words/statement
• Formula
• Flow chart
• Pseudocode
Algorithm…
Algorithm Representation
• Words/Statements
• To calculate the area A, of a rectangle
1. Get the length, L
2. Get the width, W
3. Area is found by getting the product of L and W
4. If the area is greater or equals to 100m2, stop otherwise;
5. Get new values of L and W by repeating the same process.

• Formula
• Uses mathematical expressions/theorems.
• To calculate the area A, of a rectangle
Area = Length x Width
Algorithm…
Algorithm Representation…
• Flow Chart
• The use of connected shapes with lines.
Algorithm…
Algorithm Representation…
• Pseudocode
• They are notations that resemble programming language representation.
• It is not executable by computing devices.
• Intended for human reading and not machine reading.

// Calculate Area of a rectangle


Length=L
Width=W
Area=LxW
Begin
Area>=100m2 , Stop
Else, repeat
End if
Stop
Algorithm…
Algorithm Properties
• Unambiguous
• Not open to different interpretations.
• Correct
• If the steps are followed, desired results will be achieved.
• Terminating
• The executable steps should be able to end to allow other steps and processes to be
executed.
• It should not tie the computing resources such as memory or processor time in unending
loop.
• Precise
• The steps should guide the implementers clearly.
Programming
Photosynthesis
Programming is the is the creative process of taking an algorithm (
executable set of steps) and encoding it into a programming language, so
that it can be executed by a computer.
• It is the process of writing instructions in a language that the computing
device can respond to and that other programmers can understand.
• This is the implementation of algorithms.
• Integrated Development Environments(IDE) facilitate programming. They
have the following features:
• Editors
• Compilers
• Debuggers
• Linkers
Programming…
Integrated Development Environment(IDE)
• This is a software application that provides comprehensive facilities to
computer programmers for software development.
• An IDE normally consists of a source code editor, build automation tools
and a debugger.
Examples: Netbeans Apache, Code Blocks…

Debugger
• A computer program that assists in the detection and correction of errors
in computer programs. Debugging is the process of resolving this errors.

Source Code
• Any collection of computer instructions (possibly with comments) written
using some human-readable computer language, usually as text.
Programming…
Source File
• This is a document that sets the macro definitions for the source code in a
subdirectory.
Examples: .Java, .c, .cpp and .py files

Compiler
• This is a computer program (or a set of programs) that transforms source
code written in a programming language (the source language) into
another computer language (the target language), with the latter often
having a binary form known as object code.

Linker
• A linker or link editor is a computer program that takes one or more object
files generated by a compiler and combines them into a single executable
file.
Programming Language
Photosynthesis
Programming Language is a set of instructions, written in a specific style,
that can be used to construct a program.

• This program gives instructions of the tasks to be achieved to the


computing devices.

• Why Programming Languages?


• Need to issue instructions to computer’s hardware and peripheral
devices.
• Need to indicate tasks and problems to be solved.
• Programming languages allows you to express the users needs.
Programming Language…
• Programming languages can be classified into:
• Low-Level Programming Languages
• Requires understanding of hardware.
• Machine dependent.
Example: Assembly Programming
MOV r16, r17; // Move content from one register to another

• High-Level Programming Languages


• Highly abstracted.
• Machine independent.
Example: Java Programming
int marks; // Declares variable marks that will accept integers
Event
Photosynthesis
Event is an happenings detected by a program.

• The happenings are triggered.


• Trigger is any activity or condition that has been initiated.
• The activities could be:
• Resizing
• Mouse click
• Closing a window
• Dragging and dropping
• Minimizing and maximizing
• Applications wait for unpredictable user input and responding to
an event depends on a trigger.
Event…
Event Sources
• Objects that generate events.
• They include:
• Buttons
• Text Fields

Event Listeners
• Objects that respond to events.

Event Handler
• Segment of code executed in response to a generated event.
• They are methods/functions.
• Activated when trigger occurs.

Event occurs when an event listener detects an event trigger and responds by
running an event handler(a method/function).
Event…
Example: Forms
Event…
Example: Forms
Event…
Event Initiators
• The inputs to event driven programs come from autonomous
event initiators.
• They include:
• Human
• Sensors
• Other programs
• …
Event…
Example: Analog and Digital PORTs
• Embedded Devices and Sensors

Source: (N.d., 2016)


Event Driven Programming
Photosynthesis
Event Driven Programming(EDP) is a programming paradigm in which
the flow of the program is determined by events.

• Determined by events such as:


• User actions of clicking, dragging, touching…
• Sensor outputs
• Messages from other applications
• They are different from other programs in which exact execution
order is prescribed(Program driven programs).
Event Driven Programming…
Model View Controller(MVC)
• A way of organizing code.
• MVC is a software design pattern commonly used for developing user
interfaces.
• It divides the related program into three interconnected elements:

• Model
• The implementation.
• Example: Computer POS software

• View
• The output.

• Controller
• Input mechanisms.
• Examples: Buttons, menus, combo boxes.
Graphical User Interface(GUI)
Photosynthesis
Graphical User Interface is window of a running program instance.

• GUI applications are programs that run in windows and


communicates with users using visible buttons, labels, text fields
and menus.
• The events are initiated through mouse clicks or touch(touch
screens).
• User interactions with GUI components create events that can be
caught by event handler.
GUI…
Example: MS Windows Calculator
• Deals with triggers for:
• Button clicks.
• Key presses.
• Menu selection.
• Radio buttons.
• Check boxes.
• Minimizing and maximizing movement.
Research
• Other types of programming approaches.
• Procedural
• Functional
• Object Oriented
• Scripted
• Logical
• …
• Applications of event driven programming.
Review Questions
• Define:
• GUI
• Event
• Syntax
• Event Listeners
• Event Handlers
• Event Driven Programming
• List the properties of events.
• Enumerate the benefits of Event driven programming.
• Differentiate:
1. Check boxes and Radio Buttons
2. Program Driven and Event Driven programs
• What are event handlers?
References
• Online
• N.d(2016, April 18)Arduino ir proximity sensor interfacing.Retrieved from
https://blog.circuits4you.com/2016/04/arduino-ir-proximity-sensor-
interfacing.html

• Books
• E-books
• Library

You might also like