find the length of the text in textarea
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
<applet
code="TextArea1" height=200 width=200>
</applet>
*/
public class TextArea1 extends Applet implements
ActionListener
{
TextArea
ta;
TextField
tsp,tep,tlen;
public void init()
{
Label
l1=new Label("Enter the text :");
add(l1);
ta=new
TextArea(10,50);
add(ta);
Label
l2=new Label("Starting Position :");
add(l2);
tsp=new
TextField(20);
tsp.setEditable(false);
add(tsp);
Label
l3=new Label("Ending Position :");
add(l3);
tep=new
TextField(20);
tep.setEditable(false);
add(tep);
Label
l4=new Label("Selection Length:");
add(l4);
tlen=new
TextField(20);
tlen.setEditable(false);
add(tlen);
Button
b=new Button("Show");
add(b);
b.addActionListener(this);
}
public
void actionPerformed(ActionEvent ae)
{
/*get
and set the starting position of the selection */
int
sposition=ta.getSelectionStart();
tsp.setText(sposition+"");
/*get
and set the ending position of the selection */
int
eposition=ta.getSelectionEnd();
tep.setText(eposition+"");
/*get
and set the length of selection */
String
s=ta.getSelectedText();
int
slength=s.length();
tsp.setText(slength+"");
}
}
Comments
Post a Comment