Event-Based Programming Using Top-Down Design and Stepwise Refinement. AJAX Programming for the World Wide Web



Similar documents
JavaScript By: A. Mousavi & P. Broomhead SERG, School of Engineering Design, Brunel University, UK

Web Design Basics. Cindy Royal, Ph.D. Associate Professor Texas State University

Web Development CSE2WD Final Examination June (a) Which organisation is primarily responsible for HTML, CSS and DOM standards?

Overview. In the beginning. Issues with Client Side Scripting What is JavaScript? Syntax and the Document Object Model Moving forward with JavaScript

Short notes on webpage programming languages

Client-side Web Engineering From HTML to AJAX

Website Planning Checklist

Chapter 1 Programming Languages for Web Applications

Distance Examination using Ajax to Reduce Web Server Load and Student s Data Transfer

AJAX The Future of Web Development?

WHITEPAPER. Skinning Guide. Let s chat Velaro info@velaro.com by Velaro

Script Handbook for Interactive Scientific Website Building

Web Building Blocks. Joseph Gilbert User Experience Web Developer University of Virginia Library

Performance Testing for Ajax Applications

Web Design Specialist

Outline. CIW Web Design Specialist. Course Content

Mobile Web Applications. Gary Dubuque IT Research Architect Department of Revenue

CREATING A NEWSLETTER IN ADOBE DREAMWEAVER CS5 (step-by-step directions)

A send-a-friend application with ASP Smart Mailer

Dreamweaver CS4 Day 2 Creating a Website using Div Tags, CSS, and Templates

SUBJECT CODE : 4074 PERIODS/WEEK : 4 PERIODS/ SEMESTER : 72 CREDIT : 4 TIME SCHEDULE UNIT TOPIC PERIODS 1. INTERNET FUNDAMENTALS & HTML Test 1

HTML5 and CSS3 Part 1: Using HTML and CSS to Create a Website Layout

IT3504: Web Development Techniques (Optional)

Citrix StoreFront. Customizing the Receiver for Web User Interface Citrix. All rights reserved.

How to Display Weather Data on a Web Page

Contents. Introduction Downloading the Data Files... 2

ITNP43: HTML Lecture 4

Introduction to web development and JavaScript

IT3503 Web Development Techniques (Optional)

Web Design & Development - Tutorial 04

HTML CSS Basic Structure. HTML Structure [Source Code] CSS Structure [Cascading Styles] DIV or ID Tags and Classes. The BOX MODEL

Web Design and Databases WD: Class 7: HTML and CSS Part 3

Software Requirements Specification For Real Estate Web Site

1Lesson 1: Overview of Web Design Concepts Objectives

HTML TIPS FOR DESIGNING

JavaScript: Introduction to Scripting Pearson Education, Inc. All rights reserved.

Web Design I. Spring 2009 Kevin Cole Gallaudet University

Web Development 1 A4 Project Description Web Architecture

Website Login Integration

An introduction to creating Web 2.0 applications in Rational Application Developer Version 8.0

Web Reporting by Combining the Best of HTML and SAS

CIS 467/602-01: Data Visualization

Building Ajax Applications with GT.M and EWD. Rob Tweed M/Gateway Developments Ltd

The purpose of jquery is to make it much easier to use JavaScript on your website.

DESIGNING HTML HELPERS TO OPTIMIZE WEB APPLICATION DEVELOPMENT

Introduction to Web Design Curriculum Sample

Slide.Show Quick Start Guide

Outline of CSS: Cascading Style Sheets

Chapter 1. Introduction to web development

Dreamweaver CS5. Module 1: Website Development

OIT 307/ OIT 218: Web Programming

WIRIS quizzes web services Getting started with PHP and Java

Embedding a Data View dynamic report into an existing web-page

COURSE SYLLABUS EDG 6931: Designing Integrated Media Environments 2 Educational Technology Program University of Florida

Chapter 13 Computer Programs and Programming Languages. Discovering Computers Your Interactive Guide to the Digital World

Advanced Web Design. Zac Van Note.

Debugging JavaScript and CSS Using Firebug. Harman Goei CSCI 571 1/27/13

