本题的功能是对列表项的操作 包括删除 添加和反选。窗司中有两个列表框和5个按钮 按钮标签代表
问题详情
本题的功能是对列表项的操作,包括删除、添加和反选。窗司中有两个列表框和5个按钮,按钮标签代表着移除列表项的方向,“>”代表只移除选中的列表项,“$amp;>amp;$gt;”代表移除所有的列表项,“!”代表反向选择列表项。 import java.awt.*; import java.awt.event.*; class java3 extends Frame implements ActionListener&ItemListener{ final static int ITEMS=10; List ltList=new List(ITEMS,true); List rtList=new List(0,true); java3{ super("java3"); addWindowListener(new WindowAdapter{ public void windowClosing(WindowEvent e){ System.exit(O); } }); GridBagLayout gbl=new GridBagLayout; setLayout(gbl); add(1tList,0,0,1,5,1.0,1.0); add(rtList。2,O,1,5,1.O,1.O); ltList.addActionListener(this); ltList.addhemListener(this); rtList.addActionListener(this); rtList.addhemListener(this); Button b; add(b=new Button("$amp;>quot;$),1,O,1,1,O,1.0); b.addActionListener(this); add(b=new Button("$amp;>amp;>quot;$),1,1,1,1,0,1.O); b.addActionListener(this); add(b=new Button("$amp;
参考答案
正确答案:
第1处:extends Frame. implements ActionListener,Item-
Listener
第2处:for(int i=0;i<1.getItemCount;i++)
第3处:public void hemStateChanged(ItemEvent evt)
【解析】第1处类可以实现多个接口,接口之间用“,”隔开;第2处reverseSelections方法实现的是反选,遍历列表 获得列表元素数应使用的是getItemCount方法;第3处
Java是大小写敏感的。