// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.awt.event.*;

import javax.swing.*;

public class PrimaryFrame extends JFrame implements ActionListener {
    private JButton btn;
    private SecondaryFrame sf;
    private int n;
    public PrimaryFrame() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setTitle("Primary Frame");
        setSize(300, 300);
        n = 0;
        btn = new JButton("Klik");
        btn.setSize(50, 20);
        btn.addActionListener(this);
        getContentPane().add(btn);
        sf = new SecondaryFrame();
        sf.setVisible(true);
    }
    public void actionPerformed(ActionEvent e) {
        n++;
        sf.append("Du klikkede " + n + ". gang");
    }
    public static void main(String[] args) {
        PrimaryFrame f = new PrimaryFrame();
        f.setVisible(true);
    }
}

class SecondaryFrame extends JFrame {
    private JTextArea ta;
    public SecondaryFrame() {
        setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
        setTitle("Secondary Frame");
        setSize(200, 200);
        ta = new JTextArea();
        getContentPane().add(new JScrollPane(ta));
    }
    public void append(String s) {
        ta.append("\r\n" + s);
    }
}
