Back to Applets page
Click in the boxes below, select all and copy to grab the applet
HTML listing:
<HTML> <HEAD> <TITLE>Listing 8.8</TITLE> </HEAD> <BODY BGCOLOR=WHITE> <APPLET CODEBASE="classes" CODE="Applet8.class" WIDTH=500 HEIGHT=300> </APPLET> </BODY> </HTML>
Applet listing:
import java.awt.*; import java.applet.Applet; public class Applet8 extends Applet { List firstList, secondList; public void init() { setBackground(Color.white); firstList = new List(3,true); add(new Label("Please choose from the following:")); firstList.addItem("London"); firstList.addItem("Paris"); firstList.addItem("Rome"); firstList.addItem("Detroit"); firstList.addItem("New York"); add(firstList); secondList = new List(3,true); add(secondList); } public boolean handleEvent(Event e) { String[] addItems; if (e.id == Event.LIST_SELECT || e.id == Event.LIST_DESELECT) { addItems = firstList.getSelectedItems(); secondList.clear(); for (int i=0; i<addItems.length; i++) { secondList.addItem(addItems[i]); } repaint(); return true; } return super.handleEvent(e); } }