java – JTextField setText() – Stack Overflow

I was making a GUI to reverse an input string, I am taking input from the first textfield, then reversing the string using my function strRev() then trying to produce the result on the second textfield. But am not getting any output on 2nd textfield.

package com.awt;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.Spring;
import javax.swing.SpringLayout;
import javax.swing.plaf.basic.BasicOptionPaneUI.ButtonActionListener;

import java.awt.FlowLayout;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JTextField;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.InputMethodListener;
import java.awt.event.InputMethodEvent;

public class Buttons{

    private JFrame frame;
    private JTextField textField;
    private JTextField textField_1;

    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    Buttons window = new Buttons();
                    window.frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }
    
    public Buttons() {
        initialize();
    }
    
    public String strRev(String s) {
        char a;
        String ans="";
        for(int i=0;i<s.length();i++) {
            a=s.charAt(i);
            ans=a+ans;
        }
        return ans;
    }

    private void initialize() {
        frame = new JFrame("Label Demo");
        frame.setBounds(150, 200, 450, 300);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
        
        textField = new JTextField();
        frame.getContentPane().add(textField);
        textField.setColumns(10);
        
        JButton okButton = new JButton("Reverse");
        frame.getContentPane().add(okButton);
        
        textField_1 = new JTextField();
        frame.getContentPane().add(textField_1);
        textField_1.setColumns(10);
        
        String str=textField.getText();
        final String ans=strRev(str);
        
        okButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                textField_1.setText(ans);
            }
        });
        
    }

}

The GUI looks like this:-
enter image description here

Please let me know my mistake, Thanks