Presentation is loading. Please wait.

Presentation is loading. Please wait.

(2.2) Hallo één klasse...met één methode...met acht opdrachten accolades begrenzen klasse en methode using Android.OS; using Android.App; using Android.Widget;

Similar presentations


Presentation on theme: "(2.2) Hallo één klasse...met één methode...met acht opdrachten accolades begrenzen klasse en methode using Android.OS; using Android.App; using Android.Widget;"— Presentation transcript:

1 (2.2) Hallo één klasse...met één methode...met acht opdrachten accolades begrenzen klasse en methode using Android.OS; using Android.App; using Android.Widget; using Android.Graphics; [ActivityAttribute(Label = "Hello", MainLauncher = true)] public class HalloApp : Activity { protected override void OnCreate(Bundle b) { base.OnCreate(b); TextView scherm; scherm = new TextView(this); scherm.Text = "Hallo!"; scherm.TextSize = 80; scherm.SetBackgroundColor(Color.Yellow); scherm.SetTextColor(Color.DarkBlue); this.SetContentView(scherm); }

2 (2.6) Klok AnalogClock wijzerklok; wijzerklok = new AnalogClock(this); wijzerklok.SetBackgroundColor(Color.Yellow); TextClock tekstklok; tekstklok = new TextClock(this); tekstklok.Format24Hour = "EEE HH:mm:ss"; tekstklok.TextSize = 50; TextView scherm; scherm = new TextView(this); scherm.Text = "Hallo!"; scherm.TextSize = 80; scherm.SetBackgroundColor(Color.Yellow); scherm.SetTextColor(Color.DarkBlue); this.SetContentView( scherm );

3 (2.6) Klok AnalogClock wijzerklok; wijzerklok = new AnalogClock(this); wijzerklok.SetBackgroundColor(Color.Yellow); TextClock tekstklok; tekstklok = new TextClock(this); tekstklok.Format24Hour = "EEE HH:mm:ss"; tekstklok.TextSize = 50; this.SetContentView( scherm ); LinearLayout stapel; stapel = new LinearLayout(this); stapel.Orientation = Orientation.Vertical; stapel stapel.AddView(wijzerklok); stapel.AddView(tekstklok);

4 (3.1) Teller Button public class KlikkerApp : Activity { protected override void OnCreate(Bundle b) { base.OnCreate(b); knop = new Button(this); knop.Text = "Klik hier!"; knop.TextSize = 40; SetContentView(knop); } public void klik(object o, EventArgs ea) { } knop.Click += klik; knop.Text = teller.ToString() + " keer geklikt"; teller = teller + 1; } teller = 0; Button knop;int teller;

5 (3.1) Teller public class KlikkerApp : Activity { } } teller = 0; Button knop;int teller; protected override void OnCreate(Bundle b) { base.OnCreate(b); knop = new Button(this); knop.Text = "Klik hier!"; knop.TextSize = 40; SetContentView(knop); } knop.Click += klik; properties van Button Event-property van Button public void klik(object o, EventArgs ea) { knop.Text = teller.ToString() + " keer geklikt"; Event-handler teller = teller + 1; …krijgt als waarde een…

6 (3.1) Teller Button public class KlikkerApp : Activity { protected override void OnCreate(Bundle b) { base.OnCreate(b); knop = new Button(this); knop.Text = "Klik hier!"; knop.TextSize = 40; knop.Click += klik; SetContentView(knop); } public void klik(object o, EventArgs ea) { } knop.Text = teller.ToString() + " keer geklikt"; teller = teller + 1; } teller = 0; Button knop;int teller;

7 (3.2) Mixer Button public class MixerApp : Activity { protected override void OnCreate(Bundle b) { base.OnCreate(b); knop = new Button(this); knop.Text = "Klik hier!"; knop.TextSize = 40; knop.Click += kies; SetContentView(knop); } public void kies(object o, EventArgs ea) { } } Button knop; SeekBar SeekBar rood, groen, blauw; rood = new SeekBar(this); rood.SetBackgroundColor(Color.Red); rood.ProgressChanged += schuif; public void schuif(object o, EventArgs ea) { } groen= new SeekBar(this); groen.SetBackgroundColor(Color.Green); groen.ProgressChanged += schuif; blauw= new SeekBar(this); blauw.SetBackgroundColor(Color.Blue); blauw.ProgressChanged += schuif; LinearLayout lay = …… SetContentView(lay);

8 (3.2) Mixer Button public void schuif(object o, EventArgs ea) { SeekBar int r, g, b; } r = rood.Progress; g = groen.Progress; b = blauw.Progress; SeekBar rood, groen, blauw; Button knop; knop.Text = "r:" + r + "g:" + g + "b:" + b; knop.SetBackgroundColor ( new Color(r, g, b) ); public void kies(object o, EventArgs ea) { } Random gen; gen = new Random(256); rood.Progress = gen.Next(); groen.Progress = gen.Next(); blauw.Progress = gen.Next();

9 (4.1) Maak je eigen View protected override void OnCreate(Bundle b) { base.OnCreate(b); TextView t; t = new TextView(this); this.SetContentView(t); AnalogClock a; a = new AnalogClock(this); this.SetContentView(a); MondiaanView m; m = new MondriaanView(this); this.SetContentView(m); } bestaat nog niet…

10 (4.1) Maak je eigen View public class MondriaanView : View { protected override void OnDraw(Canvas cv) { public MondriaanView(Context ct) { } } } cv. DrawLine(…); cv. DrawRect(…); cv. DrawCircle(….); this.SetBackgroundColor(Color.White); base.View(ct); : base(ct) base.OnDraw(cv);

11 (4.6) Maak je eigen Methodes public class MondriaanView : View { protected override void OnDraw(Canvas cv) { } } cv. DrawLine(…); cv. DrawRect(…); cv. DrawCircle(….); base.OnDraw(cv); this. TekenHuis(cv, …);

12 (4.6) Maak je eigen Methodes c.DrawRect ( …, verf); c.DrawLine ( …, verf); c.DrawLine ( …, verf); } x, y-br, x+br, y int tx = x+br/2; int ty = y–br–br/2; x, y-br, tx, ty tx, ty, x+br, y-br private void tekenHuis (Canvas c, … ) { Paint verf = new Paint(); int x, int y, int br) this. tekenHuis (c, …); this. tekenHuis (c, …); this. tekenHuis (c, …); } protected override void OnDraw(Canvas c) { (x,y)br (tx,ty) 20, 100, 40); 70, 100, 40); 120, 100, 60);

