Solved

Switching text in TextArea.

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
scoresSpecial  challenge 13 40
Understanding websocket example in spring 1 42
maven example error 3 36
Problem to start Neon 20 53
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now