e5_15x.java
来自「java 初学者学习实例」· Java 代码 · 共 59 行
JAVA
59 行
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class E5_15x extends Applet implements ItemListener
{
Choice choice1,choice2;
TextField text1,text2;
public void init()
{
setLayout(new GridLayout(2,2));
choice1 = new Choice();
choice2 = new Choice();
text1 = new TextField(10);
text2 = new TextField(10);
choice1.add("音乐天地");
choice1.add("武术天地");
choice1.add("象棋乐园");
choice1.add("交友聊天");
choice2.add("辽宁日报");
choice2.add("北京日报");
choice2.add("上海日报");
choice2.add("足球晚报");
add(choice1);add(choice2);
choice1.addItemListener(this);
add(choice1);add(choice2);
choice2.addItemListener(this);
add(text1);add(text2);
}
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 + -
显示快捷键?