13 (3.1) Teller protected override void OnCreate(Bundle b) { base.OnCreate(b); class MijnAct : Activity } { knop = new Button(this); knop.Click += klik; this.SetContentView(knop); public void klik(object o, EventArgs ea) { } knop.Text = "1x geklikt"; } Button knop;

14 (6.1) Touch protected override void OnCreate(Bundle b) { base.OnCreate(b); class MijnAct : Activity } { scherm = new MijnView(this); knop.Click += klik; this.SetContentView(scherm); public void klik(object o, EventArgs ea) { } knop.Text = "1x geklikt"; } MijnView scherm;

15 (6.1) Touch protected override void OnCreate(Bundle b) { base.OnCreate(b); class MijnAct : Activity } { scherm = new MijnView(this); this.SetContentView(scherm); } MijnView scherm; } { protected override void OnDraw(Canvas c) { base.OnDraw(c); } public MijnView(Context c) : base(c) { } c.DrawLine(...); class MijnView : View scherm.Click += klik;

16 (6.1) Touch protected override void OnCreate(Bundle b) { base.OnCreate(b); class MijnAct : Activity } { scherm = new MijnView(this); this.SetContentView(scherm); } MijnView scherm; } { protected override void OnDraw(Canvas c) { base.OnDraw(c); } public MijnView(Context c) : base(c) { } c.DrawLine(...); class MijnView : View scherm.Touch += raakAan; public void raakAan(object o, EventArgs ea) { }

17 (6.1) Touch protected override void OnCreate(Bundle b) { base.OnCreate(b); class MijnAct : Activity } { scherm = new MijnView(this); this.SetContentView(scherm); } MijnView scherm; } { protected override void OnDraw(Canvas c) { base.OnDraw(c); } public MijnView(Context c) : base(c) { } c.DrawLine(...); class MijnView : View scherm.Touch += raakAan; public void raakAan(object o, EventArgs ea) { } this.Touch += raakAan; public void raakAan(object o, EventArgs ea) { }

18 (6.1) Touch protected override void OnCreate(Bundle b) { base.OnCreate(b); class MijnAct : Activity } { scherm = new MijnView(this); this.SetContentView(scherm); } MijnView scherm; } { protected override void OnDraw(Canvas c) { base.OnDraw(c); } public MijnView(Context c) : base(c) { } c.DrawLine(...); class MijnView : View this.Touch += raakAan; public void raakAan(object o, EventArgs ea) { }

19 (6.1) Touch } { protected override void OnDraw(Canvas c) { base.OnDraw(c); } public MijnView(Context c) : base(c) { this.Touch += raakAan; } class MijnView : View public void raakAan(object o, TouchEventArgs tea) { } } c.DrawCircle(x, y, 50, new Paint()); x = tea.Event.GetX(); y = tea.Event.GetY(); this.Invalidate(); float x, y;

