import javax.swing.*;
import java.awt.Graphics;
import java.awt.*;
import java.awt.event.*;

public class  inverseP extends JPanel implements ActionListener
{ 
  JLabel label1;
  JTextField sentencebox;
  JPanel inputPanel;
  JTextArea t;
  String sentence;
  
  public inverseP()
  {    	
	label1=new JLabel("enter your sentence : ");
	t=new JTextArea(" ");
	t.setFont(new Font("Serif",Font.BOLD,24));
	sentencebox=new JTextField("Methinks it is like a weasel                                                ");	
    setLayout(new BorderLayout());
    inputPanel=new JPanel();
    inputPanel.add(label1);
    inputPanel.add(sentencebox);
    add(inputPanel,BorderLayout.NORTH);
    add(t,BorderLayout.CENTER);
    sentencebox.addActionListener(this);
  }
  
  public static String invert(String source) 
  { int i, len = source.length(); 
    StringBuffer dest = new StringBuffer(len); 
    for (i = (len - 1); i >= 0; i--) { 
    dest.append(source.charAt(i)); } 
    return dest.toString(); 
  }
  
  public void actionPerformed( ActionEvent e)
  {
	 if(e.getSource()==sentencebox)
        {   sentence=sentencebox.getText();
	        t.setText(invert(sentence)); }
     repaint();
  }

}
