Accept string form user and print total no of character in string using button event.
26/11/2009 15:34
/***************************************************
student name:-.
program name:-Accept string form user and print total no
of character in string using button event.
seat no:-
****************************************************/
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.awt.Button;
/*import java.awt.Textield;*/
public class textbox extends Applet implements ActionListener
{
Textfield text1,text2;
Button button1;
int cnt;
public void init()
{
cnt=0;
text1=new Textfield(20);
add(text1);
text2=new Textfield(20);
add(text2);
button1= new Button(this,"CLICK HERE");
add(button1);
button1.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==button1)
{
for(int i=0;i< text1.length();i++)
{
cnt=cnt+1;
}
text1.setText(cnt);
}
}
}
———
Back