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

import java.util.*;

import javax.swing.*;

public class FirstClass extends JFrame implements ActionListener {
   private JButton callsec;
   private JLabel data;
   private SecondClass sec;
   public FirstClass() {
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      getContentPane().setLayout(new GridLayout(1, 2));
      callsec = new JButton("Open Second");
      callsec.addActionListener(this);
      getContentPane().add(callsec);
      data = new JLabel("Not updated yet");
      getContentPane().add(data);
      pack();
   }
   public void update() {
      data.setText("I am updated " + new Date());
   }
   public void actionPerformed(ActionEvent ev) {
      sec = new SecondClass(this);
      sec.show();
   }
   public static void main(String[] args) {
      FirstClass f = new FirstClass();
      f.show();
   }
}

class SecondClass extends JFrame implements ActionListener {
   private JButton setfirst;
   private JButton back;
   private FirstClass first;
   public SecondClass(FirstClass first) {
      this.first = first;
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      getContentPane().setLayout(new GridLayout(2, 1));
      setfirst = new JButton("Update");
      setfirst.addActionListener(this);
      getContentPane().add(setfirst);
      back = new JButton("Close");
      back.addActionListener(this);
      getContentPane().add(back);
      pack();
   }
   public void actionPerformed(ActionEvent ev) {
      if (ev.getSource() == setfirst) {
         first.update();
      }
      if (ev.getSource() == back) {
         dispose();
      }
   }
}
