import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

/**
 * Disposable test Swing app used ONLY to prove CLICK / SETTEXT end-to-end
 * against SwingBridgeAgent, WITHOUT touching the live MCSJ process.
 *
 * Prints to stdout whenever the button is clicked or the text field changes,
 * so we have console proof the agent's simulated interaction actually landed
 * on real Swing components.
 */
public class TestApp {
    public static void main(String[] args) throws Exception {
        SwingUtilities.invokeAndWait(new Runnable() {
            public void run() {
                JFrame frame = new JFrame("SwingBridge Test App");
                frame.setName("TestAppFrame");
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setLayout(new FlowLayout());

                final JTextField field = new JTextField(20);
                field.setName("MyTextField");
                field.setText("initial-value");

                final JButton button = new JButton("ClickMeButton");
                button.setName("MyClickButton");

                final JLabel status = new JLabel("status: idle");
                status.setName("StatusLabel");

                button.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        System.out.println("[TestApp] BUTTON CLICKED. current field text = '" + field.getText() + "'");
                        status.setText("status: clicked!");
                    }
                });

                field.getDocument().addDocumentListener(new javax.swing.event.DocumentListener() {
                    public void insertUpdate(javax.swing.event.DocumentEvent e) { report(); }
                    public void removeUpdate(javax.swing.event.DocumentEvent e) { report(); }
                    public void changedUpdate(javax.swing.event.DocumentEvent e) { report(); }
                    private void report() {
                        System.out.println("[TestApp] FIELD TEXT CHANGED to = '" + field.getText() + "'");
                    }
                });

                frame.add(field);
                frame.add(button);
                frame.add(status);
                frame.pack();
                frame.setLocationRelativeTo(null);
                frame.setVisible(true);
                System.out.println("[TestApp] window shown, ready.");
            }
        });
    }
}
