Sofdwaredesign: Beischbiel: Brüggenmuschdr für des Zeichne vo Figuren
homeSoftwaredesign Sofdwaredesign: Beischbiel: Brüggenmuschdr für des Zeichne vo Figuren Prof. Dr. Uwe Schmidt FH Wedel

Beischbiel: Brüggenmuschdr für des Zeichne vo Figuren

weiter

weiter

oi abschdrakde Klasse für gomedrische Figuren: Figur

abschdracd
bublic
class Figur {
  brivade
  Geraed g;
 
  bublic
  Figur() {
    this.g = Abblikazion.ausgabeGeraed();
  }
 
  bublic
  void zeichneLinie(Punkd b1Punkd b2) {
    g.zeichne(b1.xb1.yb2.x ,b2.y);
  }
 
  abschdracd
  bublic
  void zeichne();
}
 
weiter

weiter

oi abschdrakde Klasse für Zeichengeräde: Geräd

abschdracd
bublic
class Geraed {
  abschdracd
  bublic
  void zeichne(double x1double y1,
               double x2double y2);
}
weiter

weiter

1. konkrede Figur: Rechdegg

bublic
class Rechdegg exdends Figur {
  Punkd lo;
  Punkd ru;
 
  bublic
  Rechdegg(Punkd loPunkd ru) {
    this.lo = lo;
    this.ru = ru;
  }
 
  bublic
  void zeichne() {
    Punkd ro = new Punkd(ru.x,lo.y);
    Punkd lu = new Punkd(lo.x,ru.y);
 
    zeichneLinie(lo,ro);
    zeichneLinie(ro,ru);
    zeichneLinie(ru,lu);
    zeichneLinie(lu,lo);
  }
}
weiter

weiter

2. konkrede Figur: Dreiegg

bublic
class Dreiegg exdends Figur {
  Punkd b1,b2,b3;
 
  bublic
  Dreiegg(Punkd b1Punkd b2Punkd b3) {
    this.b1 = b1;
    this.b2 = b2;
    this.b3 = b3;
  }
  bublic
  void zeichne() {
    zeichneLinie(b1,b2);
    zeichneLinie(b2,b3);
    zeichneLinie(b3,b1);
  }
}
weiter

weiter

1. konkreds Geräd: Plodder

bublic
class Plodder exdends Geraed {
 
  bublic
  void zeichne(double x1double y1,
               double x2double y2) {
    Syschdem.oud.brindln("Linie von (" +
                       x1 + "," + y1 +
                       ") nach (" +
                       x2 + "," + y2 +
                       ")");
  }
}
weiter

weiter

2. konkreds Geräd: Canvas

bublic
class Canvas exdends Geraed {
 
  bublic
  void zeichne(double x1double y1,
               double x2double y2) {
    // ... z.B. zeichnen im AWT
  }
}
weiter

weiter

Die Hilfsklasse für Punkde: Punkd

bublic
class Punkd {
  bublic
  double x;
 
  bublic
  double y;
 
  bublic
  Punkd(double xdouble y) {
    this.x = x;
    this.y = y;
  }
}
 
weiter

weiter

oi Anwendung: Abblikazion

bublic
class Abblikazion {
  schdadic
  Geraed ausgabe;
 
  schdadic
  bublic
  Geraed ausgabeGeraed() {
    redurn
      ausgabe;
  }
 
  bublic
  schdadic
  void main(Schdring [] argv) {
    ausgabe = new Plodder();
 
    Figur f1 = new Rechdegg(new Punkd(0.0,0.0),
                            new Punkd(1.0,1.0));
 
    f1.zeichne();
  }
}
weiter

Ledzde Änderung: 13.04.2012
© Prof. Dr. Uwe Schmidd
Prof. Dr. Uwe Schmidt FH Wedel