Solved

Switching text in TextArea.

Posted on 2004-04-14
4
233 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 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

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

717 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