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

34
LINES

< > BotCompany Repo | #1015966 // jDesktopPaneWithSkyPicture_autoUnload

JavaX fragment (include)

1  
sclass DesktopPaneWithSkyPicture_autoUnload extends JDesktopPane {
2  
  S imageID;
3  
  BufferedImage image;
4  
  new RestartableCountdown countdown;
5  
  double autoUnloadAfter = 60.0;
6  
  bool verbose = true;
7  
  
8  
  *(S *imageID, BufferedImage *image) {}
9  
  
10  
  protected void paintComponent(Graphics g) {  
11  
    paintSkyBackground(this, g, _getImage());
12  
  }
13  
  
14  
  BufferedImage _getImage() {
15  
    ret swing(func -> BufferedImage {
16  
      if (image == null) {
17  
        long time = sysNow();
18  
        image = loadImage2(imageID);
19  
        if (verbose) _print("Background image loaded in " + elapsedMS(time) + " ms");
20  
      }
21  
      countdown.start(autoUnloadAfter, r-awt {
22  
        if (image != null) {
23  
          image = null;
24  
          if (verbose) _print("Background image released");
25  
        }
26  
      });
27  
      ret image;
28  
    });
29  
  }
30  
}
31  
32  
static JDesktopPane jDesktopPaneWithSkyPicture_autoUnload(fS imageID, Color background) {
33  
  ret setBackground(background, swingNu(DesktopPaneWithSkyPicture_autoUnload, imageID, loadImage2(imageID)));
34  
}

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: 348 / 387
Version history: 13 change(s)
Referenced in: [show references]