// f: (int w, int h) -> BufferedImage static ImageSurface jcanvas(O f) { ret jcanvas(f, 500); } static ImageSurface jcanvas(fO f, final int updateDelay) { assertAWTThread(); final new ImageSurface is; final Runnable update = new Runnable { bool first = true; public void run { BufferedImage img = is.getImage(); int w = is.getWidth(), h = is.getHeight(); if (first || img.getWidth() != w || img.getHeight() != h) { is.setImage(asBufferedImage(callF(f, w, h))); first = false; } } }; onResize(is, r { awtLater(is, updateDelay, update) }); bindToComponent(is, update); // first update ret is; }