import java.lang.*;
import java.applet.Applet;
import java.awt.Button;
import java.awt.Label;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/**
*
* @author Karthi
*/
public class Stringapplet extends Applet implements ActionListener
{
Label l1=new Label("Input String");
Label l2=new Label("Output String");
TextField t1=new TextField(20);
TextField t2=new TextField(20);
Button b1=new Button("Upper Case");
Button b2=new Button("Lower Case");
Button b3=new Button("General Case");
public void init()
{
add(l1);
add(t1);
add(l2);
add(t2);
add(b1);
add(b2);
add(b3);
t1.addActionListener(this);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
String a,s1;
if(e.getSource()==b1)
{
a=t1.getText();
a = a.toUpperCase();
t2.setText(a);
}
if(e.getSource()==b2)
{
a=t1.getText();
a = a.toLowerCase();
t2.setText(a);
}
if(e.getSource()==b3)
{
StringBuffer sb=new StringBuffer(t1.getText());
int i=0;
s1="";
a=String.valueOf(sb.charAt(i));
s1=s1+a.toUpperCase();
for(i=1;i<sb.length();i++)
{
if(sb.charAt(i)!=' ')
{
a=String.valueOf(sb.charAt(i));
s1=s1+a.toLowerCase();
}
else
{
s1=s1+' ';
i=i+1;
a=String.valueOf(sb.charAt(i));
s1=s1+a.toUpperCase();
}
}
t2.setText(s1);
}
}
}
No comments:
Post a Comment