Saturday 7 July 2012

program to illustrate use of Label, TextField in applet.


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

/* <applet code = "applet1" height=150 width=380>
   </applet>
*/

public class applet1 extends Applet implements ActionListener
{
   TextField age,hobby;
  public void init()
      {
            Label l1,l2;
            l1 = new Label("Age :- ",Label.RIGHT);
            l2 = new Label("Hobby :- ");
     
            age=new TextField(5);
            hobby=new TextField(12);
           
            add(l1);
            add(age);
            add(l2);
            add(hobby);
           
            age.addActionListener(this);
            hobby.addActionListener(this);
               
       }
   // User pressed Enter
   public void actionPerformed(ActionEvent ae)
   {
    repaint();
    }
   public void paint(Graphics g)
    {
     g.drawString("Age :- " + age.getText(),6,60);
     g.drawString("Hobby :- " + hobby.getText(),6,80);
    }     
}      

No comments:

Post a Comment