Syntax for Execute this program :
Firstly then name of class and file should be and run your java file
Syntax : Appletviewer filename.java
Example : Appletviewer simple_applet.javaimport java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.awt.Checkbox;
import java.awt.CheckboxGroup;
/*
<html>
<body>
<applet code="app_form" width=800 height=600>
</applet>
</body>
</html>
*/
public class app_form extends Applet implements ActionListener , ItemListener
{
String f_name, l_name;
String s1,s2,fo1,s3,s4,s5,s6,s11,s22,s33,s44,s55,fo,s7;
Label app;
Label fn;
Label ln;
Label fan;
Label age;
Label gen;
Label hob;
Checkbox foot;
Checkbox cri;
Checkbox other;
TextField fn1;
TextField ln1;
TextField fan1;
TextField age1;
TextField gen1;
Button sub;
public void init()
{
app = new Label("APPLICATION FORM");
fn = new Label("First Name :");
ln = new Label("Last Name :");
fan = new Label("Father's Name :");
age = new Label("Age :");
gen = new Label("Gender :");
hob = new Label("Hobbies :");
foot =new Checkbox("football");
cri =new Checkbox("cricket");
fn1 = new TextField();
ln1 = new TextField();
fan1 = new TextField();
age1 = new TextField();
gen1 = new TextField();
sub = new Button("Submit");
add(app);
add(fn);
add(fn1);
add(ln);
add(ln1);
add(fan);
add(fan1);
add(age);
add(age1);
add(gen);
add(gen1);
add(hob);
add(foot);
add(cri);
add(sub);
setLayout(null);
app.setBounds(300,20,200,20);
fn.setBounds(200,50,150,20);
fn1.setBounds(380,50,150,20);
ln.setBounds(200,80,150,20);
ln1.setBounds(380,80,150,20);
fan.setBounds(200,110,150,20);
fan1.setBounds(380,110,150,20);
age.setBounds(200,140,150,20);
age1.setBounds(380,140,150,20);
gen.setBounds(200,170,150,20);
gen1.setBounds(380,170,150,20);
hob.setBounds(200,210,150,20);
foot.setBounds(380,210,100,30);
cri.setBounds(490,210,100,30);
sub.setBounds(200,250,150,20);
sub.addActionListener(this);
foot.addItemListener(this);
cri.addItemListener(this);
}
public void itemStateChanged(ItemEvent ie)
{
if(foot.getState() && cri.getState())
{
fo="football and cricket";
}
else if(cri.getState())
{
fo="cricket";
}
else if(foot.getState())
{
fo="football";
}
}
public void actionPerformed(ActionEvent ae)
{
String s = ae.getActionCommand();
if(s.equals("Submit"))
{
s1 = "FIRST NAME : ";
s11 = fn1.getText();
s2 = "LAST NAME : ";
s22 = ln1.getText();
s3 = "FATHER'S NAME : ";
s33 = fan1.getText();
s4 = "AGE : ";
s44 = age1.getText();
s5 = "GENDER : ";
s55 = gen1.getText();
s6 = "HOBBIES : ";
s7=fo;
repaint();
}
}
public void paint(Graphics g)
{
g.drawString(s1,200,325);
g.drawString(s11,400,325);
g.drawString(s2,200,350);
g.drawString(s22,400,350);
g.drawString(s3,200,375);
g.drawString(s33,400,375);
g.drawString(s4,200,400);
g.drawString(s44,400,400);
g.drawString(s5,200,425);
g.drawString(s55,400,425);
g.drawString(s6,200,450);
g.drawString(s7,400,450);
}
}
OUTPUT