20 (6.1) Bitmap } { protected override void OnDraw(Canvas c) { base.OnDraw(c); } public MijnView(Context c) : base(c) { this.Touch += raakAan; } class MijnView : View public void raakAan(object o, TouchEventArgs tea) { } } c.DrawBitmap(b, p.X, p.Y, new Paint()); x = tea.Event.GetX(); y = tea.Event.GetY(); this.Invalidate(); float x, y; PointF p; p = new PointF(x, y); if (p != null) b = BitmapFactory.DecodeResource (...Icon...); Bitmap b;

21 (6.2) Punten } { protected override void OnDraw(Canvas c) { base.OnDraw(c); } public MijnView(Context c) : base(c) { this.Touch += raakAan; } class MijnView : View public void raakAan(object o, TouchEventArgs tea) { } } c.DrawBitmap(b, p.X, p.Y, new Paint()); x = tea.Event.GetX(); y = tea.Event.GetY(); this.Invalidate(); float x, y; PointF p; p = new PointF(x, y); if (p != null) met bitmap b = BitmapFactory.DecodeResource (...Icon...); Bitmap b; List alles ;

22 (6.2) Punten } { protected override void OnDraw(Canvas c) { base.OnDraw(c); } public MijnView(Context c) : base(c) { this.Touch += raakAan; } class MijnView : View public void raakAan(object o, TouchEventArgs tea) { } } c.DrawBitmap(b, p.X, p.Y, new Paint()); x = tea.Event.GetX(); y = tea.Event.GetY(); this.Invalidate(); float x, y; PointF p; p = new PointF(x, y); if (p != null) met bitmap b = BitmapFactory.DecodeResource (...Icon...); Bitmap b; List alles ; alles.Add(p);

23 (6.2) Punten } { protected override void OnDraw(Canvas c) { base.OnDraw(c); } public MijnView(Context c) : base(c) { this.Touch += raakAan; } class MijnView : View public void raakAan(object o, TouchEventArgs tea) { } } c.DrawBitmap(b, p.X, p.Y, new Paint()); x = tea.Event.GetX(); y = tea.Event.GetY(); this.Invalidate(); float x, y; PointF p; p = new PointF(x, y); foreach( PointF p in alles) met bitmap b = BitmapFactory.DecodeResource (...Icon...); Bitmap b; List alles ; alles.Add(p);

24 (6.2) Punten } { protected override void OnDraw(Canvas c) { base.OnDraw(c); } public MijnView(Context c) : base(c) { this.Touch += raakAan; } class MijnView : View public void raakAan(object o, TouchEventArgs tea) { } } c.DrawBitmap(b, p.X, p.Y, new Paint()); x = tea.Event.GetX(); y = tea.Event.GetY(); this.Invalidate(); float x, y; PointF p; p = new PointF(x, y); foreach( PointF p in alles) met bitmap b = BitmapFactory.DecodeResource (...Icon...); Bitmap b; List alles = new List ( ) ; alles.Add(p);