COURSE OUTLINE FACULTY OF INFORMATION AND COMMUNICATION TECHNOLOGY UNIVERSITI TEKNIKAL MALAYSIA MELAKA

COMMONWEALTH OF PENNSYLVANIA DEPARTMENT S OF Human Services, INSURANCE, AND AGING

MASTERTAG DEVELOPER GUIDE

How to Properly Compose HTML Code : 1

How to code, test, and validate a web page

What is CSS? Official W3C standard for controlling presentation Style sheets rely on underlying markup structure

Further web design: HTML forms

Making Responsive s

Web Design Technology

Basics of HTML (some repetition) Cascading Style Sheets (some repetition) Web Design

WEB DEVELOPMENT IA & IB (893 & 894)

1 of 8 9/14/2011 5:40 PM

Client Side Customisation of Web Pages

Programming exercises (Assignments)

10CS73:Web Programming

Entrance exam for PBA in Web Development

Style & Layout in the web: CSS and Bootstrap

Interactive Data Visualization for the Web Scott Murray

Advanced Web Development SCOPE OF WEB DEVELOPMENT INDUSTRY

TIME SCHEDULE OBJECTIVES

PLAYER DEVELOPER GUIDE

Differences between HTML and HTML 5

Tutorial: Building a Dojo Application using IBM Rational Application Developer Loan Payment Calculator

Programming in HTML5 with JavaScript and CSS3

JavaScript: Control Statements I

Adolfo G. Nasol The Bethel Educational Support and Technology Inc.

Designing HTML s for Use in the Advanced Editor

Web Content Management System Powered by Ajax

Chapter 10: Multimedia and the Web

Microsoft Expression Web Quickstart Guide

Chapter 2 HTML Basics Key Concepts. Copyright 2013 Terry Ann Morris, Ed.D

Visualizing a Neo4j Graph Database with KeyLines

It is highly recommended that you are familiar with HTML and JavaScript before attempting this tutorial.

JOB READY ASSESSMENT BLUEPRINT WEB DESIGN - PILOT. Test Code: 3750 Version: 01

WWW. World Wide Web Aka The Internet. dr. C. P. J. Koymans. Informatics Institute Universiteit van Amsterdam. November 30, 2007

Lesson Review Answers

Create Webpages using HTML and CSS

Internet Technologies_1. Doc. Ing. František Huňka, CSc.

CSS for Page Layout. Key Concepts

CSC309 Winter 2016 Lecture 3. Larry Zhang

Designing The User Experience AIGA Design Camp

HTML Tables. IT 3203 Introduction to Web Development

Implementing Specialized Data Capture Applications with InVision Development Tools (Part 2)

Transcription:

Event-Based Programming Using Top-Down Design and Stepwise Refinement AJAX Programming for the World Wide Web By Dave McGuinness Urangan State High School QSITE Conference 2009 IPT Strand

TRADITIONAL WEB APPLICATION PROGRAMMING... 3 AJAX WHAT IS IT?... 3 SPA... 3 AJAX... 3 AJAX / SPA WHY USE IT?... 4 AJAX/SPA WHAT DO YOU NEED?... 4 AJAX = DOM + XHTML + CSS + JAVASCRIPT + PHP + MYSQL... 5 EXAMPLES... 6 MOWING: AN EVENT-BASED WEB PROGRAMMING EXAMPLE... 6 Top-Down Design... 6 Pseudocode... 7 HTML... 8 Javascript... 10 USEFUL TEXTS... 11

