Enrollment No: 1901160126
Name: Siddhi Dhanaji Sawant
Roll No.: 23
Branch: Information Technology
Semester: 5th
Practical No. 01
---------------------------------------------------------------------------
Aim : Write a program to demonstrate the use of AWT components.
X. Program Code :
1. Design an applet/application to demonstrate the use of Radio Button and
Checkbox.
Code :
import java.awt.*;
import java.applet.*;
/*
<APPLET Code="RadioButtonTest" Width=500 Height=200>
</APPLET>
*/
public class RadioButtonTest extends Applet
{
public void init( )
{
CheckboxGroup chkgrp = new CheckboxGroup ( );
Checkbox chkRed,chkBlue,chkYellow,chkGreen,chkOrange;
chkRed = new Checkbox("Red", chkgrp, false);
chkBlue = new Checkbox("Blue", chkgrp, false);
chkYellow = new Checkbox("Yellow", chkgrp, false);
chkGreen = new Checkbox("Green", chkgrp, true);
chkOrange = new Checkbox("Orange", chkgrp, false);
add(chkRed);
add(chkBlue);
add(chkYellow);
add(chkGreen);
add(chkOrange);
}
}
Output :
2. Design an applet/application to create form using Text Field, Text Area,
Button and Label.
Code :
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("Manasi");
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);
}
}
OutPut:
XII. Practical Related Questions
1. State the difference between CheckBox and RadioButton.
Answer:
CheckBox RadioButton
Here we mark or check all the Here in RadioButton we just mark a
option over the checkbox single option
The Checkbox are Used for getting RadioButton are used for specific
multiple answers answer
Checkbox are represented by square RadioButton are represented by
box circle
Checkbox are used in Multiple Are used in MCQ Exams,etc
choice option
2. Write the use of setEnabled() method.
Answer : The code setEnabled(false), disables the TextField it is not
selectable and user can’t copy data from it and also user cannot able edit or
copy ,it is just used for preventing purpose from being edited,but it will still
look the same as TextFeild without setEnabled() method.
3. Draw the life cycle of an Applet.
Answer :
XIII. Exercise
1. Develop a program using Label to display message “Welcome to Java”
Code :
import java.awt.*;
class L
{
L()
{
Frame f=new Frame();
Label l1=new Label("Welcome to Java");
l1.setBounds(100,50,120,80);
f.add(l1);
f.setSize(500,500);
f.setLayout(null);
f.setVisible(true);
}
public static void main(String a[])
{
new L();
}
}
OutPut:
2. Develop a program to select multiple languages known to user. (e. g
Marathi, Hindi, English, Sanskrit).
Code :
import java.awt.*;
public class Exp_1_4
{
Exp_1_4()
{
Frame f= new Frame();
Choice c=new Choice();
c.setBounds(100,100, 75,75);
c.add("Marathi");
c.add("Hindi");
c.add("English");
c.add("Sanskrit");
f.add(c);
f.setSize(400,400);
f.setLayout(null);
f.setVisible(true);
}
public static void main(String args[])
{
new Exp_1_4();
}
}
OutPut :
3. Write a program to create three Buttons with Caption OK, RESET and
CANCEL.
Code :
import java.awt.*;
class Exp_1_5 extends Frame
{
Button b1,b2,b3;
Exp_1_5()
{
this.setLayout(null);
b1=new Button("OK");
b2=new Button("RESET");
b3=new Button("CANCEL");
this.add(b1);
this.add(b2);
this.add(b3);
b1.setBounds(100,260,70,40);
b2.setBounds(180,260,70,40);
b3.setBounds(260,260,70,40);
}
public static void main(String args[])
{
Exp_1_5 ml=new Exp_1_5();
ml.setVisible(true);
ml.setSize(400,400);
ml.setTitle("my login window");
}
}
OutPut :