Difference between revisions of "OOP Class9"

esse quam videri
Jump to: navigation, search
Line 1: Line 1:
 
[[Category:Object Oriented Programming]]
 
[[Category:Object Oriented Programming]]
 +
 +
==Review Coins==
 +
 +
?'s
 +
 +
==Review MotorVehicle==
 +
 +
?'s
 +
 +
==Motorvehicle Diagram==
 +
 +
[[Oop Motorvehicle Diagram]]
 +
 +
http://iam.colum.edu/oop/browser/browser.aspx?f=/classsource/class7/MotorvehicleRace
  
 
==Private instance data members - accessors==
 
==Private instance data members - accessors==
Line 57: Line 71:
 
</csharp>
 
</csharp>
  
==About aspx==
 
 
[[VS Web Projects]]
 
 
{{Anatomy of an aspx page}}
 
 
==Simple Aspx Page==
 
 
http://iam.colum.edu/oop/classsource/class8/Aspx/hello.aspx [http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class8/Aspx/hello.aspx hello.aspx]
 
 
http://iam.colum.edu/oop/classsource/class8/Aspx/hello2.aspx
 
[http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class8/Aspx/hello2.aspx hello2.aspx]
 
 
http://iam.colum.edu/oop/classsource/class8/Aspx/Label.aspx
 
[http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class8/Aspx/Label.aspx Label.aspx]
 
 
In class
 
Build three hello aspx pages similar to the ones above
 
 
==Dogs on the web==
 
