Getting a Name from a menu
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class menu extends Applet implements ItemListener {
Choice colorChoice = new Choice();
public void init() {
setBackground(Color.yellow);
colorChoice.addItem("Red");
colorChoice.addItem("Yellow");
colorChoice.addItem("Green");
colorChoice.addItem("Blue");
colorChoice.addItem("White");
colorChoice.addItem("Black");
colorChoice.addItemListener(this);
add(colorChoice);
}
public void itemStateChanged(ItemEvent evt) {
Choice ch = (Choice)evt.getSource();
String selection = ch.getSelectedItem();
if (selection.equals("Red"))
setBackground(Color.red);
if (selection.equals("Yellow"))
setBackground(Color.yellow);
if (selection.equals("Green"))
setBackground(Color.green);
if (selection.equals("Blue"))
setBackground(Color.blue);
if (selection.equals("White"))
setBackground(Color.white);
if (selection.equals("Black"))
setBackground(Color.black);
}
}