(2.2) hallo één klasse...met één methode...met acht opdrachten accolades begrenzen klasse en...

Post on 17-Jan-2018

224 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

(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);

TRANSCRIPT

(2.2) Hallo

één klasse

...met éénmethode

...met achtopdrachtenaccolades begrenzen

klasseen 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.6) KlokAnalogClock 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 );

(2.6) KlokAnalogClock 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);

(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;

(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;

propertiesvan Button

Event-propertyvan Button

public void klik(object o, EventArgs ea){ knop.Text = teller.ToString()

+ " keer geklikt";

Event-handler teller = teller + 1;

…krijgt als waarde een…

(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;

(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;

SeekBarSeekBarSeekBar

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);

(3.2)Mixer

Button

public void schuif(object o, EventArgs ea){

SeekBarSeekBarSeekBar

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();

(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…

(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);

(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, …);

(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);

(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;

(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;

(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;

(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){}

(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){ }

(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){ }

(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;

(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;

(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<PointF>

alles ;

(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<PointF>

alles ;

alles.Add(p);

(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<PointF>

alles ;

alles.Add(p);

(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<PointF> alles = new

List<PointF>( ) ;

alles.Add(p);

(7.5)Kubus

}

{

protected override void OnDraw(Canvas canv){ base.OnDraw(canv);

public KubusView(Context c) : base(c){ }

class KubusView: Viewpublic 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)

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);}

}

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 );

Spijkerschriftstring 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%10

streepjes( )res =+ "-" + res;

res = "-" + res;

override void OnCreate (Bundle b){

}

... TextView t = new TextView(this);t.Text =

this.Spijker(456); ...-||||-|||||-||||||-

Keywords void int return this

override

bool new base

Programma

opdrachten

methoden

klasse

variabelen

en Geheugen

objecten

klasseklasse

zijn gegroepeerd in

zijn gegroepeerd in

zijn gegroepeerd in

hebben als type

veranderen

bewerken

Syntax van opdrachten

opdracht

( ),

;expressieklassenaamobject

expressie.

methodenaam

= expressie ;variabele

propertynaam +=

return expressie ;

opdracht

for )( expr opdrachtexpr expr;;, ,

declaratie

type exprinnaam foreach ( ) opdracht

var

try blok catch ( blok naam )type

while )( expressie opdracht

if )( expressie opdrachtelse opdracht

return expressie ;blok

Values versus PointersColor c;

Rect r;class Rect

struct Color

c

00

RG

0B

2551030

Left

Right 20Top

40Bottom

c = new Color(255,0,0);new Rect(10,20,30,40);

nullr

r =

Interface In de library

In 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 nodigom een

ISensorEventListenerte zijn?deze methode!

ik beloof eenISensorEventListener

te zijnen implementeerdus de methode!

public void OnAccuracyChanged(SensorEvent s);

(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 geldigeISensorEventListener

want zijn klasseheeft deze methode

belooft methodes

{ }

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 / XMethode

T

D

E

H

X

OO

E

O E

E

O

T

H

X

D

T E O D H

top related