♠ Posted by Unknown in Core Java at 06:04
Applet: AWT Choice Example
// Write a Java Applet that create a scrolling list with several choices and informs//you a selection and deselection using a label.
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class ChoiceExample extends Applet implements ItemListener
{
Choice choName;
List lstStandard;
String msg;
public void init()
{
choName = new Choice();
lstStandard = new List(4, true);
choName.add("Chhaya");
choName.add("Asha");
choName.add("Rajula");
choName.add("Kamini");
lstStandard.add("F.Y.");
lstStandard.add("S.Y.");
lstStandard.add("T.Y.");
lstStandard.add("P.G.D.C.A.");
add(choName);
add(lstStandard);
choName.addItemListener(this);
lstStandard.addItemListener(this);
lstStandard.select(1);
}
public void itemStateChanged(ItemEvent ie)
{ repaint();}
public void paint(Graphics g)
{
msg = "Current Name : ";
msg += choName.getSelectedItem();
g.drawString(msg, 6, 140);
msg = "Current Standard : ";
msg += lstStandard.getSelectedItem();
g.drawString(msg, 6, 180);
}
}
0 comments:
Post a Comment