1 / 44

Hoofdstuk 2

Hoofdstuk 2. Hallo, C# !. Soorten programma’s. Console- applicatie. Soorten programma’s. Console- applicatie Windows- applicatie. Soorten programma’s. Console- applicatie Windows- applicatie Web- applicatie. Soorten programma’s. Console- applicatie Windows- applicatie Web- applicatie

toshi
Télécharger la présentation

Hoofdstuk 2

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Hoofdstuk 2 Hallo, C# !

  2. Soorten programma’s • Console-applicatie

  3. Soorten programma’s • Console-applicatie • Windows-applicatie

  4. Soorten programma’s • Console-applicatie • Windows-applicatie • Web-applicatie

  5. Soorten programma’s • Console-applicatie • Windows-applicatie • Web-applicatie • Game

  6. Soorten programma’s • Console-applicatie • Windows-applicatie • Web-applicatie • Game • Applet

  7. Soorten programma’s • Console-applicatie • Windows-applicatie • Web-applicatie • Game • Applet • App

  8. Opbouw broncode • Opdrachten omhet geheugente veranderen • Opdrachten zijn gegroepeerd inmethoden • Methoden zijn gegroepeerd inklassen

  9. Soorten opdrachten • Toekennings -opdracht:verander het geheugen • Aanroep van een andere methode:voer eerst de opdrachten in die methode uit, en ga daarna verder waar je gebleven was en dat kunnen zelf ook weer aanroepenzijn van weer andere methodes... dus de “waar was ik gebleven” administratie is best ingewikkeld!

  10. Voorbeeld C#-programma using System; class Hallo { static void Main ( ) { Console.WriteLine("Hallo!"); Console.ReadLine( ); } } één klasse ...met éénmethode ...met tweeopdrachten accolades begrenzenklasse, resp. methode

  11. één van demethodes moetMain heten Main Klasse- en methode-header using System; class Hallo{ static void Main ( ) { Console.WriteLine("Hallo!"); Console.ReadLine( ); } } naam:bedacht doorde programmeur naam:bedacht doorde programmeur

  12. Opdracht: methode-aanroep using System; class Hallo { static void Main( ) { Console.WriteLine("Hallo!"); Console.ReadLine( ); } } opdrachten:aanroep vananderemethoden klasse waaruit de methode komt altijdeen punt naam van demethode overigedetails

  13. Klasse-bibliotheken using System; class Hallo { static void Main( ) { Console.WriteLine("Hallo!");Console.ReadLine( ); } } library-klassenmag jegebruiken... als je ze maaraangeeft inwelke libraryze staan

  14. Methode-header en -aanroep using System; class Hallo { static void Main( ) { Console.WriteLine("Hallo!"); Console.ReadLine( ); } } methode-header methode-aanroep

  15. compilatieeenheid library naam using ; klassedeclaratie Syntax en semantiek • Syntax:de vorm van het programma • Semantiek:wat het programmabetekent

  16. Syntax van klasse-declaratie klasse declaratie public private : naam class naam { member }

  17. Syntax van member member public private static type void naam ( type naam ) blok ,

  18. Syntax van blok blok declaratie { } opdracht

  19. Syntax van opdracht opdracht klasse naam methode naam ( expressie ) ; . , object expressie property naam += variabele = expressie ;

  20. Syntax van opdracht opdracht klasse naam methode naam ( expressie ) ; . , object expressie property naam += variabele = expressie ;

  21. Console-applicatie using System; class Hallo2 { static void Main ( ) { Console.WriteLine("Hallo!"); Console.ReadLine( ); } }

  22. Console-applicatie using System; class Hallo2 { static void Main ( ) { Console.WriteLine("Wat is je naam?"); naam = Console.ReadLine( ); } } Toekennings-opdrachtgeeft een waardeaan een variabele

  23. Console-applicatie using System; class Hallo2 { static void Main ( ) { string naam; Console.WriteLine("Wat is je naam?"); naam = Console.ReadLine( ); } } Declaratieintroduceert een variabelevan een bepaald type

  24. Console-applicatie using System; class Hallo2 { static void Main ( ) { string naam; Console.WriteLine("Wat is je naam?"); naam = Console.ReadLine( ); Console.WriteLine("Hallo, " + naam + "!"); } } gebruik vande variabele

  25. Console-applicatie using System; class Hallo2 { static void Main ( ) { string naam; Console.WriteLine("Wat is je naam?"); naam = Console.ReadLine( ); Console.WriteLine("Hallo, " + naam + "!"); Console.WriteLine("met " + naam.Length + " letters."); } } Property vaneen object

  26. Console-applicatie using System; class Hallo2 { static void Main ( ) { string naam; Console.WriteLine("Wat is je naam?"); naam = Console.ReadLine( ); Console.WriteLine("Hallo, " + naam + "!"); Console.WriteLine("met " + naam.Length + " letters."); Console.ReadLine( ); } }

  27. Syntax van opdracht opdracht klasse naam methode naam ( expressie ) ; . , object expressie property naam += variabele = expressie ;

  28. Syntax van opdracht opdracht klasse naam methode naam ( expressie ) ; . , object expressie property naam += toekenning variabele = expressie ;

  29. type declaratie klasse naam type naam ; int , string Syntax van declaratie

  30. Windows-applicatie using System.Windows.Forms; class HalloWin1 { static void Main ( ) { } } using System.Drawing; declaratie en toekenning van een variabele met type Form Form scherm; scherm = new Form( ); aanpassen vanattributen scherm.Text = "Hallo"; scherm.BackColor = Color.Yellow; scherm.Size = new Size(200,100); Application.Run(scherm); gebruik van de variabelebij aanroep van Run

  31. Syntax van opdracht opdracht klasse naam methode naam ( expressie ) ; . , object expressie property naam += variabele = expressie ;

  32. Syntax van opdracht opdracht klasse naam methode naam ( expressie ) ; . , object expressie property naam += variabele = expressie ;

  33. Windows-applicatie class HalloWin2 {static void Main ( ) { } } aanroep van deconstructor methode Form scherm; scherm = new Form( ); Application.Run(scherm); HalloForm scherm; scherm = new HalloForm( ); Application.Run(scherm); subklasse is eengespecialiseerde versie class HalloForm{ } definitie van deconstructor methode : Form public HalloForm( ) { } this.Text = "Hallo"; this.BackColor = Color.Yellow; this.Size = new Size(200,100);

  34. Windows-applicatie class HalloForm{ } : Form public HalloForm( ) { } this.Text = "Hallo"; this.BackColor = Color.Yellow; this.Size = new Size(200,100); Label groet; groet = new Label( ); groet.Text = "Hallo allemaal"; groet.Location = new Point(30,20); this.Controls.Add(groet);

  35. Syntax van opdracht opdracht klasse naam methode naam ( expressie ) ; . , object expressie property naam += variabele = expressie ;

  36. Syntax van opdracht opdracht klasse naam methode naam ( . object expressie property naam = property naam methode naam scherm . Size groet . Text naam . Length object expressie this.Controls . Add Console . WriteLine Application . Run static klasse naam Color . Yellow

  37. Static gewone methoden static methoden static Bewerken een object Bewerken geen object Aanroep:klasse . methode (…) Aanroep:object . methode (…) In de body van de definitie:this is dat object In de body van de definitie:this bestaat niet Voorbeeld: Voorbeeld: Controls.Add(groet); Application.Run(scherm); Constructormethoden zijn nooit static Main is altijd static

  38. Windows-applicatie class HalloForm{ } : Form public HalloForm( ) { } this.Text = "Hallo"; this.BackColor = Color.Yellow; this.Size = new Size(200,100); Label groet; groet = new Label( ); groet.Text = "Hallo allemaal"; groet.Location = new Point(30,20); this.Controls.Add(groet);

  39. Windows-applicatie class HalloForm{ } : Form public HalloForm( ) { } this.Text = "Hallo"; this.BackColor = Color.Yellow; this.Size = new Size(200,100); this.Paint += this.teken; “Event”-property Methode-naam,maar geen aanroep!

  40. Windows-applicatie class HalloForm{ } : Form public HalloForm( ) { } this.Text = "Hallo"; this.BackColor = Color.Yellow; this.Size = new Size(200,100); this.Paint += this.teken; } void teken( { Object o, PaintEventArgs pea ) pea. Graphics. DrawString( ); "Hallo!" , new Font("Tahoma", 30) , Brushes.Blue , 10, 10

  41. Windows-applicatie using System.Windows.Forms; class HalloWin3{ static void Main() { HalloForm scherm; scherm = new HalloForm(); Application.Run(scherm); } } class HalloForm : Form{ public HalloForm() { this.Text = "Hallo"; this.Paint += this.teken; } void teken(object o, PaintEventArgs p) { p.Graphics.DrawString( … ); } }

  42. Game-applicatie using System.Windows.Forms; using Microsoft.XNA.Framework; class HalloWin3{ static void Main() { HalloForm scherm; scherm = new HalloForm(); Application.Run(scherm); } } class HalloGame4{ static void Main() { HalloGame spel; spel = new HalloGame(); } } spel.Run(); class HalloForm : Form{ public HalloForm() { this.Text = "Hallo"; this.Paint += this.teken; } void teken(object o, PaintEventArgs p) { p.Graphics.DrawString( … ); } } class HalloGame : Game{ public HalloGame() { } } this.Window.Title = "Hallo"; override void Draw(GameTime t) { }

  43. Form vs. Game void teken(object o, PaintEventArgs pea) { gr.DrawString( ); } Graphics gr; gr = pea.Graphics; , new Font("Tahoma", 30) "Hallo!" , Brushes.Blue new Point( ) , 10, 20 override void Draw(GameTime gt) { } SpriteBatch sb; sb = new SpriteBatch(this.GraphicsDevice); sb.Begin(); sb.DrawString( ); this.Content.Load<SpriteFont>("Spelfont") , "Hallo!" gt.TotalRealTime.Milliseconds, 20) , new Vector2(10, 20) , Color.Blue sb.End();

  44. Content bij een Game this.Content.RootDirectory = "Hulpbestanden"; • Fonts, Achtergrondplaatjes, Geluiden… this.Content.Load<SpriteFont>("Spelfont") Hulpbestanden / Spelfont.spritefont <?xml version="1.0" encoding="utf-8"?> <XnaContent xmlns:Graphics="Microsoft.Xna.Framework.Content.Pipeline.Graphics"> <Asset Type="Graphics:FontDescription"> <Spacing>0</Spacing> <UseKerning>true</UseKerning> <Style>Regular</Style> <CharacterRegions><CharacterRegion><Start>&#32;</Start> <End>&#126;</End></CharacterRegion></CharacterRegions> </Asset> </XnaContent> <FontName></FontName> <Size></Size> Tahoma30

More Related