How to use methods from two classes in eachother in Java?
<p>I've been looking around and I only found one answer which wasn't clear enough, to me at least.</p>

<p>I am building a very basic chat application with a GUI and I have separated the GUI from the connection stuff. Now I need to call one method from GUI in server class and vice versa. But I don't quite understand how to do it (even with "this"). Here's what a part of code looks like (this is a class named server_frame):</p>

<pre><code>textField.addActionListener(
            new ActionListener() {

                public void actionPerformed(ActionEvent arg0) {
                    try {
                        srv.sendData(arg0.getActionCommand());
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    textField.setText("");
                }
            }
            );
</code></pre>

<p>This is a code from server_frame, srv is an object from the other class (server) which contains sendData method, and I probably didn't define it correctly so hopefully someone could make a definition of it.</p>

<p>On the other side class server from which object srv was made contains method using JTextArea displayArea from server_frame in this code:</p>

<pre><code>private void displayMessage(final String message){
    sf = new server_frame();
    SwingUtilities.invokeLater(new Runnable(){

        public void run(){
            sf.displayArea.append(message);
        }
    }
            );
}
</code></pre>

<p>Yet again sf is an object made of server_frame and yet again probably missdefined :)</p>

<p>Hopefully that was clear enough, sadly I tried the searching but it just didn't give me the results I was looking for, if you need any more info I will gladly add it!</p>

<p>Thanks for reading,</p>

<p>Mr.P.</p>

<p>P.S. Please don't mind if I made terminology mishaps, I am still quite new to java and open to any corrections!</p>
