import java.awt.*;
import java.awt.event.*;
class WindowList extends Frame implements ItemListener {
private static final long serialVersionUID = 5901122679079571694L;
private MenuBar menubar;
private Menu menu_AddWord;
private Menu menu_EditWord;
private Menu menu_Version;
private List lst_Word;
private TextArea txt_Explain;
public WindowList() {
// setTitle(s);
Toolkit tool = getToolkit();
Dimension dim = tool.getScreenSize();
setBounds(200, 200, dim.width / 2, dim.height / 2);
menubar = new MenuBar();
menu_AddWord = new Menu("添加");
menu_EditWord = new Menu("编辑");
menu_Version = new Menu("版权信息");
menubar.add(menu_AddWord);
menubar.add(menu_EditWord);
menubar.add(menu_Version);
setMenuBar(menubar);
setVisible(true);
setResizable(false);
lst_Word = new List(20, false);
txt_Explain = new TextArea(50, 58);
lst_Word.add("convenient");
lst_Word.add("cheap");
lst_Word.add("function");
lst_Word.add("add");
lst_Word.add("fashion");
lst_Word.add("interface");
add(lst_Word, BorderLayout.WEST);
add(txt_Explain, BorderLayout.EAST);
lst_Word.addItemListener(this);
txt_Explain.setEditable(false);
}
@Override
public void itemStateChanged(ItemEvent e) {
String name = lst_Word.getSelectedItem();
if (name.equals("convenient")) {
txt_Explain.setText("这个意思1");
} else if (name.equals("cheap")) {
txt_Explain.setText("这个意思2");
} else if (name.equals("function")) {
txt_Explain.setText("这个意思3");
} else if (name.equals("add")) {
txt_Explain.setText("这个意思4");
} else if (name.equals("fashion")) {
txt_Explain.setText("这个意思5");
} else if (name.equals("interface")) {
txt_Explain.setText("这个意思6");
} else {
txt_Explain.setText("没有该单词!");
}
}
}
public class Example7_1 {
public static void main(String args[]) {
new WindowList().setTitle("绪营牌英汉词典");
}
}