Your goal when designing software should be to think about as little as possible at one time. An implementation derived from such a design will tend to be composed of small, manageable "chunks" that relate to problem concepts or tasks are easier to write easier to understand have fewer undesirable dependencies or side-effects on other areas of code University of San Francisco Terence Parr -Associate professor, Computer Science Traditional Web Application Programming Traditionally, web programming involves presenting something like an input form to the user, which is submitted to a separate page which loads and acts on the data in the input page. This causes the user sit through annoying page refreshes as new pages are loaded. While the page is reloading, no useful work can be done in the browser window. Such applications tend to be a little static and lack useful response to user input. They can be said to be lacking in interactivity. AJAX What is it? SPA Single Page Application is a term used to describe browser-based programming that contains the complete user interface within one page, without the need for page refreshes. This approach provides the user with a more desktop-centric experience which is more immediate. While Firefox and IE7/8 refresh much faster than IE6, there is still an annoying delay at virtually every step of the traditional formbased approach to web-programming. The SPA application should allow the user to forget that they are remote from the experience and just get on with their business. This is particular true of game applications. AJAX Asynchronous Javascript And XML most commonly uses a range of reasonably mature technologies to provide a useful client-side programmable interface within an internet browser. Careful selection of the relevant technologies can provide a rich multimedia experience on a 2-D level. The term, AJAX, has generally been broadened to include any type of asynchronous programming technique. AJAX is best used with the XHTML 1.0 standard which extends HTML 4.01 to standardise on an XML(eXtensible Markup Language) compliant document model. XHTML is used to outline the basic structure of the document CSS (Cascading Style Sheets) standard is used to outline the appearance of the page Javascript programming language (standardised by W3C as ECMAScript) is used to manipulate the page via the DOM (Document Object Model).

AJAX relies on an un-planned use of the XMLHttpRequest object of the browser available in IE, but part of all browsers. This allows a browser page to request data from the server and be notified when it becomes available. Then the application parses the data to provide output to page via Javascript. This allows the user to go on using the application while the program updates as necessary in the background. While the original intent of the AJAX request was to return XML data, but in fact, the technology is not limited to just this kind of text document. AJAX/PHP AJAX can be used to call PHP scripts. The HTML output of the PHP scripts, including any data retrieved from a web server-based DBMS (such as MySQL), can be inserted into the page to create new content or replace existing content. If the developer is already familiar with, and indeed has already developed a substantial code-base in, PHP then progress to useful AJAX development is very smooth. AJAX / SPA Why use it? TCO Total Cost of Ownership = zero dollars. Mozilla Firefox is free. Many suitable text editors, starting with Notepad.exe are free. No more software is required. MS Visual Web Developer Express Edition which is roughly equivalent to Dreamweaver CS3 is available for free download from Microsoft.com Clear and easily accessible standards; all readily available from websites. The HTML, CSS, XHTML, XML, DOM, and ECMA standards are all maintained by CERN at www.w3c.org. Downloadable references are available. The Mozilla http://www.openajax.org/ Project also provides very useful references for Javascript and DOM. PHP and MySQL are open-source, free products with high levels of on-line support. Narrow frame of reference and limited environment make AJAX more accessible for students. It does not overwhelm with gadgets like VB or Delphi. Students switching from the Delphi IDE immediately were more comfortable and "felt" that the work was easier. This is only a perception, but a very important one when considering the benefits of scaffolding student work. Everything has to be done within the bounds of a normal web page. Surprisingly, very useful applications and entertaining games can be created in this way. The environment is definitely more than sufficient for a secondary school IT program. Clearer separation of interface design from program code, e.g. concepts such as syntax and layout of code can be learned in the simpler and more forgiving environment of HTML/CSS, then enhanced by upgrading to XHTML, before venturing into the more daunting area of coding where students tend to focus on functionality and the important issues of meaningful identifiers and readable code tends to get lost in the confusion. AJAX/SPA What do you need? 1. A text editor, most preferably with syntax highlighting and a multiple document interface. ConTEXT (http://www.context.cx) is the best one I have seen so far. It is freeware and readily available. Alternatively, Adobe Dreamweaver or Microsoft Visual Web Developer are useful syntaxhighlighted IDEs, especially the MS product which is available free. VWD does not natively support PHP at this stage, although it does a very nice job of HTML/CSS and Javscript (which it still calls Jscript). VWD has very nice code-completion in the script editor, which Dreamweaver does not. 2. A standards-compliant browser, like Mozilla Firefox, definitely not IE, not even version 7, which still does not implement the CSS standard correctly and drives students mad with paranoid defence mechanisms. Firefox 3.5 is very compliant and includes some very useful features, including the DOM Inspector and a very helpful Javascript Error Console. Firefox 3.5 also supports some

