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

public class finestreDialogo extends JFrame
{
	JButton b;
	JTextArea testo;
	Finestra d;
	public finestreDialogo()
	{
		d = new Finestra(this);
		setTitle("finestre dialogo");
		setSize(400,400);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		b = new JButton("premi");
		b.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) {
			d.setVisible(true);
			}});
		JPanel p = new JPanel();
		p.add(b);
		testo = new JTextArea();
		testo.setPreferredSize(new Dimension(350,100));
		p.add(testo);
		
		add(p);
		setVisible(true);
	}
	
	public static void main(String[] a) { finestreDialogo f = new finestreDialogo();}
}

class Finestra extends JFrame
{
	Finestra thisClass;
	finestreDialogo padre;
	JTextField riga;
	JButton ok, cancel;
	public Finestra(finestreDialogo padre)
	{
		thisClass = this;
		this.padre = padre;
		setTitle("f");
		setSize(200,100);
		setLayout(new GridLayout(2,1));
		riga = new JTextField();
		add(riga);
		
		ok = new JButton("ok");
		ok.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) {
			thisClass.padre.testo.append(riga.getText()+"\n");
			setVisible(false);
			}});
		cancel = new JButton("cancel");
		JPanel p = new JPanel();
		p.add(ok);
		p.add(cancel);
		
		add(p);
	}
}
