Practical 1: Write a program to Demonstrate the use of AWT Components like Label, Textfield, TextArea, Button, Checkbox, RadioButton and etc.

1) Design a applet/application to demonstrate the use of Radio Button and Checkbox.
Ans:
import java.awt.*;
import java.util.*;

public class RadioDemo  
{
    public static void main( String args[] )
    {
        Frame f = new Frame();
        f.setVisible(true);
        f.setSize(400,400); 
        f.setLayout(new FlowLayout());
  
       Label l1 = new Label("Select Subjects:");
       
        Checkbox cb1 = new Checkbox("English");
        Checkbox cb2 = new Checkbox("Sanskrit");
        Checkbox cb3 = new Checkbox("Hindi");
        Checkbox cb4 = new Checkbox("Marathi");
        
        Label l2 = new Label("Select Gender:");
       CheckboxGroup cg = new CheckboxGroup();
        Checkbox c1 = new Checkbox("Male",cg,true);        
        Checkbox c2 = new Checkbox("Female",cg,true);        
        
        f.add(l1);
        f.add(cb1);
        f.add(cb2);
        f.add(cb3);
        f.add(cb4);
        f.add(l2); 
        f.add(c1); 
        f.add(c2);
    }

}

Output:
Radio Button and Checkbox

2) Design an applet/application to create form using Text Field, Text Area, Button and Label.
Ans:
import java.awt.*;

public class BasicAWT
{
 public static void main(String args[])
 {
  Frame f = new Frame();
  f.setSize(400,400);
  f.setVisible(true);
  f.setLayout(new FlowLayout() );

  Label l1 = new Label();
  l1.setText("Enter Your Name ");
  
  TextField tf = new TextField("Atharva");

  Label l2 = new Label("Address"); 
  TextArea ta = new TextArea("",3,40);
 
  Button b = new Button("Submit");
  
  f.add(l1); f.add(tf); f.add(l2); f.add(ta); f.add(b);
 }
}



Previous
Next Post »