AWT Controls-1
AWT Controls-1
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*<applet code="TextFieldDemo" width=300 height=300>
</applet>*/
public class TextFieldDemo extends Applet implements
ActionListener
{
TextField name,password;
public void init()
{
Label name1=new Label("Name",Label.RIGHT);
Label password1=new Label("Password",Label.RIGHT);
name=new TextField(12);
password=new TextField(8);
password.setEchoChar('*');
add(name1);
add(name);
add(password1);
add(password);
name.addActionListener(this);
password.addActionListener(this); }
public void actionPerformed(ActionEvent ae) {
repaint(); }
public void paint(Graphics g)
{
g.drawString("Name:"+name.getText(),6,60);
g.drawString("Password:"+password.getText(),6,100);
} }
TEXTAREA
It a multiline text editor.
Constructors
TextArea ta=new TextArea()-creates an empty textarea
TextArea ta=new TextArea(int numlines,int numchars)-
creates a TextArea field with specified no.of lines and no.ofchar
for each line.
TextArea ta=new TextArea(String str,int numlines,int numchars,int bars)-
creates a TextArea field with specified no.of lines and no.ofchar
for each line and scrollbar scroll the text.
bars=SCROLL_BOTH
SCROLL_VERTICAL,SCROLL_HORIZONTAL,SCROLL_NONE.
import java.awt.*;
import java.applet.*;
import java.awt.TextArea.*;
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
/*<applet code="ListDemo" width=300 height=300>
</applet>*/
public class ListDemo extends Applet implements
ActionListener
{
List l;
public void init() {
l=new List();
l.add("Red");
l.add("Blue");
l.add("Green");
add(l);
l.addActionListener(this); }
public void actionPerformed(ActionEvent ae)
{
String msg=l.getSelectedItem();
if(msg.equals("Red"))
setBackground(Color.red);
if(msg.equals("Blue"))
setBackground(Color.blue);
if(msg.equals("Green"))
setBackground(Color.green); } }