Libraryless. Click here for Pure Java version (143L/2K/5K).
!747 !awt { !actionListener { m { p { final new JTextArea textArea; makeFrame(new JScrollPane(textArea)); final new StringBuffer buf; final DelayedUpdate du = new DelayedUpdate(runnable { textArea.append(buf.substring(textArea.getText().length())); }); thread { for (int i = 0; i <= 95; i++) { buf.append(i + " " + now() + "\n"); sleep(100); du.trigger(); } } } static class DelayedUpdate { Runnable renderer; volatile long version; long lastUpdate; // AWT time int delay = 1000; *(Runnable *renderer) {} void trigger() { awt { awt_quickUpdate(); } final long n = ++version; javax.swing.Timer timer = new javax.swing.Timer(delay, actionListener { awt_show(n); }); timer.setRepeats(false); timer.start(); } void awt_quickUpdate() { if (lastUpdate < now()-delay) { render(); lastUpdate = now(); // This can be rough, no problem } } void awt_show(long n) { if (n == version) { render(); lastUpdate = now(); } } void render() { try { renderer.run(); } catch (Throwable e) { e.printStackTrace(); } } } }
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: | 673 / 756 |
Referenced in: | [show references] |