
import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyEditorSupport;
import java.util.ArrayList;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.JButton;
import javax.swing.JTextArea;
import javax.swing.JScrollPane;

import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.text.Document;


//https://perso.telecom-paristech.fr/hudry/coursJava/interSwing/saisieBis.html

// http://www.java2s.com/Tutorial/Java/0260__Swing-Event/DocumentListenerandDocumentEvent.htm

// https://www.developpez.net/forums/d1513858/java/interfaces-graphiques-java/awt-swing/agents-placement-fenetres/2-jtextfield-relie-documentlistener/ 
// assez bien

// http://jexp.ru/index.php/Java_Tutorial/Swing_Event/DocumentListener

// Property Change Listener

// https://stackoverflow.com/questions/19795872/get-the-parent-text-component-when-a-text-changed-event-occurs

//  a voir http://www.java2s.com/Tutorial/Java/0260__Swing-Event/DocumentListenerandDocumentEvent.htm

public class pipo extends JFrame 
{

	private JPanel contentPane;

	JButton btn_ok; 
	
	
	
	public pipo() 
	{
		setTitle("Properties");
		
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		btn_ok = new JButton("New button");
		btn_ok.setBounds(160, 212, 89, 23);
		btn_ok.addActionListener(new ActionListener() 
		{
			
			@Override
			public void actionPerformed(ActionEvent arg0) 
			{
				// TODO Auto-generated method stub
				dispose();
			}
		});
		
		
		contentPane.add(btn_ok);
		
		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBounds(85, 33, 264, 152);
		contentPane.add(scrollPane);
		
		JTextArea textArea = new JTextArea();
		scrollPane.setViewportView(textArea);
		
		textArea.getDocument().addDocumentListener(new MyDocumentListener());
		  
		  
		  
		  
	}
	
	class MyDocumentListener implements DocumentListener 
	{
       
		@Override
		public void changedUpdate(DocumentEvent arg0) 
		{
			// TODO Auto-generated method stub
			System.out.print("Changed \n");
//			firePropertyChange();
			
		}
		@Override
		public void insertUpdate(DocumentEvent arg0) 
		{
			// TODO Auto-generated method stub
			System.out.print("Insert \n");
			  repaint();
			//firePropertyChange();
			
		}
		@Override
		public void removeUpdate(DocumentEvent arg0) 
		{
			// TODO Auto-generated method stub
			System.out.print("Remove \n");
			  repaint();
			//firePropertyChange();

			
		}
    }
	
	 public void addChangeListener(ChangeListener listener)
	   {
	      changeListeners.add(listener);
	   }
	 
	 private void fireStateChanged(ChangeEvent event)
	   {
	      for (ChangeListener listener : changeListeners)
	         listener.stateChanged(event);
	   }
	   
	   private ArrayList<ChangeListener> changeListeners   = new ArrayList<ChangeListener>();
}
