本题程序的功能是监听对于列表项的操作。窗口中有一个列表和“添加”、“删除”和“关闭”三个按钮。单击“添加”按钮,会在当前所选列表项后添加一个名为“新增表项”的列表项,同时后台输入列表中的表项数量。单击“删除”按钮,如果未选中表项,则弹出提示消息框“请选择表项”,否则将选中的表项删除,同时后台输出删除表项的内容和列表中的表项数量。单击“关闭”按钮退出程序。程序中存在若干错误,请找出并改正(注意:不得改动程序的结构,不得增行或删行)。 import java.awt.*; import java.awt.event.*; import javax.swing.JOptionPane; public class advance
public static void main(String args[])
final Frame frmFrame = new Frame(); Panel pnlPanel1 = new Panel(); Panel pnlPanel2 = new Panel(); final List istList = new List(8); for(int i = 0; i <10; i++)
String strName = "表项" + (new Integer(i+1)).toString(); istList.add( strName );
Button btnButton1 = new Button("添加"); Button btnButton2 = new Button("删除"); Button btnButton3 = new Button("关闭"); btnButton1.addActionListener( new ActionListener() publiC void actionPerformed(ActionEvent e)