sclass AnimatedImageSurface > ImageSurface { double fps = 20; // We start & stop the timer by setting its frequency // to the actual frequency or 0, respectively. // (Don't want to close the timer as that is permanent.) FlexibleRateTimer animationTimer = new(0, l0 renderFrame).pileUp(false); void renderFrame { var img = makeImage(); if (img != null) setImage(img); } selfType fps aka setFPS(double fps) { this.fps = fps; swing { updateTimer(isShowing()); } this; } swappable BufferedImage makeImage() { ret whiteImage(10, 10); } *() { init(); } *(IF0 *makeImage) { init(); } *(double fps, IF0 *makeImage) { setFPS(fps); init(); } *(Freq freq, IF0 *makeImage) { setFPS(freq!); init(); } void updateTimer(bool showing) { animationTimer.setFrequencyImmediately(showing ? fps : 0.0); } void init { setDoubleBuffered(true); bindToComponent(this, -> { animationTimer.start(); updateTimer(true); }, -> updateTimer(false)); } }