List and Choice

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

Enrollment No : 1901160126

Name : Siddhi Dhanaji Sawant


Roll No. : 23
Branch : Information Technology
Semester : 5th
Practical No. 02
---------------------------------------------------------------------------
Aim : Write a program to design a form using the components
List and Choice
X. Program Code
1. Write Java Program to show following output.

Program Code:
/*<applet code="Pra2_2" width ="300" height="300" >
</applet>*/
import java.awt.*;
import java.applet.Applet;
public class Pra2_1 extends Applet
{
public void init()
{
List l1=new List(3);
l1.add("Summer");
l1.add("Winter");
l1.add("Rainy");
add(l1);
}
}

XII. Practical Related Questions


1. Write the name of components used in following output.
Answer : List component is used in this above output.

2. State the difference between List and Choice control.


Answer:
A Choice is displayed in a compact form that
requires you to pull it down to see the list of available choices.
Only one item may be selected from a Choice.Choice is the
act of picking or deciding between two or more possibilities.
Only one item may be selected from a choice. 
A List may be displayed in such a way that several
List items are visible. A List supports the selection of one or
more List items. A list is any enumeration of a set of items.  A
List supports the selection of one or more list items.

3. Write the use of getSelectedItem() and


getSelectedIndex() for List.
Answer :
getSelectedIndex( returns the index of the currently
) selected item.
getSelectedItem() gets a representation of the current
choice as a string.

XIII. Exercise
1. Develop an applet/ application using List components to
add names of 10 different cities.
Code :
/*<applet code="Pra2_2" width ="300" height="300" >
</applet>*/

import java.awt.*;
import java.applet.Applet;
public class Pra2_2 extends Applet
{
public void init()
{
List l1=new List(3);
l1.add("Kalyan");
l1.add("Dombivali");
l1.add("Vasai");
l1.add("Virar");
l1.add("Solapur");
l1.add("Jalgaon");
l1.add("Amravati");
l1.add("Akola");
l1.add("Panvel");
l1.add("Latur");
add(l1);
}
}

Output :
2. Develop applet / application to select multiple names of
news papers.
Code :
/*
<applet code="News" width=300 height=300></applet>
*/
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class News extends Applet
{
public void init()
{
List l1=new List(10,true);
l1.setBounds(50,60,100,120);
l1.add("Times of India");
l1.add("Pudhari");
l1.add("Lokmat");
l1.add("The Hindu");
add(l1);
setLayout(null);
}
public void paint(Graphics g)
{
repaint();
}
}

Output :

You might also like