Applet Form

Submitted by Karthik on

import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class appform extends Applet implements ActionListener,ItemListener
{
    Label lh,la,ln,lc,lsw,lf,e1,e2,e3,e4,e5,e6,e7,e8;
    TextField tn,ta;
    Button b1,b2;
    String msg="";
    CheckboxGroup cbg,cbg1;
    Checkbox c1,c2,s1,s2,s3,s4;
    @Override
    public void init()
    {
        e1=new Label();
        e2=new Label();
        e3=new Label();
        e4=new Label();
        e5=new Label();
        e6=new Label();
        e7=new Label();
        e8=new Label();
        setLayout(new GridLayout(8,3));
        lf=new Label();
        lh=new Label("Course Registration");
        ln=new Label("Enter your Name");
        la=new Label("Enter your age");
        lc=new Label("Select  the city");
        lsw=new Label("Select Software");
        tn=new TextField(25);
        ta=new TextField(5);
        cbg=new CheckboxGroup();
        cbg1=new CheckboxGroup();
        c1=new Checkbox("DELHI",cbg,false);
        c2=new Checkbox("MADRAS",cbg,false);
        s1=new Checkbox("ORACLE",cbg1,false);
        s2=new Checkbox("VB",cbg1,false);
        s3=new Checkbox("Java",cbg1,false);
        s4=new Checkbox("C/C++",cbg1,false);
        b1=new Button("OK");
        b2=new Button("Cancel");
        b1.addActionListener(this);
        b2.addActionListener(this);
        c1.addItemListener(this);
        c2.addItemListener(this);
        s1.addItemListener(this);
        s2.addItemListener(this);
        s3.addItemListener(this);
        s4.addItemListener(this);

        add(e1);
        add(lh);
        add(e2);

        add(ln);
        add(tn);
        add(e3);

        add(la);
        add(ta);
        add(e4);

        add(lc);
        add(c1);
        add(c2);

        add(lsw);
        add(s1);
        add(s2);

        add(e5);
        add(s3);
        add(s4);

        add(b1);
        add(b2);
        add(lf);
        add(e7);
        add(e8);
    }
    public void itemStateChanged (ItemEvent ie)
    {
         repaint();
    }
    public void actionPerformed(ActionEvent ae)
    {
    String str=ae.getActionCommand();
        if(str.equals("OK"))
        {
            String s=tn.getText();
            if(s.length()>25)
            {
                e7.setText("Name Should be within 25 characters");
                tn.setText("");
            }
            else
                e7.setText("Thank YOU");
            repaint();
            String age=ta.getText();
            char t=age.charAt(0);
            for(int v = 0; v < age.length(); v++)
            {
                if(Character.isLetter(t)==true)
                {
                    ta.setText(" ");
                    e8.setText("Age Should be Numeric");
                    break;
                }
                else
                {
                    e8.setText(" ");
                }
            }
        }
        if(str.equalsIgnoreCase("CANCEL"))
        {
            ta.setText("  ");
            tn.setText(" ");
            lf.setText(" ");
        }
    }
    public void paint(Graphics g)
    {
        if(s1.getState()==true)
        lf.setText("FEES : 3000");
        if(s2.getState()==true)
        lf.setText("FEES : 2400");
        if(s3.getState()==true)
        lf.setText("FEES : 3500");
        if(s4.getState()==true)
        lf.setText("FEES : 4000");
    }

   
}

Add the following code in html page to load the applet. Remove spaces before opening and closing '><' symbols


< applet code="appform" width="800" height="600" > < /applet >