De presentatie wordt gedownload. Even geduld aub

De presentatie wordt gedownload. Even geduld aub

Meer constructormethodes in klasse Kleur { class Kleur } public byte Rood, Groen, Blauw; public Kleur( byte r, byte g, byte b ) { } Rood=r; Groen=g; Blauw=b;

Verwante presentaties


Presentatie over: "Meer constructormethodes in klasse Kleur { class Kleur } public byte Rood, Groen, Blauw; public Kleur( byte r, byte g, byte b ) { } Rood=r; Groen=g; Blauw=b;"— Transcript van de presentatie:

1 Meer constructormethodes in klasse Kleur { class Kleur } public byte Rood, Groen, Blauw; public Kleur( byte r, byte g, byte b ) { } Rood=r; Groen=g; Blauw=b; constructor-methode met parameters public Kleur( Kleur orig ) { } Rood=orig.Rood; Groen=orig.Groen; Blauw=orig.Blauw; constructor-methode die een kopie maakt public Kleur( string s ) { } constructor-methode die een string ontleedt string[ ] woorden = s.Split( ); Rood = woorden[0]; Groen = woorden[1]; Blauw = woorden[2]; Rood = byte.Parse( woorden[0] ); Groen = byte.Parse( woorden[1] ); Blauw = byte.Parse( woorden[2] ); array van strings handige methode van string

2 Static variabelen { class Kleur } public byte Rood, Groen, Blauw; static variabelen zitten niet in het object public static byte Max = 255; maar hebben er iets mee te maken public Kleur( ) { } Rood=Max; Groen=Max; Blauw=Max; constructor-methode

3 Static methoden { class Kleur } public byte Rood, Groen, Blauw; static variabelen zitten niet in het object public static byte Max = 255; maar hebben er iets mee te maken public Kleur( ) { } Rood=Max; Groen=Max; Blauw=Max; constructor-methode public static Kleur Parse( string s ) { } static methoden hebben geen object onderhanden return new Kleur(s); public static Kleur Geel = new Kleur(Max,Max,0); static variabele met de eigen klasse als type

4 Intent nIntent: bedoeling om een nieuwe activiteit te starten ueigen activiteit §Hallo §Teller ustandard §web-browser §text-sender

5 Intent: Hallo opstarten public class Multi : Activity { } Button b1, b2, b3, b4, b5, b6; public void klik1 (object o, EventArgs e) { } Intent i; i = new Intent (this, StartActivity(i); typeof(Hallo) ); i.PutExtra("wat", "Hallo!!!"); public class Hallo : Activity { } override void OnCreate(Bundle b) { base.OnCreate(b); } TextView t = new TextView(this); SetContentView(t); string s = Intent.GetStringExtra("wat"); t.Text = s; hier zijn 24 verschillende varianten van......maar net niet die je nodig hebt, bijv. Kleur i.PutExtra("kleur", oranje.ToString()); string s = Intent.GetStringExtra("kleur"); Kleur k = new Kleur(s);

6 Publieksvraag n//schrijf een static methode die telt hoe // vaak een symbool voorkomt in een string n//voorbeeld-aanroep: int n; n = Demo. Freq('e', "some text" ); n// hint: gebruik een for opdracht

7 Tel symbool-frequentie public static int Freq(char x, string s) { s[t]==x for (int t=0; t<s.Length; t++) if ( ) aantal++; int aantal; aantal = 0; return aantal; }

8 Tel symbool-frequentie public static int Freq(char x, string s) { s[t]==x for (int t=0; t<s.Length; t++) if ( ) aantal++; int aantal; aantal = 0; return aantal; } foreach ( char c in s ) c == x

9 Publieksvraag: Gelijkheid van Strings static bool Gelijk( string s, string t) { } return s==t; Maar dan zonder de bestaande operator == voor strings te gebruiken == voor char en int mag wel

10 Publieksvraag: Gelijkheid van Strings static bool Gelijk( string s, string t) { } int m = s.Length; int n = t.Length; for (i=0; i<m && i<n; i++) { } char c = s[i]; char d= t[i]; if (c!=d) return false; return m==n;

11 Gelijkheid van Strings static bool Equals( string s, string t) { } int m = s.Length; int n = t.Length; for (i=0; i<m && i<n; i++) { } char c = s[i]; char d= t[i]; if (c!=d) return false; return m==n; class String { } this.Length; this[i];

12 naamtype void () blok parameters methode member

13 naamtype void operator op () blok parameters methode member

14 Gelijkheid van Strings static Gelijk ( string s, string t) { } return s.Equals(t); operator == class String { }

15 Hoofdstuk 9.3-4 Arrays

16 nArray: rij genummerde variabelen tabel 0 1 2 3 4 length5 int [ ] tabel; new int [5];tabel = declaratie van een array creëren van het eigenlijke array-object

17 Gebruik van een array n’t zijn echte variabelen: tabel 0 1 2 3 4 Length 5 tabel [2] = 37; tabel[4] = tabel [2] + 5; 37 42 if (tabel.Length<10)... tabel.Length = 10; Length is een read-only property

