Event-based Programming Roger Crawfis. Window-based programming Most modern desktop systems are window-based. Non-window based environment Window based.

Slides:



Advertisements
Similar presentations
Information System Design Lab 5&6. User Interface Design.
Advertisements

Introduction to Visual Basic.NET Uploaded By: M.Sheraz anjum.
Chapter 16 Graphical User Interfaces John Keyser’s Modifications of Slides by Bjarne Stroustrup
Excel and VBA Creating an Excel Application
Graphical User Interface (GUI) A GUI allows user to interact with a program visually. GUIs are built from GUI components. A GUI component is an object.
CS 112 GUI 06 May 2008 Bilkent. Java GUI API Containers: ◦ contain other GUI components. E.g, Window, Panel, Applet, Frame Dialog. Components: ◦ Buttons,
By Keren Haddad and Max Panasenkov
Graphical User Interfaces A Quick Outlook. Interface Many methods to create and “interface” with the user 2 most common interface methods: – Console –
Programming Paradigms Imperative programming Functional programming Logic programming Event-driven programming Object-oriented programming A programming.
Hands-on Introduction to Visual Basic.NET Programming Right from the Start with Visual Basic.NET 1/e 6.
Introduction to Graphical User Interfaces. Objectives * Students should understand what a procedural program is. * Students should understand what an.
An Introduction to Visual Basic
Welcome to CIS 083 ! Events CIS 068.
Department of Mechanical Engineering, LSUSession VII MATLAB Tutorials Session VIII Graphical User Interface using MATLAB Rajeev Madazhy
Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and.
Introduction to OpenGL and GLUT GLUT. What is OpenGL? An application programming interface (API) A (low-level) Graphics rendering API Generate high-quality.
Chapter 5 Menus, Common Dialog Boxes, and Methods Programming in C#.NET © 2003 by The McGraw-Hill Companies, Inc. All rights reserved.
2. Introduction to the Visual Studio.NET IDE. Chapter Outline Overview of the Visual Studio.NET IDE Overview of the Visual Studio.NET IDE Menu Bar and.
G RAPHICAL U SER I NTERFACE C ONCEPTS : P ART 1 1 Outline Introduction Windows Forms Event-Handling Model - Basic Event Handling.
Introduction to the Visual Studio.NET IDE (LAB 1 )
COS240 O-O Languages AUBG, COS dept Lecture 33 Title: C# vs. Java (GUI Programming) Reference: COS240 Syllabus.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 12 - Graphical User Interface Concepts: Part.
Rajiv and Shipra Introduction to.NET (asp.net,c#,vb)
CS350 – Windows Programming Formerly and more properly named: Event Driven Programming Dr. Randy Ribler.
Introduction to Windows Programming
CHAPTER TWO INTRODUCTION TO VISUAL BASIC © Prepared By: Razif Razali 1.
Creating Graphical User Interfaces (GUI’s) with MATLAB By Jeffrey A. Webb OSU Gateway Coalition Member.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
Controls. Adding Controls to Form -You can pick controls from the toolbox. -To add the controls from Toolbox to the Form You have be in design view. -To.
Dale Roberts Introduction to Visual Programming Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and.
1 Creating Windows GUIs with Visual Studio. 2 Creating the Project New Project Visual C++ Projects Windows Forms Application Give the Project a Name and.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
Java Applets: GUI Components, Events, Etc. Ralph Westfall June, 2010.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
Introduction to OpenGL and GLUT. What’s OpenGL? An Application Programming Interface (API) A low-level graphics programming API – Contains over 250 functions.
MS Visual Basic 6 Walter Milner. VB 6 0 Introduction –background to VB, A hello World program 1 Core language 1 –Projects, data types, variables, forms,
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Object Oriented Programming.  Interface  Event Handling.
SEEM3460 Tutorial GUI in Java. Some Basic GUI Terms Component (Control in some languages) the basic GUI unit something visible something that user can.
Introduction to visual programming C#. Learning Outcomes In this chapter, you will learn about :  Event-Based Programming  The Event Based Model  Application.
ASP.NET (Active Server Page) SNU OOPSLA Lab. October 2005.
Creating User Interfaces Event-Driven Programming.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1 Chapter 15 Event-Driven Programming and.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1 Chapter 15 Event-Driven Programming and.
Appendix A: Windows Forms. 2 Overview Describe the structure of a Windows Forms application –application entry point –forms –components and controls Introduce.
User Interface Programming in C#: Basics and Events Chris North CS 3724: HCI.
12-Jun-16 Event loops. 2 Programming in prehistoric times Earliest programs were all “batch” processing There was no interaction with the user Input Output.
Introduction to Windows Programming
Visual Basic Code & No.: CS 218
Chapter Topics 15.1 Graphical User Interfaces
Event loops 16-Jun-18.
3.01 Apply Controls Associated With Visual Studio Form
1. Introduction to Visual Basic
3.01 Apply Controls Associated With Visual Studio Form
Understand Windows Forms Applications and Console-based Applications
Ellen Walker Hiram College
Windows Desktop Applications
Event Driven Programming
VISUAL BASIC.
Social Media And Global Computing Introduction to Visual Studio
Understanding the Visual IDE
Event loops.
Event loops 17-Jan-19.
Event loops 17-Jan-19.
Chapter 15: GUI Applications & Event-Driven Programming
Event loops 8-Apr-19.
Overview of the IDE Visual Studio .NET is Microsoft’s Integrated Development Environment (IDE) for creating, running and debugging programs (also.
Event loops.
Event loops 19-Aug-19.
Presentation transcript:

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 FProcedural programming F code is executed in sequential order. FEvent-driven programming F code is executed upon activation of events. statement 1 statement 2 statement statement n method 1 method 2 method 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!