0% found this document useful (0 votes)
13 views6 pages

1 PR

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views6 pages

1 PR

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

ADV JAVA [22517]

Practical No. 1: Write a program to demonstrate the use of AWT


components.

Program Code:

1. Design an applet/application to demonstrate the use of Radio Button and


Checkbox.

import java.awt.*;
import java.applet.*;
public class appletradiobutton extends Applet
{
Checkbox cb,cb1;
CheckboxGroup cbg;
public void init()
{
setLayout(new FlowLayout());
cb = new Checkbox("this is checkbox");
cbg= new CheckboxGroup();
cb1 = new Checkbox("this is radiobutton",false,cbg);
add(cb);
add(cb1);
}
}

/*
<applet code="appletradiobutton.java" width="500" height="500">
</applet>
*/
Output

2. Design an applet/application to create form using Text Field, Text Area,


Button and Label.

JAY KHANDAGALE (220348)


ADV JAVA [22517]

import java.awt.*;
import java.applet.*;
public class TFTABLForm extends Applet
{
TextField tf;
TextArea ta;
Button b;
Label l1,l2;
public void init()
{
setLayout(new GridLayout(10,10));

l1 = new Label("Name:");
l2 = new Label("Address:");
tf =new TextField("enter name here");
ta =new TextArea("enter address here");
b = new Button("submit");
add(l1);
add(tf);
add(l2);
add(ta);
add(b);

}
}
/*
<applet code= TFTABLForm.java height="500" width="500">
</applet>
*/

Practical Related Questions:

JAY KHANDAGALE (220348)


ADV JAVA [22517]

1. State the difference between CheckBox and RadioButton

Feature Checkbox Radio Button


Allows only one selection from
Selection Allows multiple selections.
a group.
Used for options that can be selected Used for mutually exclusive
Purpose
independently. choices.
Visual Typically represented as a small Typically represented as a
Appearance square. small circle.
Must be part of a
No inherent grouping; multiple
Grouping CheckboxGroup to enforce
checkboxes can be used together.
mutual exclusivity.
Can be selected (checked) or
State Can be checked or unchecked.
not selected (unchecked).
Suitable for scenarios where
Suitable for settings/preferences where
only one option should be
Use Case users can select multiple options (e.g.,
selected (e.g., gender
interests).
selection).
Event Triggered independently when Triggered when the selection
Handling checked or unchecked. changes within the group.

2. Write the use of setEnabled() method.


The setEnabled() method in Java is used to enable or disable components in GUI
applications. When a component is disabled, it is rendered grayed out and does not
respond to user interactions. This method can be applied to various components in
Swing and AWT, such as buttons, text fields, checkboxes, and more.
Syntax
component.setEnabled(boolean enabled);
enabled: If true, the component is enabled; if false, the component is disabled.

3. Draw the life cycle of an Applet

Fig.life cycle of an applet

Exercise:

1. Develop a program using Label to display message “Welcome to Java”

JAY KHANDAGALE (220348)


ADV JAVA [22517]

import java.awt.*;
public class WELCOME extends Frame
{
Label l1;
WELCOME()
{
setLayout(new FlowLayout());
l1 = new Label("Welcome to java");
add(l1);
}
public static void main (String args[])
{
WELCOME w= new WELCOME();
w.setVisible(true);
w.setSize(500,500);
w.setTitle("WELCOME");
}
}
Output

__________________________________________

2. Develop a program to select multiple languages known to user. (e. g Marathi,


Hindi, English, Sanskrit).

import java.awt.*;
public class MLang extends Frame
{
Checkbox cb1,cb2,cb3,cb4;
Label l1;
MLang()
{
setLayout(new FlowLayout());
l1= new Label("select language you know ");

JAY KHANDAGALE (220348)


ADV JAVA [22517]

cb1 = new Checkbox("Marathi");


cb2 = new Checkbox("english");
cb3 = new Checkbox("hindi");
cb4 = new Checkbox("Sanskrit");
add(l1);
add(cb1);
add(cb2);
add(cb3);
add(cb4);
}
public static void main(String args[])
{
MLang ml =new MLang();
ml.setVisible(true);
ml.setSize(500,500);
ml.setTitle("Multiple Languages");
}
}

3, Write a program to create three Buttons with Caption OK, RESET and
CANCEL.
import java.awt.*;

JAY KHANDAGALE (220348)


ADV JAVA [22517]

public class MButtons extends Frame


{
Button b1,b2,b3;
MButtons()
{
setLayout(new FlowLayout());
b1 = new Button("OK");
b2 = new Button("RESET");
b3 = new Button("CANCEL");
add(b1);
add(b2);
add(b3);
}
public static void main(String args[])
{
MButtons mb =new MButtons();
mb.setVisible(true);
mb.setSize(500,500);
mb.setTitle("Multiple Buttons");
}
}

JAY KHANDAGALE (220348)

You might also like