去掉public void 不然就加上 public class lstItemListener implements ItemListener 去掉void
帮你改好了: java文件:ListExample.java import java.applet.*; import java.awt.*; import java.awt.event.*;public class ListExample extends Applet { public Label labListStatus; public List lstScrollingList;
public void init() { lstScrollingList = new List(3, true); lstScrollingList.add("Moe"); lstScrollingList.add("Larry"); lstScrollingList.add("Curly"); lstScrollingList.add("Shemp"); lstScrollingList.add("Curly Joe");
lstScrollingList.select(3);
add(lstScrollingList);
labListStatus = new Label("You selected entry Shemp"); add(labListStatus);
不然就加上
public class lstItemListener implements ItemListener
去掉void
java文件:ListExample.java
import java.applet.*;
import java.awt.*;
import java.awt.event.*;public class ListExample extends Applet
{
public Label labListStatus;
public List lstScrollingList;
public void init()
{
lstScrollingList = new List(3, true);
lstScrollingList.add("Moe");
lstScrollingList.add("Larry");
lstScrollingList.add("Curly");
lstScrollingList.add("Shemp");
lstScrollingList.add("Curly Joe");
lstScrollingList.select(3);
add(lstScrollingList);
labListStatus = new Label("You selected entry Shemp");
add(labListStatus);
lstScrollingList.addItemListener(new lstItemListener(this.labListStatus, this.lstScrollingList));
}
}class lstItemListener implements ItemListener
{
private Label myLabel;
private List myList;
public lstItemListener(Label pLabel, List pList)
{
this.myLabel = pLabel;
this.myList = pList;
}
public void itemStateChanged(ItemEvent even)
{
String selectionString;
String selection;
int selectionNum;
if (even.getStateChange() == ItemEvent.SELECTED)
{
selectionNum = ((Integer)even.getItem()).intValue();
selection = myList.getItem(selectionNum);
selectionString = "You select " + selection;
myLabel.setText(selectionString);
System.out.println(selectionString);
}
else
{
selectionNum = ((Integer)even.getItem()).intValue();
selection = myList.getItem(selectionNum);
selectionString = "You deselect " + selection;
myLabel.setText(selectionString);
System.out.println(selectionString);
}
}
}html文件:ListExample.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD><BODY>
<applet code="ListExample" width="400" height="300">
</applet>
</BODY>
</HTML>运行命令:
appletviewer ListExample.html