Experiment 1
Experiment 1
Experiment 1
Components: AWT provides various components such as buttons, labels, text fields,
checkboxes, etc used for creating GUI elements for Java Applications.
Containers: AWT provides containers like panels, frames, and dialogues to organize and
group components in the Application.
Layout Managers: Layout Managers are responsible for arranging data in the containers sone
of the layout managers are BorderLayout, FlowLayout, etc.
Event Handling: AWT allows the user to handle the events like mouse clicks, key presses,
etc. using event listeners and adapters.
Graphics and Drawing: It is the feature of AWT that helps to draw shapes, insert images and
write text in the components of a Java Application.
import java.awt.*;
public class AwtApp extends Frame {
AwtApp(){
Label firstName = new Label("First Name");
firstName.setBounds(20, 50, 80, 20);
add(firstName);
add(lastName);
add(dob);
add(firstNameTF);
add(lastNameTF);
add(dobTF);
add(sbmt);
add(reset);
setSize(300,300);
setLayout(null);
setVisible(true);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
AwtApp awt = new AwtApp();
}
}
CODE 2:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/*<applet code="swing.class" height=500 width=500></applet>*/
public class swing extends JApplet implements ActionListener
{
JTextField tf;
JLabel l1,l2,l3,l4,l5;
JButton b;
JComboBox cb;
JComboBox cb1;
JList jl;
JRadioButton m,f;
ButtonGroup bg;
JPanel p;
public void init()
{
Color c=new Color(215,248,90);
p=new JPanel();
p.setBackground(c);
l1=new JLabel("Enter Your Name:");
l2=new JLabel("Gender:");
l3=new JLabel("Qualification:");
l4=new JLabel("Hobbies:");
l5=new JLabel("Year:");
tf=new JTextField(20);
b=new JButton("Show");
String str[]={"BA","BBA","BCA","B.TECH","MBA","MA","MCA"};
String str1[]={"Watching TV","Reading BOOKS","Watching MOVIES",
"Playing VIDEO GAMES","Surfing INTERNET"};
String str2[]={"1st Year","IInd Year","IIIrd Year","IVth Year"};
GridBagLayout gl=new GridBagLayout();
GridBagConstraints gbc=new GridBagConstraints();
p.setLayout(gl);
cb=new JComboBox(str);
jl=new JList(str1);
cb1=new JComboBox(str2);
m=new JRadioButton("Male");
f=new JRadioButton("Female");
gbc.gridx=0;
gbc.gridy=0;
gbc.anchor=GridBagConstraints.CENTER;
gbc.fill=GridBagConstraints.HORIZONTAL;
gl.setConstraints(l1,gbc);
p.add(l1);
gbc.gridx=1;
gbc.gridy=0;
gbc.gridwidth=2;
gbc.anchor=GridBagConstraints.CENTER;
gl.setConstraints(tf,gbc);
p.add(tf);
gbc.gridx=0;
gbc.gridy=2;
gbc.gridwidth=1;
gbc.anchor=GridBagConstraints.CENTER;
gl.setConstraints(l2,gbc);
p.add(l2);
bg=new ButtonGroup();
gbc.gridx=1;
gbc.gridy=2;
gbc.anchor=GridBagConstraints.CENTER;