State the difference between List and Choice control:
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.
Write the use of getSelectedItem() and
getSelectedIndex() for List
getSelectedIndex()
|
returns
the index of the currently selected item.
|
getSelectedItem()
|
gets a
representation of the current choice as a string.
|
Develop an applet using List components to add names
of 10 Different subjects
/*
<applet
code="Subjects" width=300 height=300></applet>
*/
import
java.applet.*;
import
java.awt.*;
import
java.awt.event.*;
public
class Subjects extends Applet
{
public void init()
{
List l1=new
List(10);
l1.setBounds(50,60,100,120);
l1.add("DSU");
l1.add("PIC");
l1.add("OOP");
l1.add("CGR");
l1.add("DTE");
l1.add("Microprocessor");
l1.add("CN");
l1.add("DBMS");
l1.add("SEN");
l1.add("JAVA");
add(l1);
setLayout(null);
}
public void paint(Graphics g)
{
repaint();
}
}
O/P:
Develop applet to select multiple names of news papers
/*
<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("Cwiedu");
l1.add("NDTEV");
l1.add("Gadgets360");
add(l1);
setLayout(null);
}
public void paint(Graphics g)
{
repaint();
}
}
O/p:
Thank you very much
ReplyDeletePlease add a button or link for easy navigation in next practical
ReplyDelete