Lecture 1 -responding To Events (vb 2008)

  • Uploaded by: curlicue
  • 0
  • 0
  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Lecture 1 -responding To Events (vb 2008) as PDF for free.

More details

  • Words: 1,425
  • Pages: 21
Application Programming 

Instructor Contact Information: 

John A. Rose, PhD (Assoc. Prof., APU ICT Institute)   

APU Office: Building BII, Fourth Floor E-mail: [email protected] Web-site: http://www.apu.ac.jp/~jarose/

Texts and Materials 

Primary Text: ‘Beginning VB.NET 2008’, Ch. 6 +  



Authors: Willis and Newsome Publisher: Wiley (2008)

Course Slides

Course Syllabus (tentative) 

Introduction: Building Windows Applications  



Dialog Boxes  



Lecture 1 – Responding to Events Lectures 2 – Creating Complex Applications Lecture 3 – Dialog Boxes (1) Lecture 4 – Dialog Boxes (2)

Creating Menus, Debugging, and Error Handling   

Lecture 5 – Creating Menus (1) Lecture 6 – Creating Menus (2) Lecture 7-8 – Debugging and Error Handling 



Midterm Examination

Object Oriented Programming     

Lecture 9 – Introduction to Objects Lecture 10 – Inheritance Lectures 11 – Polymorphism Lecture 12 – Shared Class Resources Lectures 12 – The .Net Classes 

Final Examination or Submission of Final Project

Course Methodology 

Lecture materials will be distributed at the beginning of each class…  



Followed by the Lecture. Where possible, examples will be presented with figures.

Each class is 95 minutes. After each lecture-period: 

students will then be provided time for practice (as time permits). 





For a total of 95 minutes (lecture + practice)

Teaching Assistants (TAs) will be available to answer questions during the practice period.

Note: substantial practice and work beyond the class period will be required.

Course Evaluation (Grading) 

The final grade (100%) will be awarded using the following criteria for evaluation (tentative): 

Attendance: 20%  



Mid-term Exam/Projects: 35%  





Students should come to each class. Note: points will be deducted for lateness or inappropriate behavior. Midterm: An In-class test After Lecture 7

Final Examination (comprehensive test): 45%

Important Notes about grading: 

Do all homework and In class programs (VB .NET Projects). 



As done in class / assigned.

Note carefully that the above is tentative. 

The above weights/items are subject to change.

Miscellaneous Instructions 

Students should bring their own data storage devices: 

Necessary for storing work: 

USB 2.0 Flash Memory (preferred)  



CD-RW 



650 or 700 MB

Floppy Disk 



64 MB or higher Windows XP Compatible

3.5’, 1.4 MB

These can be purchased in the APU Book Store.

Lecture 1: Responding to Events

Outline 

Introduction:  



Event Example: Multiple Button Events  



WinForms Responding to Events

Using the Class Name and Member Name combo boxes. Adding multiple button events.

Building a Simple Application: Char/Word Counter  

Using the controls we have… And a new control, the Radio Button.

Windows Forms 

The basic element of Applications are Windows: 

As we have seen, Windows support placement of controls…  



Windows support Rapid Application Development (RAD): 

Developers simply draw controls on the screen…  



The ‘Visual’ approach (e.g., VB .NET) We have used a blank window called the Design Window (Form1).

Non-visual: Need to code each Window / Control ‘from scratch’. 



Buttons to handle user requests Labels, TextBoxes, ListBoxes, etc for GUI-based Input/Output

Usually, 1000’s of lines of code required (e.g., Java)

In Visual Basic, windows are called ‘Forms’  

Sometimes also called ‘WinForms’ We have already been using Forms in our simple applications… 

Now, we will take a closer look at Forms and Form use. 



Including the use of multiple forms.

Our Goal: making fully-featured Windows applications.

Event-Driven Programming 

In GUI-based Programming: 

We build a user interface (GUI) to ease user communication... 



By painting controls on the Design Window.

Each control can recognize certain user actions  

