SlideShare a Scribd company logo
Event-based Programming
Roger Crawfis
Window-based
programming
• Most modern desktop systems are
window-based.
Non-window based environment
Window based environment
What location do I use to set this pixel?
Event-based Programming
• Window-based GUI’s are typically
comprised of many independent
processes.
• These processes sit and wait for
the user to do something, to which
it can respond.
• Moreover, a simple application may
be waiting for any of a number of
things.
Event-based Programming
• Sample main programs:
– C# / managed C++
static void Main()
{
Application.Run( new Form1());
}
– C++ (MFC Document/View architecture)
There isn’t one!!
– GLUT
void main(int argc, char** argv)
{
myInit();
glutMainLoop();
}
Programming forms
 Procedural programming
 code is executed in sequential order.
 Event-driven programming
 code is executed upon activation of events.
statement 1
statement 2
statement 3
--------
--------
statement n
method 1
method 2
method 3
--------
--------
method n
Do
method 1
then
method 3
Do
method 2
then
method 1
then
method 3
Procedural programming
• Up to now, our control flow model has been
pretty straight-forward.
• Execution starts at main() and executes
statement sequentially branching with if,for,and
while statement, and occasional method calls.
• When we need user input we call read() on the
console stream which waits (blocks) until the
user types something, then returns.
• One problem with this model is: How do we wait
for and respond to input from more than one
source (eg keyboard and mouse). If we block
on either waiting for input, we may miss input
from the other.
Event-driven programming
• the system waits for user input
events, and these events trigger
program methods
• Event-based programming
addresses the two problems:
– How to wait on multiple input sources
(input events)
– How to decide what to do on each
type of input event
General form of event-
driven programming
• The operating system and window
system process input events from
devices (mouse movement, mouse
clicks, key presses etc)
• The window system decides which
window, and hence which frame and
program, each input event belongs to.
General form of event-driven
programming
• A data structure describing the event is
produced and placed on an event queue.
Events are added to one end of the
queue by the window system. Events are
removed from the queue and processed
by the program. These event data
structures hold information including:
– Which of the program's windows this event
belongs to.
– The type of event (mouse click, key press,
etc.)
– Any event-specific data (mouse position, key
code, etc.)
Event loop
• main(){
• ...set up application data structures...
• ...set up GUI....
• // enter event loop
• while(true){
• Event e = get_event();
• process_event(e); // event dispatch routine } }
• the event loop is usually hidden from
programmer, he/she provides just a
process_event() method
AWT Applications - Frame
• Frame is a container for components
Frame with
normal window
controls
Optional Menu
Three
containers in
Frame with
Border Layout
UI-components
inside
containers each
with own layout
Understanding the GUI
• UI-containers
– have list of
UI-components
• Each UI-component
– is a class
– with paint method
– & lists of
Event listeners
{Frame}
{label}
{textfield}
{button}
components
Understanding .NET UI
Components
• Overview
– Replacement for VB Forms and MFC
• Fully integrated with the .NET framework
• Web Service aware
• Data (ADO.NET and XML) aware
• Secure code and Licensing
– A framework for building Windows
application
• “No touch” deployment
– No registration, Versionable, Smart caching
– A RAD environment in Visual Studio .NET
• Windows Form Designer, Property Browser
Overview (cont)
– Rich set of controls
• Standard controls - Label, Button, TextBox, etc.
• Common controls - ProgressBar, StatusBar, etc.
• Data aware controls - ListBox, DataGrid, etc.
• Common dialogs
– ActiveX Interoperability
• Can host ActiveX controls / author ActiveX controls
– Printing Support
– Visual inheritance
• Create a form based on another form by using
inheritance
– Advanced layout
• Anchoring and docking
Basic Terms
• Component
– Timer, DB Connection
• Control (User Control)
– Windows Forms
• Menu
• Button
• etc
– Web Forms
• ASP.NET specific
Using VS.NET
• Adding Components and Controls
– Just drag component from the toolbox
• Editing properties
– Edit directly in the properties editor
• Registering for events
– Also in the properties editor
What actually happens?
• Data members for components
• For example, after placing timer:
public class FunnyButton :
System.Windows.Forms.Button
{
private System.Windows.Forms.Timer
timer1;
What actually happens?
• Attributes for the properties
• For example, after changing Text
property:
private void InitializeComponent()
{
…
this.Text = "ADO Example";
What actually happens?
• Delegates for events
– Special type event in .NET (special delegate)
private void InitializeComponent()
{
…
this->MouseEnter += new
System.EventHandler(this.UserControl1_MouseEnter
);
…
}
…
private void UserControl1_MouseEnter(object sender,
System.EventArgs e) {}
Names everyone should
know
• Properties
– Name – data member name
– Text – text shown by control (was
Caption)
– ForeColor – current text color
– Dock – docking to the parent
– Enabled – active or not
• Events
– Click – mouse click on the control
– SizeChanged - resize
InitializeComponent()
method
• This method is created by VS.NET
• Code generated there represents all the
changes done in the design view
• Note: if you remove event handler or
data member added by VS.NET
manually, do not forget to clean the code
that uses it from InitializeComponent().
• Doing this from the design view is easier!

More Related Content

PDF
The fundamental problems of GUI applications and why people choose React
PDF
Introduction to Visual Basic 6.0
PPTX
Win runner testing tool
PPT
2.5 gui
PPTX
Spug pt session2 - debuggingl
PDF
Apache flink
PPT
2006 - Basta!: Advanced server controls
The fundamental problems of GUI applications and why people choose React
Introduction to Visual Basic 6.0
Win runner testing tool
2.5 gui
Spug pt session2 - debuggingl
Apache flink
2006 - Basta!: Advanced server controls

Similar to cse581_03_EventProgramming.ppt (20)

PPT
digital data processing types of OS utility.ppt
PPTX
Advanced Coded UI Testing
PPTX
Mastering the Lightning Framework - Part 2 - JF Paradis.pptx
PPTX
c programming 1-1.pptx
PPT
Implementation
PPT
Lesson 2 - Understanding Operating System Configurations
PDF
PPT
Windows programming ppt
PPT
Swing_Introduction and working java.ppt
PPTX
B2. activity and intent
PPTX
Presentation acme sys999tems Ragini 1.pptx
PPTX
A look behind the scenes: Windows 8 background processing
PPTX
3 App Compat Win7
PDF
Visual basic
PPT
2310 b 05
PPTX
Event driven theory
PPTX
Introduction to embedded system
KEY
Intro To webOS
PPTX
Azure Service Fabric: notes from the field (Sam Vanhoute @Integrate 2016)
PDF
Suncoast Credit Union and Armwood High School - UiPath automation developer s...
digital data processing types of OS utility.ppt
Advanced Coded UI Testing
Mastering the Lightning Framework - Part 2 - JF Paradis.pptx
c programming 1-1.pptx
Implementation
Lesson 2 - Understanding Operating System Configurations
Windows programming ppt
Swing_Introduction and working java.ppt
B2. activity and intent
Presentation acme sys999tems Ragini 1.pptx
A look behind the scenes: Windows 8 background processing
3 App Compat Win7
Visual basic
2310 b 05
Event driven theory
Introduction to embedded system
Intro To webOS
Azure Service Fabric: notes from the field (Sam Vanhoute @Integrate 2016)
Suncoast Credit Union and Armwood High School - UiPath automation developer s...
Ad

More from tadudemise (8)

PPTX
What is requirement gathering chap3 1.pptx
PPT
chaptertaaaaaaaaaaaaaaadddddddd2222 4.ppt
PPT
8329969.ppt
PPT
03a-IntroductionToEventDrivenProgramming.ppt
PPT
Introduction.ppt
PPT
Chapter 1.ppt
PPT
SPL_PS2 (1).ppt
PPT
03a-IntroductionToEventDrivenProgramming.ppt
What is requirement gathering chap3 1.pptx
chaptertaaaaaaaaaaaaaaadddddddd2222 4.ppt
8329969.ppt
03a-IntroductionToEventDrivenProgramming.ppt
Introduction.ppt
Chapter 1.ppt
SPL_PS2 (1).ppt
03a-IntroductionToEventDrivenProgramming.ppt
Ad

Recently uploaded (20)

PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
MYSQL Presentation for SQL database connectivity
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PPTX
Spectroscopy.pptx food analysis technology
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Empathic Computing: Creating Shared Understanding
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
A Presentation on Artificial Intelligence
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
MYSQL Presentation for SQL database connectivity
NewMind AI Weekly Chronicles - August'25-Week II
Spectroscopy.pptx food analysis technology
sap open course for s4hana steps from ECC to s4
Empathic Computing: Creating Shared Understanding
“AI and Expert System Decision Support & Business Intelligence Systems”
Network Security Unit 5.pdf for BCA BBA.
MIND Revenue Release Quarter 2 2025 Press Release
A Presentation on Artificial Intelligence
20250228 LYD VKU AI Blended-Learning.pptx
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Review of recent advances in non-invasive hemoglobin estimation
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
The Rise and Fall of 3GPP – Time for a Sabbatical?
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm

cse581_03_EventProgramming.ppt

  • 2. Window-based programming • Most modern desktop systems are window-based. Non-window based environment Window based environment What location do I use to set this pixel?
  • 3. Event-based Programming • Window-based GUI’s are typically comprised of many independent processes. • These processes sit and wait for the user to do something, to which it can respond. • Moreover, a simple application may be waiting for any of a number of things.
  • 4. Event-based Programming • Sample main programs: – C# / managed C++ static void Main() { Application.Run( new Form1()); } – C++ (MFC Document/View architecture) There isn’t one!! – GLUT void main(int argc, char** argv) { myInit(); glutMainLoop(); }
  • 5. Programming forms  Procedural programming  code is executed in sequential order.  Event-driven programming  code is executed upon activation of events. statement 1 statement 2 statement 3 -------- -------- statement n method 1 method 2 method 3 -------- -------- method n Do method 1 then method 3 Do method 2 then method 1 then method 3
  • 6. Procedural programming • Up to now, our control flow model has been pretty straight-forward. • Execution starts at main() and executes statement sequentially branching with if,for,and while statement, and occasional method calls. • When we need user input we call read() on the console stream which waits (blocks) until the user types something, then returns. • One problem with this model is: How do we wait for and respond to input from more than one source (eg keyboard and mouse). If we block on either waiting for input, we may miss input from the other.
  • 7. Event-driven programming • the system waits for user input events, and these events trigger program methods • Event-based programming addresses the two problems: – How to wait on multiple input sources (input events) – How to decide what to do on each type of input event
  • 8. General form of event- driven programming • The operating system and window system process input events from devices (mouse movement, mouse clicks, key presses etc) • The window system decides which window, and hence which frame and program, each input event belongs to.
  • 9. General form of event-driven programming • A data structure describing the event is produced and placed on an event queue. Events are added to one end of the queue by the window system. Events are removed from the queue and processed by the program. These event data structures hold information including: – Which of the program's windows this event belongs to. – The type of event (mouse click, key press, etc.) – Any event-specific data (mouse position, key code, etc.)
  • 10. Event loop • main(){ • ...set up application data structures... • ...set up GUI.... • // enter event loop • while(true){ • Event e = get_event(); • process_event(e); // event dispatch routine } } • the event loop is usually hidden from programmer, he/she provides just a process_event() method
  • 11. AWT Applications - Frame • Frame is a container for components Frame with normal window controls Optional Menu Three containers in Frame with Border Layout UI-components inside containers each with own layout
  • 12. Understanding the GUI • UI-containers – have list of UI-components • Each UI-component – is a class – with paint method – & lists of Event listeners {Frame} {label} {textfield} {button} components
  • 13. Understanding .NET UI Components • Overview – Replacement for VB Forms and MFC • Fully integrated with the .NET framework • Web Service aware • Data (ADO.NET and XML) aware • Secure code and Licensing – A framework for building Windows application • “No touch” deployment – No registration, Versionable, Smart caching – A RAD environment in Visual Studio .NET • Windows Form Designer, Property Browser
  • 14. Overview (cont) – Rich set of controls • Standard controls - Label, Button, TextBox, etc. • Common controls - ProgressBar, StatusBar, etc. • Data aware controls - ListBox, DataGrid, etc. • Common dialogs – ActiveX Interoperability • Can host ActiveX controls / author ActiveX controls – Printing Support – Visual inheritance • Create a form based on another form by using inheritance – Advanced layout • Anchoring and docking
  • 15. Basic Terms • Component – Timer, DB Connection • Control (User Control) – Windows Forms • Menu • Button • etc – Web Forms • ASP.NET specific
  • 16. Using VS.NET • Adding Components and Controls – Just drag component from the toolbox • Editing properties – Edit directly in the properties editor • Registering for events – Also in the properties editor
  • 17. What actually happens? • Data members for components • For example, after placing timer: public class FunnyButton : System.Windows.Forms.Button { private System.Windows.Forms.Timer timer1;
  • 18. What actually happens? • Attributes for the properties • For example, after changing Text property: private void InitializeComponent() { … this.Text = "ADO Example";
  • 19. What actually happens? • Delegates for events – Special type event in .NET (special delegate) private void InitializeComponent() { … this->MouseEnter += new System.EventHandler(this.UserControl1_MouseEnter ); … } … private void UserControl1_MouseEnter(object sender, System.EventArgs e) {}
  • 20. Names everyone should know • Properties – Name – data member name – Text – text shown by control (was Caption) – ForeColor – current text color – Dock – docking to the parent – Enabled – active or not • Events – Click – mouse click on the control – SizeChanged - resize
  • 21. InitializeComponent() method • This method is created by VS.NET • Code generated there represents all the changes done in the design view • Note: if you remove event handler or data member added by VS.NET manually, do not forget to clean the code that uses it from InitializeComponent(). • Doing this from the design view is easier!