三、简单应用题(共24分)
本题的功能是对下拉菜单项的操作,包括添加和删除。页面包括一个下拉菜单、一个文本框和两个按钮“删除”和“添加”,选中下拉菜单的一项后,可以通过“删除”按钮从下拉菜单中删除该项,在文本框中填入字符串后,单击“添加”按钮就可以将该项添加到下拉菜单中,所有信息都将显示在右侧的文本域中。
import java.awt.*;
import java.awt.event.*;
public class java2 extends java.applet.Applet imple-
ments hemListener,ActionListener
{Choice choice;
TextField text;
TextArea area;
Button add,del;
public void init() .
{choice:new Choice();
text=new TextField(8);
area:new TextArea(6,15);
choice.add("音乐天地");
choice.add("武术天地");
choice.add("象棋乐园");
choice.add("交友聊天");
add=new Button("添加");
del=new Button("删除");
add.addActionListener(this);
del.addActionListener(this);
choice.addItemListener(this);
add(choice);
add(del);add(text);add(add);add(area);
}
public void itemStateChanged(hemEvent e)
{String name= ;
int index=choice.getSelectedIndex();
area.setText("\n"+index+":"+name);
}
public void actionPerformed(ActionEvent e)
{if(e.getSource()= =add||e.getSource()= =
text)
{String name=text.getText();
if(name.length()>0)
{choice.add(name);
choice.select(name);
area.append("\n添加"+name);
}
}
else if(e.getSource()= =del)
{choice.remove( );
area.append("\n删除"+choice.getSelectedItem
());
}
}
}
正在阅读:
手机被收检讨书范文1000字12-04
马来西亚留学有什么世界?01-22
2022福建中医药大学附属人民医院招聘非在编合同制人员公告【12人】(二)07-14
2018年湖北省武汉市东湖生态旅游风景区管理委员会招聘公告【4人】04-10
餐饮前厅经理工作计划怎么写_前厅经理工作计划怎么写08-21
早读迟到检讨书800字五篇06-08
二年级小学生语文作业题3篇10-15
2016年海南会计继续教育考试试题及答案07-16
早安暖心话短句微信短信05-19