import javax.imageio.*; import java.awt.image.*; import java.awt.event.*; import java.awt.*; import java.security.NoSuchAlgorithmException; import java.security.MessageDigest; import java.lang.management.*; import java.lang.ref.*; import java.lang.reflect.*; import java.net.*; import java.io.*; import javax.swing.table.*; import javax.swing.text.*; import javax.swing.event.*; import javax.swing.*; import java.util.concurrent.atomic.*; import java.util.concurrent.*; import java.util.regex.*; import java.util.List; import java.util.zip.*; import java.util.*; public class main { public static void main(String[] args) throws Exception { final JTextArea textArea = new JTextArea(); makeFrame(new JScrollPane(textArea)); final StringBuffer buf = new StringBuffer(); final DelayedUpdate du = new DelayedUpdate(new Runnable() { public void run() { try { textArea.append(buf.substring(textArea.getText().length())); } catch (Exception __e) { throw __e instanceof RuntimeException ? (RuntimeException) __e : new RuntimeException(__e); }}}); Thread _t_0 = new Thread() { public void run() { try { for (int i = 0; i <= 95; i++) { buf.append(i + " " + now() + "\n"); sleep(100); du.trigger(); } } catch (Exception _e) { throw _e instanceof RuntimeException ? (RuntimeException) _e : new RuntimeException(_e); } } }; _t_0.start(); } static class DelayedUpdate { Runnable renderer; volatile long version; long lastUpdate; // AWT time int delay = 1000; DelayedUpdate(Runnable renderer) { this.renderer = renderer;} void trigger() { SwingUtilities.invokeLater(new Runnable() { public void run() { try { awt_quickUpdate(); } catch (Exception _e) { throw _e instanceof RuntimeException ? (RuntimeException) _e : new RuntimeException(_e); } } }); final long n = ++version; javax.swing.Timer timer = new javax.swing.Timer(delay, new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent _evt) { 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(); } } } static void makeFrame(Component content) { // TODO: get program ID makeFrame("A JavaX Frame", content); } static void makeFrame(String title, Component content) { JFrame frame = new JFrame(title); frame.getContentPane().add(content); frame.setBounds(300, 100, 500, 400); frame.setVisible(true); exitOnFrameClose(frame); } static long now_virtualTime; static long now() { return now_virtualTime != 0 ? now_virtualTime : System.currentTimeMillis(); } static void sleep(long ms) { try { Thread.sleep(ms); } catch (Exception e) { throw new RuntimeException(e); } } static void sleep() { try { synchronized(main.class) { main.class.wait(); } } catch (Throwable __e) { throw __e instanceof RuntimeException ? (RuntimeException) __e : new RuntimeException(__e); }} static void exitOnFrameClose(JFrame frame) { frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }