简答题:本题的功能是对下拉菜单项的操作,包括添加和删除。页面包括一个下拉菜单、一个文本框和两个按钮“删除”和“添加”,选中下拉菜

  • 题目分类:Java
  • 题目类型:简答题
  • 查看权限:VIP
题目内容:
本题的功能是对下拉菜单项的操作,包括添加和删除。页面包括一个下拉菜单、一个文本框和两个按钮“删除”和“添加”,选中下拉菜单的一项后,可以通过“删除”按钮从下拉菜单中删除该项,在文本框中填入字符串后,单击“添加”按钮就可以将该项添加到下拉菜单中,所有信息都将显示在右侧的文本域中。
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
());
}
}
}
参考答案:
答案解析:

在Applet中显示文字、图形等信息时,应使用的方法是(  )。

在Applet中显示文字、图形等信息时,应使用的方法是(  )。 A.init() B.start() C.paint() D.destroy()

查看答案

一Have you got a camera?一No.I should buy________.

一Have you got a camera?一No.I should buy________. A.it B.one C.1that D.this

查看答案

Today is Jenny’s wedding day.She________to Tom.

Today is Jenny’s wedding day.She________to Tom. A.just has got married B.has jus

查看答案

Dr. Kanner cured the girl by________

Dr. Kanner cured the girl by________A.using Aristotle's method B.giving her p

查看答案

People are asked__________.

People are asked__________. A.to read the book Safety inFlight B.to find out whe

查看答案