Problem Statement:
Create Java program to enter BioData of Student,

Student bio data swing Applet
QuickStart:
Step by Step Guide,
First we will import the java packages
| import java.awt.*; //import awt componentsimport java.awt.event.*; //import awt eventsimport javax.swing.*; //import swing componentsimport javax.swing.JOptionPane.*; //import |
we are implementing the program using applet so we have
to append following lines into the code-
/*
<applet code=”BioData” height=”220″ width=”400″>
</applet>
*/ |
also we are creating an applet so we extend the class from JApplet
| public class BioData extends JApplet |
Perform required declaration of java components in the classs:
JLabel lblName, lblAddress, lblTelephone, lblGender,lblQual;
JTextField txtName, txtAddress, txtTelephone;
JPanel c,pnlGender,pnlOk;
JRadioButton optMale,optFemale;
ButtonGroup optGroup; JComboBox cmbQual;
JButton btnSubmit,btnClose; |
In the constructor we will initialize the previously declared components:
public BioData(){
lblName=new JLabel(“Name:”,JLabel.RIGHT);
txtName=new JTextField(15);
lblAddress=new JLabel(“Address”,JLabel.RIGHT);
txtAddress=new JTextField(15);
lblTelephone=new JLabel(“Telephone”,JLabel.RIGHT);
txtTelephone=new JTextField(15);
lblGender=new JLabel(“Gender”,JLabel.RIGHT);
pnlGender=new JPanel();
optMale=new JRadioButton(“Male”);
optFemale=new JRadioButton(“Female”);
optGroup=new ButtonGroup();
lblQual=new JLabel(“Qualification”,JLabel.RIGHT);
cmbQual=new JComboBox();
pnlOk=new JPanel();
btnSubmit=new JButton(“Submit”);
btnClose=new JButton(“Close”);
c=new JPanel();
} |
In the init() method of JApplet which initializes the JApplet, we add the components
to the applet window container using add() method, this method is called
automatically when you run applet using appletviewer or a browser
public void init(){
setLayout(new FlowLayout(FlowLayout.CENTER));
c.setBackground(new java.awt.Color(204, 204, 255));
c.setLayout(new GridLayout(5,2));
c.add(lblName); c.add(txtName);
c.add(lblAddress);
c.add(txtAddress);
c.add(lblTelephone);
c.add(txtTelephone);
c.add(lblGender);
c.add(pnlGender);
optGroup.add(optMale);
optGroup.add(optFemale);
pnlGender.add(optMale);
pnlGender.add(optFemale);
cmbQual.addItem(“BSc”);
cmbQual.addItem(“BCom”);
cmbQual.addItem(“BA”);
c.add(lblQual);
c.add(cmbQual);
//c.setLocation(0,0);
setSize(400,220);
add(c);
add(btnSubmit);
add(btnClose);
btnClose.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
System.out.println(ae.getActionCommand());
JOptionPane.showMessageDialog(btnClose,ae.getActionCommand());
}
});
btnSubmit.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
System.out.println(ae.getActionCommand());
JOptionPane.showMessageDialog(btnSubmit,ae.getActionCommand());
}
});
}
|
in init() method we are using anonymous classes to handle events, using anonymous
classes in the java applications is the best way for event handling,
Finally, Save the file as “BioData.java”
Open cmd, go to the directory
where the file is located eg. cd Java
Compile program using javac BioData.java
To run the applet use command appletviewer BioData.java
Here’s the output of program:

biodata
Download Source code
Thanx for Reading the article, this is my First Java article .