Java Programming Practical 14
Question 1
Design an applet/application to demonstrate the use of Radio Button and Checkbox.
RadioDemo.java
Java
import java.awt.*;
class RadioDemo extends Frame
{
Checkbox cb1,cb2,cb3,cb4;
CheckboxGroup cbg;
Label l1,l2;
RadioDemo()
{
l1 = new Label("Select Subjects:");
l2 = new Label("Select Gender:");
cb1 = new Checkbox("Java");
cb2 = new Checkbox("Python");
cbg = new CheckboxGroup();
cb3 = new Checkbox("Male",cbg,false);
cb4 = new Checkbox("Female",cbg,false);
setLayout(new FlowLayout());
add(l1);
add(cb1);
add(cb2);
add(l2);
add(cb3);
add(cb4);
setTitle("Checkbox and Radio Buttons");
setSize(500,500);
setVisible(true);
}
public static void main( String args[] )
{
RadioDemo obj=new RadioDemo();
}
}
Output

Question 2
Design an applet/application to create form using Text Filed, Text Area, Button and Label.
FormDemo.java
Java
import java.awt.*;
import java.awt.event.*;
public class FormDemo extends Frame
{
Label nameLabel, addressLabel;
TextField nameTextField;
TextArea addressTextArea;
Button submitButton;
public FormDemo() {
setLayout(new FlowLayout());
nameLabel = new Label("Name:");
add(nameLabel);
nameTextField = new TextField(20);
add(nameTextField);
addressLabel = new Label("Address:");
add(addressLabel);
addressTextArea = new TextArea(5, 20);
add(addressTextArea);
submitButton = new Button("Submit");
add(submitButton);
setTitle("Simple Form");
setSize(400, 300);
setVisible(true);
}
public static void main(String[] args)
{
FormDemo obj=new FormDemo();
}
}
Output

Question 3
Write a program to create three Buttons with Caption OK RESET and CANCEL.
ButtonsDemo.java
Java
import java.awt.*;
class ButtonsDemo extends Frame
{
ButtonsDemo()
{
Button b1=new Button("OK");
Button b2=new Button("RESET");
Button b3=new Button("CANCEL");
b1.setBounds(50,50,50,50);
b2.setBounds(130,50,80,50);
b3.setBounds(230,50,80,50);
setLayout(null);
setTitle("Buttons");
setSize(700,500);
setVisible(true);
add(b1);
add(b2);
add(b3);
}
public static void main(String args[])
{
ButtonsDemo obj=new ButtonsDemo();
}
}
Output

Question 4
Develop an applet/application using List components to add names of 10 different cities.
Cities.java
Java
import java.awt.*;
class Cities extends Frame
{
Cities()
{
Label lb=new Label("Select Cities");
List l=new List(10,true);
l.add("Mumbai");
l.add("Pune");
l.add("Hyderabad");
l.add("Bengaluru");
l.add("Chennai");
l.add("Jaipur");
l.add("Goa");
l.add("Nagpur");
l.add("Nashik");
l.add("Kanpur");
lb.setBounds(50,50,130,50);
l.setBounds(50,100,100,200);
setLayout(null);
setTitle("List of 10 Cities");
setSize(700,500);
setVisible(true);
add(lb);
add(l);
}
public static void main(String args[])
{
Cities obj=new Cities();
}
}
Output

Question 5
Develop applet/application to select multiple names of news papers.
Newspapers.java
Java
import java.awt.*;
class Newspapers extends Frame
{
Newspapers()
{
Label lb=new Label("Select Newspapers");
List l=new List(10,true);
l.add("The times of India");
l.add("Hindustan times");
l.add("Dainik Jagaran");
l.add("Sakal");
l.add("Dainik Bhaskar");
l.add("Lokmat");
lb.setBounds(50,50,200,50);
l.setBounds(50,100,150,150);
setLayout(null);
add(lb);
add(l);
setTitle("Newspapers");
setSize(700,500);
setVisible(true);
}
public static void main(String args[])
{
Newspapers obj=new Newspapers();
}
}
Output
