<p>I have a <code>JFrame</code> that contains a "display" <code>JPanel</code> with <code>JTextField</code> and a "control" <code>JPanel</code> with buttons that should access the contents of the display <code>JPanel</code>. I think my problem is related on how to use the observer pattern, which in principle I understand. You need to place listeners and update messages, but I don't have a clue where to put these, how to get access from one panel to the other and maybe if necessary to introduce a "datamodel" class. For example, I want to access the contents of the <code>JTextField</code> from the control panel and I use an anonymous action listener as follows:</p>

<pre><code>JButton openfile = new JButton("Convert file");
openfile.addActionListener(new ActionListener() { 
    public void actionPerformed(ActionEvent e) { 
        openButtonPressed();
    }           
});
</code></pre>

It does make the code cleaner if you create the models in one layer and add a layer or two above to create the components and layout. Certainly do not extend the likes of
```
JFrame
```
and
```
JPanel
```
.
Do not feel the need to make the composition hierarchy in the model layer exactly match the display. Then it's just a matter of taking the text from the
```
Document
```
and performing the relevant operation.
Okay, perhpas not that simple. Swing models are a little bit messy. In particular ButtonModel is brain damaged, and the controller area of code might not be entirely pure.