I need text area help


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: I need text area help

Hybrid View

  1. #1
    edlover Guest

    I need text area help


    OK I have an applet with three panels, North Center and South. North and
    Center each contain a TextArea and South contains a label and two buttons.
    I want to reverse the text in North and set it in center when one of the
    buttons get clicked.Can anyone Look at the code and tell me what I am missing:


    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;

    public class Encryption extends Applet implements ActionListener

    {
    TextArea firstTextArea;
    TextArea secondTextArea;
    Button firstButton;
    Button secondButton;
    public void init()
    {
    firstTextArea = new TextArea();

    secondTextArea = new TextArea();

    Panel p1=new Panel();
    p1.setLayout(new FlowLayout());
    p1.add(firstTextArea);

    Panel p2=new Panel();
    p2.setLayout(new FlowLayout());
    p2.add(secondTextArea);
    secondTextArea.setEditable(false);
    Panel p3=new Panel();
    p3.add(new Label("Welcome to Encryption",Label.LEFT));

    setLayout(new BorderLayout());
    add("North",p1);
    add("Center",p2);
    add("South",p3);

    firstButton = new Button("CLEAR");
    secondButton = new Button("ENCRYPT");
    p3.add(firstButton);
    firstButton.addActionListener(this);
    p3.add(secondButton);
    secondButton.addActionListener(this);
    }
    public void actionPerformed(ActionEvent e)
    {
    String actionCommand = e.getActionCommand();
    if (actionCommand.equals("Encrypt"))
    {
    StringBuffer reverseText = new StringBuffer();
    String cypherText = new String();


    cypherText = (firstTextArea.getText().trim());


    reverseText.append(cypherText);
    reverseText.reverse();

    //Store results of reversal back in original String
    cypherText = reverseText.toString();
    secondTextArea.setText(cypherText);

    }
    else if (actionCommand.equals("Clear"))
    {
    firstTextArea.setText("");
    secondTextArea.setText("");
    }
    }

    }


  2. #2
    Faisal Guest

    Re: I need text area help


    Hi edlover,

    You have to chech for the caption exactly as u have given.
    ie is in getActionCommand().equals("ENCRYPT")AND .("CLEAR");

    cHEERS
    FAISAL



    "edlover" <mr_edward_99@yahoo.com> wrote:
    >
    >OK I have an applet with three panels, North Center and South. North

    and
    >Center each contain a TextArea and South contains a label and two buttons.
    > I want to reverse the text in North and set it in center when one of the
    >buttons get clicked.Can anyone Look at the code and tell me what I am missing:
    >
    >
    >import java.applet.*;
    >import java.awt.*;
    >import java.awt.event.*;
    >
    >public class Encryption extends Applet implements ActionListener
    >
    >{
    > TextArea firstTextArea;
    > TextArea secondTextArea;
    > Button firstButton;
    > Button secondButton;
    > public void init()
    > {
    > firstTextArea = new TextArea();
    >
    > secondTextArea = new TextArea();
    >
    > Panel p1=new Panel();
    > p1.setLayout(new FlowLayout());
    > p1.add(firstTextArea);
    >
    > Panel p2=new Panel();
    > p2.setLayout(new FlowLayout());
    > p2.add(secondTextArea);
    > secondTextArea.setEditable(false);
    > Panel p3=new Panel();
    > p3.add(new Label("Welcome to Encryption",Label.LEFT));
    >
    > setLayout(new BorderLayout());
    > add("North",p1);
    > add("Center",p2);
    > add("South",p3);
    >
    > firstButton = new Button("CLEAR");
    > secondButton = new Button("ENCRYPT");
    > p3.add(firstButton);
    > firstButton.addActionListener(this);
    > p3.add(secondButton);
    > secondButton.addActionListener(this);
    > }
    > public void actionPerformed(ActionEvent e)
    > {
    > String actionCommand = e.getActionCommand();
    > if (actionCommand.equals("Encrypt"))
    > {
    > StringBuffer reverseText = new StringBuffer();
    > String cypherText = new String();
    >
    >
    > cypherText = (firstTextArea.getText().trim());
    >
    >
    > reverseText.append(cypherText);
    > reverseText.reverse();
    >
    > //Store results of reversal back in original String
    > cypherText = reverseText.toString();
    > secondTextArea.setText(cypherText);
    >
    > }
    > else if (actionCommand.equals("Clear"))
    > {
    > firstTextArea.setText("");
    > secondTextArea.setText("");
    > }
    > }
    >
    >}
    >



  3. #3
    edlover Guest

    Re: I need text area help


    Thanks Faisal, So simple, yet it escaped me.







Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center