9. สร้างใหม่จากเก่า

The Camtasia Studio video content presented here requires JavaScript to be enabled and the latest version of the Macromedia Flash Player. If you are you using a browser with JavaScript disabled please enable it now. Otherwise, please update your version of the free Flash Player by downloading here.

 
รหัสที่ 9-7  คลาส IntegerLEDWindow
import jlab.graphics.DWindow;

public class IntegerLEDWindow extends DWindow {
  private DecimalLED[] digits;
  private int value;
  private double digitWidth;
   
  public IntegerLEDWindow(int numDigits, double digitWidth) {
    super(numDigits * digitWidth, digitWidth * 7 / 5);
    super.setBackground(super.BLACK);
    digits = new DecimalLED[numDigits];
    for (int i = 0; i < digits.length; i++) {
      digits[i] = new DecimalLED();
      digits[i].setWidth(digitWidth * 0.8);
    }
    this.digitWidth = digitWidth;
  }
   public int getValue() {
    return value;
  }
  public void setValue(int d) {
    value = d;
    for (int i = digits.length - 1; i >= 0; i--) {
      digits[i].setDigit(d % 10);
      digits[i].draw(this, (i + 0.1) * digitWidth, 10);
      d = d / 10;
    }
  }
}
©2009 S.Prasitjutrakul