18 Gebruik van een array nvariabele als index in de array tabel 0 1 2 3 4 Length5 tabel [0] = 42; tabel [1] = 42; tabel [2] = 42; tabel [3] = 42; tabel [4] = 42; 42 tabel [t] = 42; for (t=0; t<5; t++)

19 Array als parameter tabel 0 1 2 3 4 Length5 12 95 11 23 15 int Grootste ( int [ ] tabel ) { } int resultaat; return resultaat; if (tabel [t] > resultaat) resultaat = tabel [t]; for (t=0; t<tabel.Length; t++) int t; resultaat =tabel [0]; static

20 Syntax van array-type type int short sbyte long decimal double float char bool uint ushort byte ulong struct naam class naam object string waarde verwijzing [], array

21 Array van getallen tabel int [ ] tabel; new int [5];tabel = 0 1 2 3 4 Length 5

22 Array van struct-objecten tabel Color [ ] palet; new Color[5]; palet = 0 1 2 3 4 Length 5

23 Array van class-objecten tabel PointF [ ] plaatsen; new PointF[5]; tabel = 0 1 2 3 4 Length 5 for (int t=0; t<5; t++) plaatsen[t] = new PointF( );

24 string versus array nKlassen Type met speciale syntax nSpeciale index-notatie string s = new string();char[] a = new char[10]; c = a[2];a[3] = c; nSpeciale quote-notatie s = "hallo"; nProperty a.Length nProperty s.Length nMethoden s.Substring(3,2); s.IndexOf(t); nIndexer -notatie c = s[2];s[3] = c;

25 Declaratie declaratie naamtype, =initialisatieconst ; var met intitialisatie initialisatie expressie initialisatie}{, string [ ] woorden = { "aap", "noot", "mies" }; int [ ] maand = { 31,28,31,30,31,30,31,31,30,31,30,31 }; Color [ ] palet = { new Color(64,0,0), Color.Yellow };

26 Tekst Analyse EditText TekstAnalyse DiagramView class TekstAnalyse : Activity class DiagramView : View LinearLayout

27 Tekst Analyse public class TekstAnalyse : Activity { protected override void OnCreate(Bundle b) { base.OnCreate(b); } tekst = new EditText(this); diagram = new DiagramView(this); } EditText tekst; DiagramView diagram; LinearLayout s = new LinearLayout(this); s.AddView(tekst); s.AddView(diagram); SetContentView(s); public void veranderd(object o, EventArgs e) } { tekst.AfterTextChanged += veranderd; diagram.Invoer = tekst.Text; diagram.Invalidate( );

28 Tekst Analyse public class DiagramView: View { protected override void OnDraw(Canvas cv) { base.OnDraw(cv); } } public string Invoer; tellers 9 0 5 1 5 14 1 2 3 4 26 Length 0 5 6 8 0 5 6 7 8 9 int [ ] tellers; tellers = new int [26];

29 Tekst Analyse public class DiagramView: View { protected override void OnDraw(Canvas cv) { base.OnDraw(cv); } } public string Invoer; tellers 9 0 5 1 5 14 1 2 3 4 26 Length 0 5 6 8 0 5 6 7 8 9 int [ ] tellers; tellers = new int [26]; tellers[ ]++; foreach(char c in Invoer) c-'a' if (c>='a' && c<='z') foreach(int a in tellers) { } cv.DrawRect( x, y, x+a*w, y+h, verf ); cv.DrawText( a.ToString()... ); int h = Height/ 26; y = y+h;, y=0; int w = Width / max;

30 Array / List nDeclaratie nCreatie nOpvragen nWijzigen nLengte String [ ] a; a = new String[10]; ……a[5]…… a[5] = ……; …a.Length… List a; a = new List(); …a.Get(5)… a.Set(5,…); …a.Count… array: oject dat een rij waarden bevat, met speciale notaties List: array “ingepakt” in een klasse, met extra methodes nInvoegen nAchtervoegen a.Insert(5,…); List a; a = new List (); a.Add(…); ……a[5]…… a[5] = ……;

31 ListView

32 public class KleurenApp : Activity { protected override void OnCreate(Bundle b) { base.OnCreate(b); } kleurLijst = new ListView(this); } ListView kleurLijst; SetContentView(kleurLijst); public void klik(object o, ItemClickEventArgs e) } { kleurLijst.Adapter = kleurAdp; ArrayAdapter kleurAdp; kleurAdp = new ArrayAdapter (this, SimpleListItemChecked, kleuren); kleurLijst.Choicemode = Multiple; string[] kleuren = {"rood", "wit", "blauw"}; kleurLijst.ItemClick += klik; string s = kleuren[e.Position]; Toast.MakeText(...t...). Show( );


Download ppt "Meer constructormethodes in klasse Kleur { class Kleur } public byte Rood, Groen, Blauw; public Kleur( byte r, byte g, byte b ) { } Rood=r; Groen=g; Blauw=b;"

Verwante presentaties


Ads door Google