ASP ScriptingJava ScriptingCGI ScriptingHTMLJavaLanguage CERP Education Links

JAVA

Find & Replace

import java.awt.*;
public class FindReplace extends Frame 
{
TextArea text; 
Label txt; 
TextField find,repl; 
Label fnd,rpl; 
Button ok;
String f,r,a; 
int i = 0, j = 0; 
public FindReplace()
{
setBackground(Color.gray); 
setTitle("Find and Replace Window"); 
fnd = new Label ("Find  ") ;
rpl  = new Label("Replace  "); 
add(fnd);
add(rpl); 
fnd.reshape(50,150,50,25); 
rpl.reshape(50,175,50,25);
find = new TextField(); 
repl = new TextField(); 
add(find);
add(repl); 
find.reshape(175,150,50,25); 
repl.reshape(175,175,50,25);
txt = new Label ("Enter the Text°) ; 
text = new TextArea();
add(txt);
add(text); 
txt.reshape(50,50,100,25); 
text.reshape(175,50,150,100);
ok = new Button("Replace"); 
add (ok) ;
ok.reshape(250,350,75,25);
public boolean handleEvent(Event e) 
{
if (e.id == Event.WINDOW_DESTROY) 
{
System:exit(0);
return(super.handleEvent(e));
}
public boolean action(Event e,Object arg)
{
if (arg.equals ("Replace") )
{
f = find.getText(); 
r= repl.gettext()
a= text.getText();
i = a.indexOf ( f )'; 
j = r.length ( );
if ( i > 0 )
text.replaceText(r,i,i+j);
}
else
return (super.action(e,arg)); 
repaint();
return true:
}
public static void main(String arg[])
FindReplace t;
t=new FindReplace();
t.resize(400,400);
t.show();
}
}

Output : This code will show the Find & Replace Procedure.

 


Your Ad Here
Not All Of Your Subscribers Use RSS - AWeber Email Marketing
Your Ad Here