title: How do I make one event listener to multiple text fields in Java Swing?
body: <p>I have a shell with several Text Widgets.</p>
  
  <p>Each one corresponds to a different <code>String</code> object which saves its input for later processing (after the widget itself is disposed).</p>
  
  <p>I'm using a <code>ModifyListener</code> to update the string each time the text changes, as seen in this simple example:</p>
  
  <pre><code>    String clientNametext = "";
      Text clientName = new Text(composite, SWT.BORDER);
      clientName.addModifyListener(new ModifyListener() {
  
          @Override
          public void modifyText(ModifyEvent paramModifyEvent)
          {
              clientNametext = clientName.getText();
  
          }
      });
  </code></pre>
  
  <p>However, I have many such <code>Text</code> fields and I would like to clean up the code, and - instead of attaching a new inner class listener per field - create a single <code>ModifyListener</code>, which will then be attached to all of them, and modify the correct variable according to which field change triggered the event.</p>
  
  <p>The issue is, the <code>ModifyEvent</code> itself doesn't seem to hold such information, or any way to uniquely identify which text field changed.</p>
  
  <p><strong>EDIT:</strong> It is very important for me to have only one Listener which handles all cases, if possible.</p>
  
  <p>Answers with "use other types of fields and listening objects" are welcome, in case <code>ModifyEvent</code> cannot uniquely identify the exact widget where it occurred, without using some crazy logic with mapping Object IDs or whatnot.</p>