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

public class  inverseA extends JApplet implements ActionListener
{ 
  JLabel label1;
  JTextField sentencebox;
  JPanel inputPanel;
  JTextArea t;
  String sentence;

 
  public void init()
  {    
	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)); }
}

    public static void main(String s[])
    {
        JFrame f = new JFrame("inversion of a writing Applet Graphic");
        f.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
        JApplet applet = new inverseA();
        f.getContentPane().add("Center", applet);
        applet.init();
        f.setSize(800,500);
        f.setVisible(true); 
    }  
}
