Fri Feb 08, 2013 8:55 pm
import java.awt.*;
import java.applet.Applet;
public class UsageList extends Applet {
TextArea output;
List listOne, listTwo;
public void init() {
//Build first list
listOne = new List(4, true);
listOne.addItem("x1");
listOne.addItem("x2");
listOne.addItem("x3");
listOne.addItem("x4");
listOne.addItem("x5");
listOne.addItem("x6");
listOne.addItem("x7");
listTwo = new List();
listTwo.addItem("y1");
listTwo.addItem("y2");
listTwo.addItem("y3");
listTwo.addItem("y4");
listTwo.addItem("y5");
listTwo.addItem("y6");
listTwo.addItem("y7");
//Add lists to the Applet.
GridBagLayout badLayout = new GridBagLayout();
setLayout(badLayout);
output = new TextArea(10, 40);
output.setEditable(false);
GridBagConstraints gridBagConstrain = new GridBagConstraints();
gridBagConstrain.fill = GridBagConstraints.BOTH;
gridBagConstrain.weightx = 1.0;
gridBagConstrain.weighty = 1.0;
gridBagConstrain.gridheight = 2;
badLayout.setConstraints(output, gridBagConstrain);
add(output);
GridBagConstraints bagConstrain = new GridBagConstraints();
bagConstrain.fill = GridBagConstraints.VERTICAL;
bagConstrain.gridwidth = GridBagConstraints.REMAINDER; //end row
badLayout.setConstraints(listOne, bagConstrain);
add(listOne);
badLayout.setConstraints(listTwo, bagConstrain);
add(listTwo);
validate();
}
public boolean action(Event e, Object arg) {
if (e.target instanceof List) {
String language = (e.target == listOne) ?
"listOne" : "listTwo";
output.appendText("Action event occurred on \""
+ (String)arg + "\" in "
+ language + ".\n");
}
return true;
}
public boolean handleEvent(Event e) {
if (e.target instanceof List) {
List list = (List)(e.target);
String language = (list == listOne) ?
"listOne" : "listTwo";
switch (e.id) {
case Event.LIST_SELECT:
int sIndex = ((Integer)e.arg).intValue();
output.appendText("Select event occurred on item #"
+ sIndex + " (\""
+ list.getItem(sIndex) + "\") in "
+ language + ".\n");
break;
case Event.LIST_DESELECT:
int dIndex = ((Integer)e.arg).intValue();
output.appendText("Deselect event occurred on item #"
+ dIndex + " (\""
+ list.getItem(dIndex) + "\") in "
+ language + ".\n");
}
}
return super.handleEvent(e);
}
}
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.