Libraryless. Click here for Pure Java version (143L/2K/5K).
1 | !747 |
2 | !awt { |
3 | !actionListener { |
4 | |
5 | m { |
6 | p { |
7 | final new JTextArea textArea; |
8 | makeFrame(new JScrollPane(textArea)); |
9 | |
10 | final new StringBuffer buf; |
11 | |
12 | final DelayedUpdate du = new DelayedUpdate(runnable { |
13 | textArea.append(buf.substring(textArea.getText().length())); |
14 | }); |
15 | |
16 | thread { |
17 | for (int i = 0; i <= 95; i++) { |
18 | buf.append(i + " " + now() + "\n"); |
19 | sleep(100); |
20 | du.trigger(); |
21 | } |
22 | } |
23 | } |
24 | |
25 | static class DelayedUpdate { |
26 | Runnable renderer; |
27 | volatile long version; |
28 | long lastUpdate; // AWT time |
29 | int delay = 1000; |
30 | |
31 | *(Runnable *renderer) {} |
32 | |
33 | void trigger() { |
34 | awt { |
35 | awt_quickUpdate(); |
36 | } |
37 | |
38 | final long n = ++version; |
39 | |
40 | javax.swing.Timer timer = new javax.swing.Timer(delay, actionListener { |
41 | awt_show(n); |
42 | }); |
43 | timer.setRepeats(false); |
44 | timer.start(); |
45 | } |
46 | |
47 | void awt_quickUpdate() { |
48 | if (lastUpdate < now()-delay) { |
49 | render(); |
50 | lastUpdate = now(); // This can be rough, no problem |
51 | } |
52 | } |
53 | |
54 | void awt_show(long n) { |
55 | if (n == version) { |
56 | render(); |
57 | lastUpdate = now(); |
58 | } |
59 | } |
60 | |
61 | void render() { |
62 | try { |
63 | renderer.run(); |
64 | } catch (Throwable e) { |
65 | e.printStackTrace(); |
66 | } |
67 | } |
68 | } |
69 | } |
Began life as a copy of #1000926 Last line displayed should be "95 ..."
download show line numbers debug dex old transpilations
Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, teubizvjbppd, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1000927 |
Snippet name: | Delayed AWT update test |
Eternal ID of this version: | #1000927/1 |
Text MD5: | bcadf80e96c48653e44621c0d085e3ed |
Transpilation MD5: | 3cd26f9cc5c90907cecc3119ff725c3a |
Author: | stefan |
Category: | javax |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2015-10-20 20:23:48 |
Source code size: | 1386 bytes / 69 lines |
Pitched / IR pitched: | No / Yes |
Views / Downloads: | 674 / 758 |
Referenced in: | [show references] |