0% found this document useful (0 votes)
9 views5 pages

1.3.2 AWT Controls & Layout Manager Part-7

Uploaded by

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

1.3.2 AWT Controls & Layout Manager Part-7

Uploaded by

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

Choice-

- used to show pop up menu of choices


- Selected choice is shown on the top of the menu.

Constructor-
Choice() : creates an new empty choice menu .

Methods-
1. void add(String s)- adds an item to this Choice menu
2. String getItem(int i)- gets the string at the specified index in this Choice menu
3. int getItemCount()- returns the number of items in this Choice menu
4. String getSelectedItem()- gets a representation of the current choice as a string.
5. int getSelectedIndex()- returns the index of the currently selected item.
6. void select(int p)- set the currently selected item with specified index
Program- Develop a program to add choice on applet
import java.awt.*;
import java.applet.*;
public class choicedemo extends Applet
{
Choice c;
public void init()
{
c=new Choice();
c.add("FY");
c.add("SY");
c.add("TY");
add(c);
}
}

/* <applet code=choicedemo width=200 height=300> </applet> */

Note- compile using javac choice.java and execute it by appletviewer choice.java


List
- The List represents a list of text items.
-user can choose either one item or multiple items.

Constructor-
1. List() -Creates a new scrolling list.
2. List(int rows) -Creates a new scrolling list initialized with the specified number of
visible lines.
3. List(int rows, boolean multipleMode) -Creates a new scrolling list initialized to
display the specified number of rows.
Methods
1. void add(String item) - Adds the specified item to the end of scrolling list
2. void add(String item, int index) - the specified item to the the scrolling list at the
position indicated by the index.
3. void addItem(String item)- Adds the specified item to the end of scrolling list
4. void addItem(String item, int index) - Adds the specified item to the the scrolling
list at the position indicated by the index.
5. String getItem(int index) - Gets the item associated with the specified index.
6. int getItemCount() - Gets the number of items in the list.
7. String[] getItems()- Gets the items in the list.
8. int getSelectedIndex() -Gets the index of the selected item on the list
9. String getSelectedItem() -Gets the selected item on this scrolling list.
10. void remove(int position) -Removes the item at the specified position from this
scrolling list.
11. void remove(String item)-Removes the first occurrence of an item from the list.
12. void removeAll() -Removes all items from this list.
Program- Develop a program to add list on applet
import java.awt.*;
import java.applet.*;
public class ListExample extends Applet
{
List l1=new List(3);
public void init()
{

l1.add("Item 1");
l1.add("Item 2");
l1.add("Item 3");
l1.add("Item 4");
l1.add("Item 5");
add(l1);
}
}
/* <applet code=ListExample width=200 height=300> </applet> */

Note- compile using javac ListExample.java and execute it by appletviewer ListExample.java

You might also like