package three.day.applet;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.JApplet;
import javax.swing.JComboBox;
import javax.swing.JLabel;
public class JAppletDemo02 extends JApplet implements ItemListener {
Container ctp = this.getContentPane();
JLabel lb1 = new JLabel("姓名");
JLabel lb2 = new JLabel("英语");
JLabel lb3 = new JLabel("80");
String name[] = { "李林", "赵欣", "张扬", "童梅" };
String score[] = { "80", "94", "75", "87" };
JComboBox cb = new JComboBox();
public void init() {
ctp.setLayout(new FlowLayout());
for (int i = 0; i < name.length; i++) {
cb.addItem(name[i]);
}
cb.addItemListener(this);
ctp.add(lb1);
ctp.add(cb);
ctp.add(lb2);
ctp.add(lb3);
}
@Override
public void itemStateChanged(ItemEvent e) {
int index = 0;
String str = (String) e.getItem();
for (int i = 0; i < name.length; i++) {
if (str == name[i]) {
index = cb.getSelectedIndex();
}
}
lb3.setText(score[index]);
}
}