Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

34
LINES

< > BotCompany Repo | #1015966 // jDesktopPaneWithSkyPicture_autoUnload

JavaX fragment (include)

sclass DesktopPaneWithSkyPicture_autoUnload extends JDesktopPane {
  S imageID;
  BufferedImage image;
  new RestartableCountdown countdown;
  double autoUnloadAfter = 60.0;
  bool verbose = true;
  
  *(S *imageID, BufferedImage *image) {}
  
  protected void paintComponent(Graphics g) {  
    paintSkyBackground(this, g, _getImage());
  }
  
  BufferedImage _getImage() {
    ret swing(func -> BufferedImage {
      if (image == null) {
        long time = sysNow();
        image = loadImage2(imageID);
        if (verbose) _print("Background image loaded in " + elapsedMS(time) + " ms");
      }
      countdown.start(autoUnloadAfter, r-awt {
        if (image != null) {
          image = null;
          if (verbose) _print("Background image released");
        }
      });
      ret image;
    });
  }
}

static JDesktopPane jDesktopPaneWithSkyPicture_autoUnload(fS imageID, Color background) {
  ret setBackground(background, swingNu(DesktopPaneWithSkyPicture_autoUnload, imageID, loadImage2(imageID)));
}

Author comment

Began life as a copy of #1015863

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1015966
Snippet name: jDesktopPaneWithSkyPicture_autoUnload
Eternal ID of this version: #1015966/14
Text MD5: 06c342ee40f15a0759763d2bd7a66dd3
Author: stefan
Category: javax / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-06-02 12:40:10
Source code size: 1047 bytes / 34 lines
Pitched / IR pitched: No / No
Views / Downloads: 277 / 309
Version history: 13 change(s)
Referenced in: [show references]