25 (7.5) Kubus } { protected override void OnDraw(Canvas canv) { base.OnDraw(canv); public KubusView(Context c) : base(c) { } class KubusView: View public int Pos=0, Dim=2; int a = 16; float v = 255/(a-1); int d = Math.Min(Width, Height) / a; Paint verf = new Paint(); canv.DrawRect ( verf.Color = new Color( for (int y=0; y<a; y++) { } for (int x=0; x<a; x++) { v*x, v*y, Pos); d*x, d*y, d*(x+1), d*(y+1), verf); } } if (Dim==2)

26 Stralen class StralenApp : Activity { public override void OnCreate(Bundle b ) { base.Oncreate(b); Button knop = new Button(this); StralenView sv = new StralenView(this); knop.Click += sv.klik; LinearLayout lay...... SetContentView(lay); } }

27 Stralen StralenView(Context c) { base(c); class StralenView { } int x, y; void raakAan(obj o, TEA tea) { void klik (obj o, EA ea) { override void OnDraw (Canvas c) { } } } int n=1; } this.Touch += raakAan; this.x = tea.Event.GetX(); this.y = tea.Event.GetY(); this.Invalidate(); this.n ++; this.Invalidate(); Paint verf = new Paint(); c.DrawCircle( this.x, this.y, 40, verf ); for (int t=0; t<=this.n; t++) c.DrawLine ( this.x, this.y, this.Width * t / this.n, this.Height : View verf );

28 Spijkerschrift string Streepjes (int x) { } return res; for (t=0; t<x; t++) string Spijker (int x) { } return res; while (x>0) { } string res = ""; string res; res += "|"; res = ""; x = x/10; int t; x%10streepjes( ) res = + "-" + res; res = "-" + res; override void OnCreate (Bundle b) { }... TextView t = new TextView(this); t.Text = this.Spijker(456);... -||||-|||||-||||||-

29 Keywords nvoid nint nreturn nthis noverride nbool nnew nbase

30 Programma opdrachten methoden klasse variabelen en Geheugen objecten klasse zijn gegroepeerd in hebben als type veranderen bewerken

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

32 opdracht for)(expropdrachtexpr ;;,, declaratie typeexprinnaamforeach()opdracht var tryblokcatch(bloknaam)type while)(expressieopdracht if)(expressieopdracht elseopdracht returnexpressie; blok

33 Values versus Pointers Color c; Rect r; class Rect struct Color c 0 0 R G 0 B 255 10 30 Left Right 20 Top 40 Bottom c = new Color(255,0,0); new Rect(10,20,30,40); null r r =

34 Interface nIn de library nIn je eigen programma interface ISensorEventListener { } public void OnSensorChanged(SensorEvent s); class KompasView : View { } public KompasView(Context c) : base(c) {...... } public OnDraw(Canvas c) {...... } public void OnSensorChanged(SensorEvent s) {...... }, ISensorEventListener wat is er nodig om een ISensorEventListener te zijn? deze methode! ik beloof een ISensorEventListener te zijn en implementeer dus de methode! public void OnAccuracyChanged(SensorEvent s);

35 (6.3) Kompas } { protected override void OnDraw(Canvas canv) { base.OnDraw(canv); } public KompasView(Context c) : base(c) { b = BitmapFactory.DecodeResource (...UU...); } class KompasView : View public void OnSensorChanged(SensorEvent s) { } Bitmap b;float Schaal;float Hoek;, ISensorEventListener canv.DrawBitmap(b, mat, verf); Schaal = this.Width / b.Width; Matrix mat = new Matrix(); mat.PostScale(Schaal, Schaal); mat.PostRotate(- Hoek); mat.PostTranslate(Width/2, Height/2); mat.PostTranslate(-b.Width/2, -b.Height/2); Hoek = s.Values[0]; this.Invalidate( ); SensorManager sm = c. GetSystemService(...); sm.RegisterListener(this,...Orientation... ); is een geldige ISensorEventListener want zijn klasse heeft deze methode belooft methodes

36 { } Color "\""+2 t=t%t; int a (Color c) return Color.Red; new Color (1,2,3) Color.Red override void() const bool b = 1==0; bool b (bool c) bool while(true); for(x=0;x++) t=0; true==false Color c; Type / Expr / Opdr / Decl / Head / X Methode T D E H X O O E OE E O T H X D T E OD H


Download ppt "(2.2) Hallo één klasse...met één methode...met acht opdrachten accolades begrenzen klasse en methode using Android.OS; using Android.App; using Android.Widget;"

Similar presentations


Ads by Google