A possibility is:

- in SubFrame: you declare a constructor in for which you pass a reference of your 'outputText' object that you store in a member variable
If you need more elements of your main frame for different actions, directly pass a reference of the main frame and implement on it getters to access the elements that you want to update from your sub-frame
- in actionPerformed, you have access to this variable directly if you passed it or thru a getter if you passed the mainFrame reference



At 06:18 PM 10/25/2002 -0400, Richard A Johnson 973-386-7345 wrote:
I am writing a swing application that has a main application frame,
plus up to three additional frames that it creates.  In my main
frame, I have a JTextArea, and I would like to append text from
any of the other three frames into this text area.  Here are some
code fragments:

========================================================================
class SubFrame extends JFrame implements ActionListener {
        public SubFrame() {
                // construct sub frame
        }

        public void actionPerformed(ActionEvent e) {
                if (some_action) {
                        //
                        // append some text to outputText of MainFrame
                        // This is where I need help!
                        //
                }
        }
}

class MainFrame extends JFrame implements ActionListener {

        JTextArea outputText;
        JScrollPane outputPanel;

        public MainFrame() {
                //
                // create the output text area
                //
                outputText = new JTextArea(6, 20);
                outputPanel = new JScrollPane(outputText);
                getContentPane().add(outputPanel, BorderLayout.SOUTH);
        }

        public void actionPerformed(ActionEvent e) {
                if (some_action) {
                        subFrame = new SubFrame();
                        subFrame.setVisible(true);
                }
        }
}
========================================================================

My question is, how do I reference "outputText" from the SubFrame class?
I tried MainFrame.outputText.append(), but that didn't work.  Do I need
to write a method of MainFrame, or can I simply reference outputText
somehow outside of MainFrame?

Any help would be appreciated.

Rich

_______________________________________________
Swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/swing
_______________________________________________
Swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/swing

Reply via email to