CNS 1410 Graphical User Interfaces. Obectives Students should understand the difference between a procedural program and an Event Driven Program. Students.

Slides:



Advertisements
Similar presentations
Chapter 16 Graphical User Interfaces
Advertisements

Chapter 16 Graphical User Interfaces John Keyser’s Modifications of Slides by Bjarne Stroustrup
Unit 3 Graphical User Interface (GUI) Dr. Magdi AMER.
Graphic User Interfaces Layout Managers Event Handling.
1 Chapter 8 Objects and Classes Lecture 2 Prepared by Muhanad Alkhalisy.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
CA 121 Intro to Programming Tariq Aziz and Kevin Jones GUI Programming in Visual Studio.NET Chapter 1 Tariq Aziz and Kevin Jones.
Visual Basic Project Files:.VBP file: Project File: a small text file that contains the names of other files in the project, as well as some information.
1 Event Driven Programming with Graphical User Interfaces (GUIs) A Crash Course © Rick Mercer.
Fundamentals of Programming in Visual Basic 3.1 Visual basic Objects Visual Basic programs display a Windows style screen (called a form) with boxes into.
Exploring the Basics of Windows XP
Chapter 6: Graphical User Interface (GUI) and Object-Oriented Design (OOD) J ava P rogramming: Program Design Including Data Structures Program Design.
Visual Basic 2008 Express Edition The IDE. Visual Basic 2008 Express The Start Page Recent Projects Open an existing project Create a New Project.
Java Programming Chapter 10 Graphical User Interfaces.
CS5103 Software Engineering Lecture 08 Android Development II.
Introduction to Graphical User Interfaces. Objectives * Students should understand what a procedural program is. * Students should understand what an.
Java Programming, 3e Concepts and Techniques Chapter 3 Section 65 – Manipulating Data Using Methods – Java Applet.
GUI’s Part Two wxWidgets components. Resources for wxWidgets Sample code on course website wxWidgets web site.
Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and.
© 2006 Lawrenceville Press Slide 1 Chapter 3 Visual Basic Interface.
Visual C++ Lecture 11 Friday, 29 Aug Windows Graphic User Interface l Event driven programming environment l Windows graphic libraries (X11 on Unix,
Prepared by Fareeha Lecturer DCS IIUI 1 Windows API.
Java Programming: From Problem Analysis to Program Design, Second Edition1  Learn about basic GUI components.  Explore how the GUI components JFrame,
Getting Started The structure of a simple wxWidgets program, Look at where and how a wxWidgets application starts and ends, how to show the main window,
Introduction to Visual Basic.NET Chapter 2 Introduction to Controls, Events.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 7 Using Menus, Common Dialogs, Procedures, Functions, and Arrays.
1 Scroll Bars Providing Scrollbars. 2 Objectives You will be able to: Use Windows Graphics to display tabular information on a Windows form. Add graphics.
C H A P T E R T E N Event-Driven Programming Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan.
Sample Application Multi Layered Architecture (n-tier): –Graphical User Interface (GUI): Forms, components, controls The Visual Designer in Visual Studio.
FEN IntroJava2006 AAU1 GUI: Graphical User Interface AWT/SWING: Components Drag and Drop in NetBeans Events Listeners.
1 Computer Science of Graphics and Games MONT 105S, Spring 2009 Session 20 Graphical User Interface (GUI)
CC111 Lec7 : Visual Basic 1 Visual Basic(1) Lecture 7.
Applications Development
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.
Introduction to Windows Created by Mrs. Leverette.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
CS324e - Elements of Graphics and Visualization Java GUIs - Event Handling.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 21.1 Test-Driving the Painter Application.
CS-1020 Dr. Mark L. Hornick 1 Event-Driven Programming.
Topics Introduction Scene Graphs
CS1054: Lecture 21 - Graphical User Interface. Graphical User Interfaces vs. Text User Interface.
Java Programming: From Problem Analysis to Program Design, 3e Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
9-Nov-97Tri-Ada '971 TASH An Alternative to the Windows API TRI-Ada ‘97 Terry J. Westley
Java Programming: From Problem Analysis to Program Design, Second Edition1 Lecture 5 Objectives  Learn about basic GUI components.  Explore how the GUI.
GUIs Basic Concepts. GUI GUI : Graphical User Interface Window/Frame : a window on the screen Controls/Widgets : GUI components.
CIS Intro to JAVA Lecture Notes Set 8 9-June-05.
Word Processor Version.2. Methods Visual Basic is –Object Oriented –Event Driven Objects –Properties –Methods.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 2 – Welcome Application Introduction to Graphical.
Architecture Multi Layered Architecture (n-tier): Application: Model Controllers Database Access Graphical User Interface (GUI): Forms, components, controls.
Lecture 33: More Graphical User Interface (GUI) Announcements & Review Read Ch GU1 & GU2 Cohoon & Davidson Ch 14 Reges & Stepp Lab 10 set game due 4/26.
Programming Logic and Design Fourth Edition, Comprehensive Chapter 14 Event-Driven Programming with Graphical User Interfaces.
Copyright © – Curt Hill Building Windows Applications in wxDev-C++
Lesson 28: More on the GUI button, frame and actions.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
5-1 GUIs and Events Rick Mercer. 5-2 Event-Driven Programming with Graphical user Interfaces  Most applications have graphical user interfaces to respond.
1 Event Driven Programming with Graphical User Interfaces (GUIs) A Crash Course © Rick Mercer.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 7 ( Book Chapter 14) GUI and Event-Driven Programming.
Topics Graphical User Interfaces Using the tkinter Module
Event Loops and GUI Intro2CS – weeks
Visual Basic Code & No.: CS 218
Introduction to Computer CC111
1. Introduction to Visual Basic
Java Programming: From Problem Analysis to Program Design,
Ellen Walker Hiram College
Introduction to Computing Using Java
AWT Components and Containers
Topics Graphical User Interfaces Using the tkinter Module
Advanced Programming in Java
Constructors, GUI’s(Using Swing) and ActionListner
Tonga Institute of Higher Education
Presentation transcript:

CNS 1410 Graphical User Interfaces

Obectives Students should understand the difference between a procedural program and an Event Driven Program. Students should be able to describe the basic components of a GUI. Students should be able to create a simple GUI, using wxWidgets Students should be able to describe the event handling mechanism of wxWidgets.

Traditional Model – Command Line Programs Object main ( ) { declare variables create objects send messages to objects... send messages to objects... return 0 }

Graphical User Interface Model Application Object Frame Object Domain Objects

Graphical User Interface Model Application Object The application object “listens” for events to occur, then calls event handlers in the Frame Object.

Graphical User Interface Model Frame Object GUI Component GUI Component (widgets) generate events. Event handlers react to events GUI Component GUI Component

x File Edit View Help Name: Phone: PUSH GUI Components Frame

Graphical User Interface Model Domain Objects Domain objects do the work of the application

File Edit View Help PUSH Application Object Windows Event Queue Button Event

Application Object Windows Event Queue Frame Object Button Event

Application Object Windows Event Queue Frame Object Button Event Call event handler

Graphical User Interfaces Application Object Windows Event Queue Frame Object Button Event Call event handler Domain Objects Call functions in domain objects to do some work.

#include class BasicApplication : public wxApp { public: bool OnInit( ); }; Application Object The application class only needs one Function named OnInit. This function is used to create the User Interface.

bool BasicApplication::OnInit( ) { BasicFrame *frame = new BasicFrame("Hello World", 50, 50, 450, 340); frame->Show(true); SetTopWindow(frame); return TRUE; } This statement creates a Frame object. Frames represent windows. By default, Frame objects contain all of the function of a simple window. You can drag them, resize them, and close them.

bool BasicApplication::OnInit( ) { BasicFrame *frame = new BasicFrame("Hello World", 50, 50, 450, 340); frame->Show(true); SetTopWindow(frame); return TRUE; } This statement makes the Frame object visible.

bool BasicApplication::OnInit( ) { BasicFrame *frame = new BasicFrame("Hello World", 50, 50, 450, 340); frame->Show(true); SetTopWindow(frame); return TRUE; } This statement makes the Frame the topmost Frame.

#include class BasicFrame : public wxFrame { public: BasicFrame(const wxChar *title, int xpos, int ypos, int width, int height); void OnQuit(wxCommandEvent& event); void OnAbout(wxCommandEvent& event); private: DECLARE_EVENT_TABLE( ) }; Event handlers

BEGIN_EVENT_TABLE(BasicFrame, wxFrame) EVT_MENU(ID_QUIT, BasicFrame::OnQuit) EVT_MENU(ID_ABOUT, BasicFrame::OnAbout) END_EVENT_TABLE( ) The Event Table for the Frame When you receive an event named ID_QUIT, call the function OnQuit in the BasicFrame class.

BasicFrame::BasicFrame(const wxChar *title, int xpos, int ypos, int width, int height) : wxFrame( (wxFrame *)NULL, -1, title, wxPoint(xpos, ypos), wxSize(width, height)) { wxMenu *menuFile = new wxMenu; menuFile->Append(ID_ABOUT, "&About..."); menuFile->AppendSeparator( ); menuFile->Append(ID_QUIT, "E&xit"); wxMenuBar *menuBar = new wxMenuBar; menuBar->Append(menuFile, "&File"); SetMenuBar(menuBar); CreateStatusBar( ); SetStatusText("Welcome to wxWidgets"); } Frame Constructor text for title bar Position of upper left hand corner of the window on the screen window size

BasicFrame::BasicFrame(const wxChar *title, int xpos, int ypos, int width, int height) : wxFrame( (wxFrame *)NULL, -1, title, wxPoint(xpos, ypos), // wxSize(width, height)) { wxMenu *menuFile = new wxMenu; menuFile->Append(ID_ABOUT, "&About..."); menuFile->AppendSeparator( ); menuFile->Append(ID_QUIT, "E&xit"); wxMenuBar *menuBar = new wxMenuBar; menuBar->Append(menuFile, "&File"); SetMenuBar(menuBar); CreateStatusBar( ); SetStatusText("Welcome to wxWidgets"); } Frame Constructor pointer to parent (containing) class ID – default is -1 title bar text position // size

BasicFrame::BasicFrame(const wxChar *title, int xpos, int ypos, int width, int height) : wxFrame( (wxFrame *)NULL, -1, title, wxPoint(xpos, ypos), wxSize(width, height)) { wxMenu *menuFile = new wxMenu; menuFile->Append(ID_ABOUT, "&About..."); menuFile->AppendSeparator( ); menuFile->Append(ID_QUIT, "E&xit"); wxMenuBar *menuBar = new wxMenuBar; menuBar->Append(menuFile, "&File"); SetMenuBar(menuBar); CreateStatusBar( ); SetStatusText("Welcome to wxWidgets"); } Frame Constructor create a menu object

BasicFrame::BasicFrame(const wxChar *title, int xpos, int ypos, int width, int height) : wxFrame( (wxFrame *)NULL, -1, title, wxPoint(xpos, ypos), wxSize(width, height)) { wxMenu *menuFile = new wxMenu; menuFile->Append(ID_ABOUT, "&About..."); menuFile->AppendSeparator( ); menuFile->Append(ID_QUIT, "E&xit"); wxMenuBar *menuBar = new wxMenuBar; menuBar->Append(menuFile, "&File"); SetMenuBar(menuBar); CreateStatusBar( ); SetStatusText("Welcome to wxWidgets"); } Frame Constructor Define the menu items in the menu About Exit generate an event with this name

BasicFrame::BasicFrame(const wxChar *title, int xpos, int ypos, int width, int height) : wxFrame( (wxFrame *)NULL, -1, title, wxPoint(xpos, ypos), wxSize(width, height)) { wxMenu *menuFile = new wxMenu; menuFile->Append(ID_ABOUT, "&About..."); menuFile->AppendSeparator( ); menuFile->Append(ID_QUIT, "E&xit"); wxMenuBar *menuBar = new wxMenuBar; menuBar->Append(menuFile, "&File"); SetMenuBar(menuBar); CreateStatusBar( ); SetStatusText("Welcome to wxWidgets"); } Frame Constructor Define a MenuBar object

BasicFrame::BasicFrame(const wxChar *title, int xpos, int ypos, int width, int height) : wxFrame( (wxFrame *)NULL, -1, title, wxPoint(xpos, ypos), wxSize(width, height)) { wxMenu *menuFile = new wxMenu; menuFile->Append(ID_ABOUT, "&About..."); menuFile->AppendSeparator( ); menuFile->Append(ID_QUIT, "E&xit"); wxMenuBar *menuBar = new wxMenuBar; menuBar->Append(menuFile, "&File"); SetMenuBar(menuBar); CreateStatusBar( ); SetStatusText("Welcome to wxWidgets"); } Frame Constructor About Quit File Store the Menu object in the MenuBar and label it.

BasicFrame::BasicFrame(const wxChar *title, int xpos, int ypos, int width, int height) : wxFrame( (wxFrame *)NULL, -1, title, wxPoint(xpos, ypos), wxSize(width, height)) { wxMenu *menuFile = new wxMenu; menuFile->Append(ID_ABOUT, "&About..."); menuFile->AppendSeparator( ); menuFile->Append(ID_QUIT, "E&xit"); wxMenuBar *menuBar = new wxMenuBar; menuBar->Append(menuFile, "&File"); SetMenuBar(menuBar); CreateStatusBar( ); SetStatusText("Welcome to wxWidgets"); } Frame Constructor Make the MenuBar object the currently active menu bar.

BasicFrame::BasicFrame(const wxChar *title, int xpos, int ypos, int width, int height) : wxFrame( (wxFrame *)NULL, -1, title, wxPoint(xpos, ypos), wxSize(width, height)) { wxMenu *menuFile = new wxMenu; menuFile->Append(ID_ABOUT, "&About..."); menuFile->AppendSeparator( ); menuFile->Append(ID_QUIT, "E&xit"); wxMenuBar *menuBar = new wxMenuBar; menuBar->Append(menuFile, "&File"); SetMenuBar(menuBar); CreateStatusBar( ); SetStatusText("Welcome to wxWidgets"); } Frame Constructor Create a StatusBar object

BasicFrame::BasicFrame(const wxChar *title, int xpos, int ypos, int width, int height) : wxFrame( (wxFrame *)NULL, -1, title, wxPoint(xpos, ypos), wxSize(width, height)) { wxMenu *menuFile = new wxMenu; menuFile->Append(ID_ABOUT, "&About..."); menuFile->AppendSeparator( ); menuFile->Append(ID_QUIT, "E&xit"); wxMenuBar *menuBar = new wxMenuBar; menuBar->Append(menuFile, "&File"); SetMenuBar(menuBar); CreateStatusBar( ); SetStatusText("Welcome to wxWidgets"); } Frame Constructor Store this text in the status bar

The Event Handlers void BasicFrame::OnQuit(wxCommandEvent& event) { Close(TRUE); } void BasicFrame::OnAbout(wxCommandEvent& event) { wxMessageBox("The Hello World Sample", "About Hello World", wxOK | wxICON_INFORMATION); } Closes the window and terminates the application.

Finishing Touches enum { ID_QUIT = 1, ID_ABOUT }; Use an enumeration to define event names IMPLEMENT_APP(BasicApplication) This macro starts the Windows event loop running

Write the code using the minGW Compiler This code is available on the course web site as part of Lab #6.