It is simple. You can do it in many ways.
One way to do it is to pass your mainFrame to the event listener of
your Jbutton. Like this,
MyActionListener myactionhandler = new MyActionListener(mainFrame);
....
class MyActionListener extends ActionListener {
private textFrame;
public MyActionListener(JFrame f) {
textFrame = f;
}
public void actionPerformed(ActionEvent evt) {
//append text to textFrame here
}