?
Solved

Switching text in TextArea.

Posted on 2004-04-14
4
Medium Priority
?
234 Views
Last Modified: 2010-03-31
hi!

I am trying to fine convenient way to switch text(from one sentence to another sentence) in TextArea when button is clicked.
Any suggestions will be helpful...

Thanks,


0
Comment
Question by:dkim18
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 13

Accepted Solution

by:
Webstorm earned 160 total points
ID: 10825860
Hi dkim18,

To change the text you can use setText:

    TextArea ta=new TextArea("first text");
    Button b=new Button("OK");

    ...
    b.addActionListener(
        new ActionListener(){
            public void actionPerformed(ActionEvent ev)
            {
                 // ta.getText();
                 ta.setText("second text");
            }
        }
    }

What do you mean by "to switch text" ? Can you give some examples ?

0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 160 total points
ID: 10825946
You can keep your sentences in arrays:

final String[] SENTENCES = { "xxx", "yyy", "zzz" };
int sentenceIndex = 0;


public void actionPerformed(ActionEvent ev)
{
    ta.setText(SENTENCES[sentenceIndex++ % SENTENCES.length]);
}


0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10826223
8-)
0
 
LVL 13

Expert Comment

by:Webstorm
ID: 10826594
:-)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month14 days, 10 hours left to enroll

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question