How to use Text box in java applet?

Hello Friends, 

Today I will explain how can we use Text box in java applet.
In this  program I have print simple user name & password text box…but you can create your own text box.

import java.applet.*;
import java.awt.*;
import java.awt.event.*;

/*


*/

public class ten extends Applet implements ActionListener
{
TextField name,pass;
public void init()
{
Label namep=new Label("NAME:",Label.LEFT);
name=new TextField(15);
System.out.println("vivek");
Label passp=new Label("PASSWORD:",Label.RIGHT);
pass=new TextField(15);

pass.setEchoChar('*');

add(name);
add(pass);
add(namep);
add(passp);

name.addActionListener(this);
pass.addActionListener(this);
}

public void actionPerformed(ActionEvent ae)
{
repaint();
}

public void paint(Graphics g)
{
g.drawString("Name:"+name.getText(),6,60);
g.drawString("Selected Text Name:"+pass.getSelectedText(),6,80);
g.drawString("Password:"+pass.getText(),6,100);
}
}

Leave a Reply