Search code examples
javaactionlistenerjtextfieldgettextjtextarea

How can ActionListener sends the result of the process back to the JTextArea


My question is a bit complicated and as my program is a bit big, I can't put it all here. Anyway, here is the description of the problem: The program has a JTextField, and JTextArea. When the user searches for a word, by getText, and addActionListener it sends the entered word to the action listener, in action listener it search for the result and then print it out in command line. But I want the action listener sends it back to the previous class where there is a JTextArea. To show the result of the search in the text area.

So now in the search part, there is a system.print.out() code, but I should replace something to send it back.

So any idea? Thanks in advance.


Solution

  • public void actionPerformed(ActionEvent e) {
        String result = search(textField.getText());
        textArea.append(result);
    }