// 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 javax.swing.*;
import java.awt.event.*;

public class Parent extends JFrame {
    private String s;

    private JPanel p;

    public Parent() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(400, 400);
        s = "Noget data";
        p = new MyPanel();
        getContentPane().add(p);
    }

    public String getS() {
        return s;
    }

    public static void main(String[] args) {
        Parent f = new Parent();
        f.setVisible(true);
    }
}

class MyPanel extends JPanel implements ActionListener {
    private JButton btn;

    public MyPanel() {
        super();
        btn = new JButton("Test");
        btn.addActionListener(this);
        add(btn);
    }

    public void actionPerformed(ActionEvent evt) {
        Parent p = (Parent)getParent().getParent().getParent().getParent();
        JOptionPane.showMessageDialog(this, p.getS());
    }
}