Example: a click. In VB .NET, such recognizable actions are called events… 



We use this Event recognition capability to drive program behavior: 

By coding subroutines called event handlers: 

Sometimes called ‘action listeners’ (Java)… 





Which wait for a specific event, at a specific control.

These are identified by the ‘Handles’ keyword… 

which registers the event, for us.

Given occurrence of the registered event (Control, Event). 



In other languages (Java), the word ‘action’ is also used.

The Subroutine’s lines of code are then executed .

This model of programming is called ‘Event-Driven Programming’ 

Let’s take a closer look at the ‘event philosophy’… 

by setting up a button event.

Button Events: A Second Look 

Open up VB Studio .NET and make a new project… 

With a single ‘Welcome’ button:

The Class Name Combo Box 

Next, drop down the list in the Class Name combo box: 



The combo box options will appear, as shown above. 



At the top of the Code Window…

It mainly lists the Classes and Members added to the current project.

Here: 1. Form 1 is a Class (an Object definition) 

As denoted by its icon (three connected boxes: purple/blue/yellow)

2. The last two items are slightly indented… 

This means they are all related to Form1.

3. (Form1 Events) are a Events of Form1. 

This is denoted by its icon (a lightning bolt).

4. btnWelcome is a Member of Form1. 

This is denoted by its icon (a small blue box).

The Method Name Combo Box 

Next, drop down the list in the Method Name combo box: 



At the top right of the Code Window…

The items that appear depend on the Class Name combo box selection: 

Here, Form1 is selected at left… 



So, names of the Libraries, Classes, etc in the current project are listed at right.

Note that: 1. Selecting the (Declarations) entry takes you to the Class top… 

Where you can change the Class definition, and add members.

2. Items appear either bold (existing) or faint (not yet created). 

Here, the Finalize method can automatically be created by selecting it. 

We will not discuss Finalize until later...

3. Methods are denoted by a small purple square icon. 4. Libraries are denoted by an icon with 4 stacked books.

Adding more Event Handlers 

Next, select btnWelcome in the Class Name combo box: 

Only items related to btnWelcome now appear in the Method Name combo box:  Specifically, events are shown (icon: lightning bolt)... 



Note that existing events are shown in bold (Click)

Let’s use this combo box to add 2 more event handlers to btnWelcome… 



By selecting the events, MouseEnter and MouseLeave…  This creates two new, empty event handlers. Now, add the code below to the two new event handlers:

Adding Event Handlers (Test Function) 

Let’s test the function of our simple, 3-event button…

Program 2 – Char/Word Counting Tool 

Let’s practice by making a second application… 



A simple counting utility (tool)

Goal: Design a tool with the ability to accept input text, and: 

Ability 1: Count the characters in the input Text  





Using the property String.Length And the TextBox event handler TextChanged

Ability 2: Count the words in the input Text

To allow selection of these actions/abilities by the user: 

We use a new type of control, the Radio Button (rad) 

A user selecting a particular Radio Button sets its Checked property: 



Only 1 Radio Button can be checked, at one time, in a single group…  



RadioButton.Checked  True

In our case, our group is the entire Container called Form1 Note: We could also make ‘internal’ groups with Group Boxes.

First, lets make the GUI and program the Char. Counting ability:

Char/Word Counting Tool (Ability 1) 

First, construct the GUI and program the Character Counting ability: 

We need 3 Labels (lbl), 1 TextBox (txt), 2 Radio Buttons (rad), and 1 button (btn):

Char/Word Counting Tool (Ability 2) 

Again, our goal is to make a tool with two abilities: 

Ability 1: Count the characters in the input Text  





Using the property String.length And the TextBox event listener TextChanged

Ability 2: Count the words in the input Text

Now, let’s modify our tool to perform its second ability…

Counting Words (Step 1) 

First, let’s add a Function which counts the ‘words’ in an input string…

Counting Words (Step 2) 

Next, add a Function to UPDATE the GUI, for ALL counting activities…

Counting Words (Test Function)

Related Documents


More Documents from "curlicue"