elements of HTML 5 including the very useful <audio> tag which allows native playback of wav files. This, in particular, is very useful for student projects. 3. An extension of the Firefox interface called the Web Developers Toolbar adds some brilliant functionality to Firefox that makes it the browser of choice for web development. AJAX = DOM + XHTML + CSS + Javascript + PHP + MySQL AJAX can be organised logically by separating code into relevant files. Because the interface is built on the Document Object Model within the browser window, the DOM is the foundation code. The layout of the application in the browser window is built-in HTML. Students will need a working knowledge of HTML structures before attempting AJAX. Latest versions of Javascript require dynamically created code to meet the XHTML standard or errors may be thrown by the interpreter. It follows that it is a good idea to insist that students follow the more stringent syntax of XHTML from the beginning to avoid such problems later. Understanding of the TABLE, DIV and SPAN elements is important as these give complete control over location and movement on the page. Once students have mastered HTML, CSS presentation should be added in, in-line, and in a separate.css file. While in-line stylesheets work fine, the clear organisational separation of a css file can be a useful concept the flows on to further work. Javascript code should also be added mainly in a separate file for clear separation of function from layout. Where necessary it is useful to place some code in-line, but a much more useful construct is to use a topdown design approach to link Javascript functions in the.js file to events triggered by the interface. Once students have mastered the basis of the three coding elements, you can then move on to developing basic applications to demonstrate the use of sequence, selection, and iteration. Beyond that, application development should be taught via top-down design and step-wise refinement approach. I recommend using a design tool like Inspiration or Dia to develop a block diagram for the topdown design and Pseudocode the step-wise refinement. Examples of these are available from the workshop resources at http://www.mcgoo.com.au.

Examples Mowing: An Event-Based Web Programming Example This example is based on an exercise in the textbook, Simple Program Design (Robertson). This text focuses on algorithm design theory with no specific programming language used. The approach to algorithm design fits very well with the SPA/AJAX web programming environment. In this program, the user inputs dimensions for a house block and then is able to calculate how long it will take to mow. Top-Down Design Evt txtblocklength onchange Evt txtblockwidth onchange Evt txthouse Length onchange Evt txthousewidth onchange Evt btncalculatetime onclick Fn resetblock() Fn resethouse() Fn calctime() This top-down structure diagram has been developed in Dia which is an excellent application for diagramming structural ideas. Inspiration can also be used, but this is not free. Students are taught to develop a mock-up of the interface in HTML and CSS before attempting algorithm design. This requires them to think about HCI (Human Computer Interface). What will the game look like to the user? How will the user interact with the game? Events that represent all possible user interactions are linked to the interface, and then appropriate functions to handle these events are linked to the events.

Pseudocode The next step is to start stepwise refinement of the algorithm by using pseudocode. Inspiration allows the use to add notes to each node in the design tree. We use this note window to enter the pseudocode steps for the program. Later this pseudocode is copied as comments in to the Javascript code editor from which to develop the actual program code. In Outline View, Inspiration shows all of the notes as an outline of the design. Mowing Area Program txtblocklength onchange resetblock() Set divblock width = txtblockwidth value Set divblock length = txtblocklength value txtblockwidth onchange txthouselength onchange resethouse() Set divhouse width = txthousewidth value Set divhouse length = txthouselength value txthousewidth onchange btncalculatetime onclick calctime() set numblockwidth = txtblockwidth value as float set numblocklength = txtblocklength value as float set numhousewidth = txthousewidth value as float set numhouselength = txthouselength value as float set numblockarea = numblockwidth * numblocklength set numhousearea = numhousewidth * numhouselength set nummowingarea = numblockarea - numhousearea set nummowingtime = nummowingarea / 2 set stroutput = "The mowing time will be " + nummowingtime + " minutes." spnoutput innerhtml = stroutput

