2.2 Swing components part-3
2.2 Swing components part-3
String country[]={"India","Aus","U.S.A","England","Newzealand"};
JComboBox cb=new JComboBox(country);
JLabel j2=new JLabel("Select");
public void init()
{
Container cp=getContentPane();
cp.setLayout(new FlowLayout());
cp.add(j2);cp.add(cb);
}
}
Methods-
1.int getSelectedIndex()- returns the index of selected item of the list
2. String getSelectedValue()- returns the selected value of the element of the list
3.void setSelectedIndex(int i)- sets the selected index of the list to I
4.void addElement(Object obj)-add the object into list.
5.void setVisibleRowCount(int v)- set how many visible rows you want
Develop a program to add radiobutton on applet using swing
import javax.swing.*;
import java.awt.*;
public class list extends JApplet
{
String week[]= { "Monday","Tuesday","Wednesday",
"Thursday","Friday","Saturday","Sunday"};
JList b;
public void init()
{
b= new JList(week);
Container cp=getContentPane();
cp.setLayout(new FlowLayout());
cp.add(b);
}
}