void allocImage() {
        pixels = null;
        int w = rect.width;
        int h = rect.height;
        if (w == 0 || h == 0) {
            return;
        }
        if (sim.useBufferedImage()) {
            try {
                /* simulate the following code using reflection:
                 dbimage = new BufferedImage(d.width, d.height,
                 BufferedImage.TYPE_INT_RGB);
                 DataBuffer db = (DataBuffer)(((BufferedImage)dbimage).
                 getRaster().getDataBuffer());
                 DataBufferInt dbi = (DataBufferInt) db;
                 pixels = dbi.getData();
                 */
                Class biclass = Class.forName("java.awt.image.BufferedImage");
                Class dbiclass = Class.forName("java.awt.image.DataBufferInt");
                Class rasclass = Class.forName("java.awt.image.Raster");
                Constructor cstr = biclass.getConstructor(
                        new Class[]{int.class, int.class, int.class});
                image = (Image) cstr.newInstance(new Object[]{
                    new Integer(w), new Integer(h),
                    new Integer(BufferedImage.TYPE_INT_RGB)});
                Method m = biclass.getMethod("getRaster");
                Object ras = m.invoke(image);
                Object db = rasclass.getMethod("getDataBuffer").invoke(ras);
                pixels = (int[]) dbiclass.getMethod("getData").invoke(db);
            } catch (Exception ee) {
                // ee.printStackTrace();
                System.out.println("BufferedImage failed");
            }
        }
        if (pixels == null) {
            pixels = new int[w * h];
            int i;
            for (i = 0; i != w * h; i++) {
                pixels[i] = 0xFF000000;
            }
            imageSource = new MemoryImageSource(w, h, pixels, 0, w);
            imageSource.setAnimated(true);
            imageSource.setFullBufferUpdates(true);
            image = sim.getCircuitCanvas().createImage(imageSource);
        }
        dpixels = new float[w * h];
        draw_ox = draw_oy = -1;
    }