HTML <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>mowing Area Program</title> <script type="text/javascript" src="mowingarea.js" ></script> <style type="text/css"> <!--.style1 {font-family: Arial, Helvetica, sans-serif #divblock { position:absolute; width:357px; height:237px; z-index:1; left: 268px; top: 10px; background-color: #00FF00; padding:20px; #divhouse { position:absolute; width:89px; height:122px; z-index:2; left: 314px; top: 67px; background-color: #CC3300; padding:20px;.style2 { color: #FFFFFF; font-weight: bold; --> </style> </head> <body> <table width="245" border="0" cellpadding="6" cellspacing="2" bgcolor="#ffcc99"> <td colspan="2"><span class="style1">this program will calculate the time it takes to mow the grass.</span></td> <td width="120"><span class="style1">length of Block</span></td> <td width="95"><span class="style1"> <label> <input name="txtblocklength" title="block Length in metres" type="text" id="txtblocklength" size="8" onchange="resetblock() "/> </label> </span></td> <td><span class="style1">width of Block</span></td> <td><span class="style1"> <input name="txtblockwidth" title="block Width in metres" type="text" id="txtblockwidth" size="8" onchange="resetblock()"/> </span></td>

<td><span class="style1">length of House</span></td> <td><span class="style1"> <input name="txthouselength" title="house Length in metres" type="text" id="txthouselength" size="8" onchange="resethouse()"/> </span></td> <td><span class="style1">width of House</span></td> <td><span class="style1"> <input name="txthousewidth" title="house Width in metres" type="text" id="txthousewidth" size="8" onchange="resethouse()"/> </span></td> <td colspan="2"> <input type="submit" name="btncalculatetime" id="btncalculatetime" value="calculate Mowing Time" onclick="calctime()" /> </td> <td colspan="2"><span id="spnoutput" class="style1"> <label></label> Mowing Time: </span></td> </table> <div id="divblock"> <div align="center"><strong>block</strong></div> </div> <div class="style2" id="divhouse"> <div align="center"> <p> </p> <p>house</p> </div> </div> </body> </html>

Javascript // JavaScript Document // Mowing Area Program function getelement(strid) { var elttoget = document.getelementbyid(strid); return elttoget; // function resetblock() function resetblock() { // set divblock = getelement 'divblock' var divblock = getelement('divblock'); // Set divblock width = txtblockwidth value divblock.style.width = document.getelementbyid("txtblockwidth").value *10 + 'px'; // Set divblock length = txtblocklength value divblock.style.height = document.getelementbyid("txtblocklength").value *10 + 'px'; // function resethouse() function resethouse() { // set divhouse = getelement 'divhouse' var divhouse = getelement('divhouse'); // Set divhouse width = txthousewidth value divhouse.style.width = document.getelementbyid("txthousewidth").value *10 + 'px'; // Set divhouse length = txthouselength value divhouse.style.height = document.getelementbyid("txthouselength").value *10 + 'px'; // function calctime() function calctime() { // set numblockwidth = txtblockwidth value as float var numblockwidth = parsefloat(document.getelementbyid("txtblockwidth").value); // set numblocklength = txtblocklength value as float var numblocklength = parsefloat(document.getelementbyid("txtblocklength").value); // set numhousewidth = txthousewidth value as float var numhousewidth = parsefloat(document.getelementbyid("txthousewidth").value); // set numhouselength = txthouselength value as float var numhouselength = parsefloat(document.getelementbyid("txthouselength").value); // set numblockarea = numblockwidth * numblocklength var numblockarea = numblockwidth * numblocklength; // set numhousearea = numhousewidth * numhouselength var numhousearea = numhousewidth * numhouselength; // set nummowingarea = numblockarea - numhousearea var nummowingarea = numblockarea - numhousearea; // set nummowingtime = nummowingarea / 2 var nummowingtime = nummowingarea / 2; // set stroutput = "The mowing time will be " + nummowingtime + " minutes." var stroutput = ' The mowing time will be '; var stroutput += nummowingtime.tofixed(2) + ' minutes.'; // spnoutput innerhtml = stroutput var spnoutput = getelement('spnoutput'); spnoutput.innerhtml = stroutput;

Useful Texts Simple Program Design, Lesley Anne Robertson, Nelson Javascript: A Programmer's Companion from the Basics through DHTML, CSS, and DOM, Stefan Koch, Wiley. Javascript and AJAX, Tom Negrino and Dori Smith, Peachpit Press. Ajax Bible, Steven Holzner, Wiley. Spring into HTML and CSS, Molly E. Holzschlag, Addison-Wesley DHTML Utopia: Modern Web Design Using Javascript and DOM, Stuart Langridge, Sitepoint. HTML Utopia: Designing Without Tables Using CSS, Dan Shafer, Sitepoint. Information and Intelligent Systems, Kevin Savage, www.edit.net.au