testchoice.java
来自「这是一张java应用教程的随书光盘」· Java 代码 · 共 43 行
JAVA
43 行
import java.applet.*; import java.awt.*;
import java.awt.event.*;
public class Testchoice extends Applet implements ItemListener
{ Choice choice1,choice2;
TextArea text1,text2;
public void init()
{ setLayout(new GridLayout(2,2));
choice1=new Choice();
choice2=new Choice();
text1=new TextArea(10,3);
text2=new TextArea(10,3);
choice1.add("物理");
choice1.add("数学");
choice1.add("英语");
choice1.add("政治");
choice2.add("清华大学"); choice2.add("北京大学");
choice2.add("复旦大学"); choice2.add("南开大学");
add(choice1); add(choice2); add(text1); add(text2);
choice1.addItemListener(this);choice2.addItemListener(this);
}
public void itemStateChanged(ItemEvent e)
{ if(e.getItemSelectable()==choice1)
{ if(choice1.getSelectedIndex()==0)
{ text1.setText("你选修的课程是:物理") ;}
else if(choice1.getSelectedIndex()==1)
{ text1.setText("你选修的课程是:数学") ;}
else if(choice1.getSelectedIndex()==2)
{ text1.setText("你选修的课程是:英语") ;}
else if(choice1.getSelectedIndex()==3)
{ text1.setText("你选修的课程是:政治") ;}
}
else if(e.getItemSelectable()==choice2)
{ if(choice2.getSelectedIndex()==0)
{ text2.setText("清华大学是理工为主的综合性大学") ;}
else if(choice2.getSelectedIndex()==1)
{ text2.setText("北京大学是以人文为主的综合性大学") ;}
else if(choice2.getSelectedIndex()==2)
{ text2.setText("复旦大学位于上海市") ;}
else if(choice2.getSelectedIndex()==3)
{ text2.setText("南开大学位于天津市") ;}
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?