Presentation is loading. Please wait.

Presentation is loading. Please wait.

© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 20.1 Test-Driving the Shipping Hub Application.

Similar presentations


Presentation on theme: "© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 20.1 Test-Driving the Shipping Hub Application."— Presentation transcript:

1 © Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 20.1 Test-Driving the Shipping Hub Application 20.2 Package Class 20.3 Using Properties TabIndex and TabStop 20.4 Using Access Keys 20.5 Collections 20.6 Shipping Hub Application: Using Class ArrayList 20.7 foreach Repetition Statement 20.8 Wrap-Up Tutorial 20 – Shipping Hub Application Introducing Collections, the foreach Statement and Access Keys

2 © Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 2 Objectives In this tutorial, you will learn to: –Create and manipulate an ArrayList object. –Set the TabStop and TabIndex properties of a control. –Create an access key for a control. –Use a foreach loop to iterate through an ArrayList.

3 © Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 3 20.1 Test-Driving the Shipping Hub Application

4 © Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 4 20.1 Test-Driving the Shipping Hub Application Figure 20.1 Shipping Hub application when first run. Run the Shipping Hub application – Debug > Start

5 © Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 5 20.1 Test-Driving the Shipping Hub Application Figure 20.2 Scanning a new package. Click Scan New Button Click in Address: TextBox and type 318 Some Street

6 © Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 6 20.1 Test-Driving the Shipping Hub Application Figure 20.3 Pressing the Tab key moves the cursor to the next TextBox. Cursor now appears in the City : TextBox

7 © Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 7 20.1 Test-Driving the Shipping Hub Application Figure 20.4 Viewing all packages going to South Carolina. You can view all Package ID’s by state using the ComboBox

8 © Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 8 20.2 Package Class

9 © Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 9 20.2 Package Class Figure 20.6 Solution Explorer with Package.cs added. Package class added to the ShippingHub project

10 © Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 10 20.3 Using Properties TabIndex and TabStop TabIndex and access keys – Requires only the keyboard (allows user to avoid constantly switching between using the mouse and keyboard).

11 © Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 11 20.3 Using Properties TabIndex and TabStop Figure 20.7 Setting the TabIndex properties using the Tab Order view of the Shipping Hub application. TabIndex boxes (not modified) TabIndex box set to zero Set TabStop property to true for controls that receive user input and false for the other controls

12 © Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 12 20.3 Using Properties TabIndex and TabStop Figure 20.8 Tab Order view of the Shipping Hub application. Set the TabIndex properties by clicking each control in the order indicated

13 © Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 13 20.4 Using Access Keys Figure 20.9 Creating an access key. Using the & symbol to create an access key (there is no space between & and S ) Access key letter underlined

14 © Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 14 20.5 Collections Collections –Used to store groups of related objects –Aid in storage and organization of data, requiring no knowledge of how they work. ArrayList –Dynamic resizing capability Grow and shrink according to storage needs –Contained in Collections namespace

15 © Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 15 20.6 Shipping Hub Application:Using Class ArrayList

16 © Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 16 20.6 Shipping Hub Application:Using Class ArrayList

17 © Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 17 20.6 Shipping Hub Application:Using Class ArrayList

18 © Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 18 20.6 Shipping Hub Application:Using Class ArrayList Figure 20.11 Declaring the ArrayList reference. Declaring an ArrayList reference Accessing ArrayList – Use the member-access operator (. ) OR – Member of System.Collections namespace

19 © Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 19 20.6 Shipping Hub Application:Using Class ArrayList Figure 20.12 Creating an ArrayList object. Creating the ArrayList reference

20 © Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 20 20.6 Shipping Hub Application:Using Class ArrayList Figure 20.13 Creating a Package object. Create a new Package object with a unique ID

21 © Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 21 20.6 Shipping Hub Application:Using Class ArrayList Figure 20.14 Displaying the package’s number and arrival time. Displaying arrival time and package ID number in Label s ToString method returns value representing object as a string – Example: 11/11/2002 9:34:00 AM

22 © Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 22 20.6 Shipping Hub Application:Using Class ArrayList Figure 20.15 Adding a package to the ArrayList. Adding a Package object to an ArrayList An Object’s position in ArrayList is called an index – Index of first object is zero

23 © Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 23 20.6 Shipping Hub Application:Using Class ArrayList Figure 20.16 Removing a package from the ArrayList. Removing the current package from the ArrayList

24 © Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 24 20.6 Shipping Hub Application:Using Class ArrayList Figure 20.17 Changing the Edit Button to display Update. Using code to change the text displayed on a Button

25 © Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 25 20.6 Shipping Hub Application:Using Class ArrayList Figure 20.18 Removing and inserting a package to update data. Updating the ArrayList with new package information

26 © Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 26 20.6 Shipping Hub Application:Using Class ArrayList Figure 20.19 Setting the Button ’s Text property back to Edit. Using code to display the text on the Button

27 © Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 27 20.6 Shipping Hub Application:Using Class ArrayList Figure 20.20 Retrieving a package from the ArrayList. Retrieving a Package object from an ArrayList

28 © Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 28 20.6 Shipping Hub Application:Using Class ArrayList Figure 20.21 Displaying the package data in the Form ’s controls. Displaying data stored in the Package object

29 © Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 29 20.7 foreach Repetition Statement foreach ( Package objPackage in objArrayList ) { lstPackages.Items.Add( objPackage.PackageNumber ); } The foreach statement requires both a collection type and an element – Collection type : specifies the array or collection through which you wish to iterate – Element : Use to store a reference to a value in the collection type

30 © Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 30 20.7 foreach Repetition Statement Figure 20.22 UML activity diagram for foreach repetition statement.

31 © Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 31 20.7 foreach Repetition Statement Figure 20.23 Writing a foreach statement. foreach header

32 © Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 32 20.7 foreach Repetition Statement Figure 20.24 Displaying all packages going to selected state. Displaying package ID numbers only for packages destined for the specified state

33 Outline © Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 33 ShippingHub.cs (1 of 15)

34 Outline © Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 34 ShippingHub.cs (2 of 15)

35 Outline © Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 35 ShippingHub.cs (3 of 15)

36 Outline © Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 36 ShippingHub.cs (4 of 15)

37 Outline © Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 37 ShippingHub.cs (5 of 15) Use a Random object to generate a random number for package IDs Initially, there are no objects in the ArrayList so set the position to zero

38 Outline © Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 38 ShippingHub.cs (6 of 15)

39 Outline © Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 39 ShippingHub.cs (7 of 15) Display package ID numbers in ListBox if the state names match

40 Outline © Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 40 ShippingHub.cs (8 of 15) When the user clicks the NEXT > Button, increment the position. If the position was the last object in the array, set the position to zero When the user clicks the < BACK Button, decrement the position. If the position was zero, set the position to the last object in the ArrayList

41 Outline © Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 41 ShippingHub.cs (9 of 15) Load the next package, update m_intPosition as necessary

42 Outline © Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 42 ShippingHub.cs (10 of 15)

43 Outline © Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 43 ShippingHub.cs (11 of 15)

44 Outline © Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 44 ShippingHub.cs (12 of 15) Retrieve data from user, and store it in the Package object

45 Outline © Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 45 ShippingHub.cs (13 of 15) Enable or disable Buttons depending on value of blnState

46 Outline © Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 46 ShippingHub.cs (14 of 15) Defining the SelectedIndexChanged event of a ComboBox

47 Outline © Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 47 ShippingHub.cs (15 of 15)


Download ppt "© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 20.1 Test-Driving the Shipping Hub Application."

Similar presentations


Ads by Google