Difference between revisions of "OOP Class9"
esse quam videri
Line 26: | Line 26: | ||
MessageBox.Show("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> | </csharp> | ||
Line 37: | Line 91: | ||
If you need to add any supporting methods or properties that are not on the diagram feel free. | If you need to add any supporting methods or properties that are not on the diagram feel free. | ||
+ | |||
Revision as of 15:33, 26 June 2008
Contents
Motorvehicle Diagram
http://iam.colum.edu/oop/browser/browser.aspx?f=/classsource/class7/MotorvehicleRace
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
use Pair Programming to make tests and classes from the following UML
If you need to add any supporting methods or properties that are not on the diagram feel free.
Test Student() Jeff Meyers says hello. StudentDiagram.Student Jeff Meyers StudentID = 0000 0 Courses Test Student("Matina" , "Navratilova" ) Matina Navratilova says hello. StudentDiagram.Student Matina Navratilova StudentID = 0000 0 Courses Test Student("Dan", "Rockwood") Dan Rockwood says hello. StudentDiagram.Student Dan Rockwood StudentID = 0000 0 Courses Make Some Course CourseName: Object Oriented Programming CourseName: 36-1300 Add Course StudentDiagram.Student Dan Rockwood StudentID = 0000 5 Courses CourseName: Object Oriented Programming CourseName: 36-1300 CourseName: Media Theory and Design 1 CourseName: 36-1000 CourseName: Media Theory and Design 2 CourseName: 36-2000 CourseName: English 101 CourseName: 52-1000 CourseName: Gym 101 CourseName: 11-1111 StudentDiagram.Student Dan Rockwood StudentID = 0000 4 Courses CourseName: Object Oriented Programming CourseName: 36-1300 CourseName: Media Theory and Design 1 CourseName: 36-1000 CourseName: English 101 CourseName: 52-1000 CourseName: Gym 101 CourseName: 11-1111 StudentDiagram.Student Dan Rockwood StudentID = 0000 5 Courses CourseName: Object Oriented Programming CourseName: 36-1300 CourseName: Media Theory and Design 1 CourseName: 36-1000 CourseName: test 101 CourseName: 00-0000 CourseName: English 101 CourseName: 52-1000 CourseName: Gym 101 CourseName: 11-1111 Test Instructor StudentDiagram.Instructor Edna Krabappel FacultyID = 0000 1 Course CourseName: English 101 CourseName: 52-1000 Test Pencil StudentDiagram.Pencil.isSharp = True Dan has no pencil StudentDiagram.Pencil.isSharp = True All work and no play makes Dan a dull student. StudentDiagram.Pencil.isSharp = False All work and no play makes Dan a dull student. StudentDiagram.Pencil.isSharp = False