firstTime = false;
firstTime = false; }   graphicsHandle.setColor(backgroundColor); graphicsHandle.clearRect(0, 0, area.width, area.height);  if (backgroundImage!=null) { graphicsHandle.drawImage(backgroundImage, 0, 0, area.width, area.height, this); } else {  graphicsHandle.fillRect(0, 0, area.width, area.height); }   drawPanel(graphicsHandle);   g2.drawImage(bi, 0, 0, this);   dirty = false; } catch (Throwable ex) { ex.printStackTrace();
    public void update(Graphics g) {        Graphics2D g2 = (Graphics2D) g;        Dimension dim = getSize();        int w = dim.width;        int h = dim.height;        // if the graph has not been drawn or the size has changed,        // initialize the graph        if (firstTime || dirty) {            // create the buffered image & its graphics            bi = (BufferedImage) createImage(w, h);            graphicsHandle = bi.createGraphics();            graphicsHandle.setColor(Color.black);            graphicsHandle.setStroke(new BasicStroke(5.0f));            // set up antialiasing            graphicsHandle.setRenderingHint(RenderingHints.KEY_ANTIALIASING,                RenderingHints.VALUE_ANTIALIAS_ON);            // drawing area            area = new Rectangle(dim);            // it's not first time anymore, but following functions may            // use the dirty flag : unset it at the end of the draw phase            firstTime = false;        }        // Clears the rectangle that was previously drawn.        graphicsHandle.setColor(backgroundColor);        graphicsHandle.clearRect(0, 0, area.width, area.height);        if (backgroundImage != null) {            graphicsHandle.drawImage(backgroundImage, 0, 0, area.width,                area.height, this);        } else {            // Draws and fills the newly positioned rectangle to the buffer.            graphicsHandle.fillRect(0, 0, area.width, area.height);        }        // Draws the content of the panel on to the buffered image's graphics        drawPanel(graphicsHandle);        // Draws the buffered image to the screen.        g2.drawImage(bi, 0, 0, this);        // if dirty was true, we give a chance to any of the previous function to do some work        dirty = false;    }