/* Schlange2.inc */ public void run() { //Schlange konstruieren ColorRectangle cr; int x = 100; int y = 100; for (int i=0; i < NUMELEMENTS; ++i) { cr = new ColorRectangle(); cr.x = x; cr.y = y; cr.width = SIZERECT; cr.height = SIZERECT; x += SIZERECT; cr.color = new Color( i*(256/NUMELEMENTS), 0, 240-i*(256/NUMELEMENTS) ); snake.addElement(cr); } //Löschelement anhängen cr = new ColorRectangle(); cr.x = x; cr.y = y; cr.width = SIZERECT; cr.height = SIZERECT; cr.color = BGCOLOR; snake.addElement(cr); //Vorzugsrichtung festlegen dx = -1; dy = -1; //Schlange laufen lassen while (true) { repaint(); try { Thread.sleep(SLEEP); } catch (InterruptedException e){ //nichts } moveSnake(); } }