com148x1 interactive programming lecture 7. topics today hci event handling

21
COM148X1 Interactive Programming Lecture 7

Upload: oscar-howard

Post on 13-Jan-2016

224 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: COM148X1 Interactive Programming Lecture 7. Topics Today HCI Event Handling

COM148X1Interactive Programming

Lecture 7

Page 2: COM148X1 Interactive Programming Lecture 7. Topics Today HCI Event Handling

Topics Today

HCI Event Handling

Page 3: COM148X1 Interactive Programming Lecture 7. Topics Today HCI Event Handling

HCI

Page 4: COM148X1 Interactive Programming Lecture 7. Topics Today HCI Event Handling

What is HCI

HCI stands for Human Computer Interaction, it is a field of study of designing user-friendly computer interface

There are different guidelines available included Apple, Microsoft … etc.

What is going to reference mainly from the guidelines provided from Apple

Page 5: COM148X1 Interactive Programming Lecture 7. Topics Today HCI Event Handling

User Interface Design

Use metaphors to present the concepts and features of the application Folder icon represents a directory in file system Recycle Bin icon represents useless files places

Reflect users’ mental model, satisfy users’ expectation of what to do and what to get Familiarity Simplicity Availability Discoverability

Page 6: COM148X1 Interactive Programming Lecture 7. Topics Today HCI Event Handling

User Interface Design (cont’)

Choose explicit action (e.g. show the command of selected object in menu) and implied action (e.g. drag a document icon to word processor) to match users’ expectation

Make user have a feeling of manipulating the data directly Allow users to rearrange the play-list of media

player by drag and drop operation

Page 7: COM148X1 Interactive Programming Lecture 7. Topics Today HCI Event Handling

User Interface Design (cont’)

Provide different level of controls to different level of users (novice to expert)

Provide feedback for users Show progress when application is going to take

a lengthy operation Consistence control among other applications

Windows’ close button always appears in top-right corner

Page 8: COM148X1 Interactive Programming Lecture 7. Topics Today HCI Event Handling

User Interface Design (cont’)

WYSIWYG (What Is See Is What You Get), keep the output consistency among different output devices

Allow users to undo their actions or warn them if something is going to change irreversible

Keep the user interface consist for the whole application Make the disabled menu items dimmer instead of

hide them away from user

Page 9: COM148X1 Interactive Programming Lecture 7. Topics Today HCI Event Handling

User Interface Design (cont’)

Keep user interface “good” looking Use high resolution icons Use anti-alias fonts Use large enough font size

Use model forms as less as possible (forms force focus on themselves such as alert windows)

Last but not the least, simple is good

Page 10: COM148X1 Interactive Programming Lecture 7. Topics Today HCI Event Handling

Test User Interface

Create prototype is a way to test if the user satisfy the user interface design

In prototype, the program not necessary truly do the job but it should be able to demonstrate the workflow when the application completed

Page 11: COM148X1 Interactive Programming Lecture 7. Topics Today HCI Event Handling

Event Handling

Page 12: COM148X1 Interactive Programming Lecture 7. Topics Today HCI Event Handling

Event

An event is an action which programmer can handle in code

An event can be generated by User (clicking a button) System (timer completed count down) Programmer (change the attribute of control)

In VB, different control expose different set of event for programmer to handle

Page 13: COM148X1 Interactive Programming Lecture 7. Topics Today HCI Event Handling

Event Handler

Event handler is the program which handle specific event(s)

Page 14: COM148X1 Interactive Programming Lecture 7. Topics Today HCI Event Handling

Create Event Handler

Step 1: in code view, select the control which generates event

Page 15: COM148X1 Interactive Programming Lecture 7. Topics Today HCI Event Handling

Create Event Handler (cont’)

Step 2: select the event of the control

Page 16: COM148X1 Interactive Programming Lecture 7. Topics Today HCI Event Handling

Create Event Handler (cont’)

Step 3: add code to handle the event

Page 17: COM148X1 Interactive Programming Lecture 7. Topics Today HCI Event Handling

Event Argument

The details of event is store in the EventArgs parameter

Different event will generate different kinds of EventArgs

Example of EventArgs EventArgs (no details provided) MouseEventArgs KeyEventArgs

Page 18: COM148X1 Interactive Programming Lecture 7. Topics Today HCI Event Handling

MouseEventArgs

Store the detail for MouseUp, MouseDown and MouseMove event

X – x coordinate of the mouse Y – y coordinate of the mouse Button – mouse button pressed Clicks – number of time the button was clicke

d Delta – the count of mouse wheel rotated

Page 19: COM148X1 Interactive Programming Lecture 7. Topics Today HCI Event Handling

KeyEventArgs

Store the details of KeyUp and KeyDown event

Alt – indicate if Alt key was pressed Control – indicate if Ctrl key was pressed Shift – indicate if Shift key was pressed KeyValue – the ASCII value of the pressed k

ey KeyCode – the code of the pressed key, usua

lly used for special keys detection

Page 20: COM148X1 Interactive Programming Lecture 7. Topics Today HCI Event Handling

Handle Multiple Events

Sometimes, it is convenient to handle multiple events by 1 event handler only

For this case, programmers can set different value of Tag of each control

Instead of create new event handler, append the event to the same event handler

Check the Tag of the control in event handler to identify the source of event

Page 21: COM148X1 Interactive Programming Lecture 7. Topics Today HCI Event Handling

Handle Multiple Event Example

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button2.Click

Dim b As Button = senderIf b.Tag = 1 Then

MsgBox(“Button 1 was pressed”)Else

MsgBox(“Button 2 was pressed”)End If

End Sub