做一个Java 下拉列表框 如下图所示 60
3个回答
展开全部
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class L extends Applet implements ItemListener, 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(ItemEvent e) {
String name = choice.getSelectedItem();
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(choice.getSelectedIndex());
area.append("\n删除" + choice.getSelectedItem());
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询