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

33
LINES

< > BotCompany Repo | #1035209 // testDirectlyPaintingOnJComponent

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (14849L/87K).

1  
svoid testDirectlyPaintingOnJComponent(int w default 256) {
2  
  int h = w;
3  
  var c = //jcenteredlabel("Bla");
4  
    new JComponent {};
5  
  setOpaqueBackground(Color.white, c);
6  
  jMinSize(c, w, h);
7  
  
8  
  var it = WeightlessShuffledIteratorWithSeed<Pt>(virtualList(w*h, i -> pt(i%w, i/w)));
9  
  
10  
  new Var<Graphics2D> g;
11  
  new Flag done;
12  
  double timeToFinish = 2; // seconds
13  
  int pixelsPerMS = iceilRatio(w*h/100, timeToFinish);
14  
  
15  
  awtEvery(c, 10, -> {
16  
    if (!g.has()) {
17  
      g.set((Graphics2D) c.getGraphics());
18  
      if (!g.has()) ret;
19  
    }
20  
  
21  
    repeat pixelsPerMS {
22  
      if (!it.hasNext()) {
23  
        if (done.raise())
24  
          print("Done painting " + nPixels(w*h));
25  
        break;
26  
      }
27  
      var p = it.next();
28  
      //print(+p);
29  
      setPixel(g!, p, Color.black);
30  
    }
31  
  });
32  
  showFrame(c);
33  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1035209
Snippet name: testDirectlyPaintingOnJComponent
Eternal ID of this version: #1035209/7
Text MD5: 4381ae31afd6e53b8c9369862936695c
Transpilation MD5: e4dde5aa3812999df38cc800b6cbcf50
Author: stefan
Category: javax / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-04-15 05:27:20
Source code size: 835 bytes / 33 lines
Pitched / IR pitched: No / No
Views / Downloads: 130 / 214
Version history: 6 change(s)
Referenced in: [show references]