Solved

Switching text in TextArea.

Posted on 2004-04-14
4
231 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
  • 2
  • 2
4 Comments
 
LVL 13

Accepted Solution

by:
Webstorm earned 40 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 40 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

713 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