private void setScaledImage(Image background, String key) {
      if (background != null) {
         float iw = background.getWidth(this);
         float ih = background.getHeight(this);
         float pw = getWidth();   //panel width
         float ph = getHeight();  //panel height

         if (pw < iw || ph < ih) {
            if ((pw / ph) > (iw / ih)) {
               iw = -1;
               ih = ph;
            } else {
               iw = pw;
               ih = -1;
            }
            if (iw == 0) {
               iw = -1;
            }
            if (ih == 0) {
               ih = -1;
            }
            scaledHeight = (int) ih;
            scaledWidth = (int) iw;
            scaled.put(key, background
                    .getScaledInstance(new Float(iw).intValue(), new Float(ih).intValue(), Image.SCALE_FAST));
         } else {
            scaled.put(key, background);
         }
      }
   }