import java.util.*; import java.util.zip.*; import java.util.List; import java.util.regex.*; import java.util.concurrent.*; import java.util.concurrent.atomic.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.text.*; import javax.swing.table.*; import java.io.*; import java.net.*; import java.lang.reflect.*; import java.lang.ref.*; import java.lang.management.*; import java.security.*; import java.security.spec.*; import java.awt.*; import java.awt.event.*; import java.awt.image.*; import javax.imageio.*; import java.math.*; public class main { static JTextArea ta1, ta2; public static void main(String[] args) throws Exception { showSideBySide("Linked Text Areas", withTitle("Left Text", ta1 = newTypeWriterTextArea()), withTitle("Right Text", ta2 = newTypeWriterTextArea())); onUpdate(ta1, new Runnable() { public void run() { try { ta2.setText(ta1.getText()); } catch (Exception __e) { throw __e instanceof RuntimeException ? (RuntimeException) __e : new RuntimeException(__e); }}}); } static JComponent withTitle(String title, Component c) { return withTitle(withTitle_titlePanel(title), c); } static JComponent withTitle_titlePanel(String title) { return new JLabel(title); } static JPanel withTitle(JComponent titleComponent, Component c) { titleComponent.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, UIManager.getColor("Button.borderColor"))); JPanel panel = new JPanel(new BorderLayout()); panel.setBackground(Color.WHITE); panel.add(BorderLayout.NORTH, titleComponent); panel.add(BorderLayout.CENTER, wrap(c)); return panel; } static JFrame showSideBySide(String title, Component c1, Component c2) { JFrame frame = showFrame(title); frame.getContentPane().setLayout(new GridLayout(1, 2)); frame.getContentPane().add(wrap(c1)); frame.getContentPane().add(wrap(c2)); swingUpdate(frame); return frame; } static void onUpdate(JTextComponent c, final Runnable r) { c.getDocument().addDocumentListener(new DocumentListener() { public void insertUpdate(DocumentEvent e) { r.run(); } public void removeUpdate(DocumentEvent e) { r.run(); } public void changedUpdate(DocumentEvent e) { r.run(); } }); } static JTextArea newTypeWriterTextArea() { JTextArea textArea = new JTextArea(); textArea.setFont(new Font("Courier", Font.PLAIN, 14)); return textArea; } static JTextArea newTypeWriterTextArea(String text) { JTextArea textArea = newTypeWriterTextArea(); textArea.setText(text); return textArea; } static JFrame showFrame() { return makeFrame(); } static JFrame showFrame(Component content) { return makeFrame(content); } static JFrame showFrame(String title) { return makeFrame(title); } static JFrame showFrame(String title, Component content) { return makeFrame(title, content); } static Component wrap(Component c) { if (c instanceof JTable || c instanceof JList || c instanceof JTextArea) return new JScrollPane(c); return c; } static void swingUpdate(Component c) { c.revalidate(); c.repaint(); } static JFrame makeFrame() { return makeFrame((Component) null); } static JFrame makeFrame(Component content) { // TODO: get program ID return makeFrame("A JavaX Frame", content); } static JFrame makeFrame(String title) { return makeFrame(title, null); } static JFrame makeFrame(String title, Component content) { JFrame frame = new JFrame(title); if (content != null) frame.getContentPane().add(content); frame.setBounds(300, 100, 500, 400); frame.setVisible(true); //exitOnFrameClose(frame); return frame; } }