[http://iam.colum.edu/oop/browser/browser.aspx?f=/classsource/class8/DogWeb DogWeb]
 
 
 
 
{{HTML and HTTP}}
 
 
 
http://iam.colum.edu/oop/classsource/class9/htmlForms.html [http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class9/htmlForms.html htmlForms.html - source]
 
 
==Courses on the Web==
 
[http://iam.colum.edu/oop/browser/browser.aspx?f=/classsource/class8/StudentWeb Student Web]
 
 
==Response Object==
 
 
Response.Write()
 
 
http://iam.colum.edu/oop/classsource/class10/Response/Response1.aspx
 
[http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class10/Response/Response1.aspx Response1.aspx - source]
 
 
Response.End()
 
 
http://iam.colum.edu/oop/classsource/class10/Response/Response2.aspx
 
[http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class10/Response/Response2.aspx Response2.aspx - source]
 
 
Response.Clear()
 
 
http://iam.colum.edu/oop/classsource/class10/Response/ResponseClear.aspx
 
[http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class10/Response/ResponseClear.aspx ResponseClear.aspx - source]
 
 
Response.Flush()
 
 
http://iam.colum.edu/oop/classsource/class10/Response/ResponseFlush.aspx
 
[http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class10/Response/ResponseFlush.aspx ResponseFlush.aspx - source]
 
 
 
===Debugging with response object===
 
 
Using the response buffer can be extreemely usefull for debugging. Sometime you may have to setup a small debug system to help catch errors in object that do not inherit from System.UI.Page.
 
 
Response.Flush()
 
 
http://iam.colum.edu/oop/classsource/class10/Response/ResponseDebug.aspx
 
[http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class10/Response/ResponseDebug.aspx ResponseDebug.aspx - source]
 
 
==Home Work==
 
 
Convert one of your classes to work as an aspx page.
 
 
Have a nice break....
 
 
 
 
 
==Web Forms==
 
Examples of Web Forms
 
 
http://iam.colum.edu/oop/classsource/class9/aspForms.aspx [http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class9/aspForms.aspx aspForms.aspx - Source]
 
 
'''todo''' examples of all the html elements and how they react to form submits
 
 
==Persisting Data==
 
 
===POST and GET===
 
 
http://iam.colum.edu/oop/browser/browser.aspx?f=/classsource/class9
 
 
an asps page posting to itself
 
 
'''GET'''
 
 
Simple get page
 
http://iam.colum.edu/oop/classsource/class9/simpleGet.html [http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class9/simpleGet.html source]
 
 
http://iam.colum.edu/oop/classsource/class9/simpleGet.aspx [http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class9/simpleGet.aspx source]
 
 
'''POST'''
 
 
Simple post page http://iam.colum.edu/oop/classsource/class9/simplePost.html [http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class9/simplePost.html source]
 
 
http://iam.colum.edu/oop/classsource/class9/simplePost.aspx [http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class9/simplePost.aspx source]
 
 
Simple post page http://iam.colum.edu/oop/classsource/class9/simplePostValues.html [http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class9/simplePostValues.html source]
 
 
http://iam.colum.edu/oop/classsource/class9/simplePostValues.aspx [http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class9/simplePostValues.aspx source]
 
 
 
'''ASP POSTBACK'''
 
 
http://iam.colum.edu/oop/classsource/class9/postBack.aspx [http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class9/postBack.aspx source]
 
 
{{ASPX csharp commands}}
 
 
==Home Work==
 
 
Create a web page with a button that uses your class.
 
 
 
==Motorvehicle Diagram==
 
 
[[Oop Motorvehicle Diagram]]
 
 
http://iam.colum.edu/oop/browser/browser.aspx?f=/classsource/class7/MotorvehicleRace
 
  
 
==Windows forms==
 
==Windows forms==

Revision as of 21:52, 22 June 2009


Review Coins

?'s

Review MotorVehicle

?'s

Motorvehicle Diagram

Oop Motorvehicle Diagram

http://iam.colum.edu/oop/browser/browser.aspx?f=/classsource/class7/MotorvehicleRace

Private instance data members - accessors

Microsoft has stared calling private variables with accessors Properties

Private class memebers the use get and set keyword to set and retrieve data. Get and set are known as accessor methods private members are helpful when you want to also do other things when a data member is changed or change the rutern value under certain conditions. C# Programmer's Reference - Accessors http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vclrfaccessorspg.asp. Lastly accessor also make read only and write only variables possible

<csharp>//private string color read/write private string color;

public string Color {

 get
 {
  return color;
 }
 set
 {
  color = value;
 }

}

//private string color read only private string color;

public string Color {

 get
 {
  return color;
 }

}</csharp>


Another property that is a good candidate for a private instance data member is the dogs age

<csharp> private string age;

public int Age {

 //age can only be accessed with get there is no set accessor
 //age must be set with HappyBirthday()
 get
 {
  return age;
 }

}

public int HappyBirthday() {

 age++;
 return age;

}


</csharp>


Windows forms

Events

events from a windows form or web page are handled by event handlers. Events are raised when a user interacts with interface elements and handled by the event handlers.


http://www.csharphelp.com/archives/archive253.html

Examaple of event handlers and classes

http://iam.colum.edu/oop/MotorvehicleRace.zip

<csharp> private void button1_Click(object sender, EventArgs e)

       {
           Console.WriteLine("button1 Clicked");
           MessageBox.Show("button1 Clicked");   
       }

</csharp>

Create a windows form with a button the uses your class.

<csharp> using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms;

namespace WindowsDog {

   public partial class Form1 : Form
   {
       Dog fido;
       
       public Form1()
       {
           InitializeComponent();
           fido = new Dog();
       }
       private void btnBark_Click(object sender, EventArgs e)
       {
           lblBark.Text = fido.Bark();
       }


       public class Dog 
       {
           public string Name;		// the dog's name
           public int Age;			// the dog's age
           public int Weight;			// the dog's weight
           public string BarkSound;	// the sound of the dog's bark
           public Dog()
           {
               BarkSound = "Woof!!!";
           }
           public string Bark()
           {
               return this.BarkSound;
           }
           public void Eat()
           {
               //put eat code here 
           }
       }	
   }

} </csharp>

Home Work

Put your class in a windows form. Use and event to call one of your methods.