Problem Statement:
Create Java program to enter BioData of Student,
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);
optMale=new JRadioButton(“Male”);
pnlOk=new JPanel();
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(txtTelephone);
c.add(pnlGender);
c.add(cmbQual);
setSize(400,220);
add(btnSubmit); add(btnClose);
});
}); }
|
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:
Thanx for Reading the article, this is my First Java article .

