choice1.java

来自「翁剀JAVA语言那门课程的教案 很多人都看多他的视频教程可惜没有ppt的教案」· Java 代码 · 共 38 行

JAVA
38
字号
//:Choicel.java
// Using drop-down lists
import java.awt.*;
import java.applet.*;

public class Choice1 extends Applet {
	String[] description={"Ebullient","Obtuse",
		"Recalcitrant","Brilliant","Somneacent",
		"Timorous","Florid", "Putrescent"};
	TextField t=new TextField(30);
	Choice c=new Choice();
	Button b=new Button("add items");
	int count =0;
	
	public void init() {
		t.setEditable(false);
		for(int i =0;i < 4; i++)
			c.addItem(description[count++]);
		add(t);
		add(c);
		add(b);
	}
	
	public boolean action (Event evt,Object arg) {
		if(evt.target.equals(c))
			t.setText("index: " + c.getSelectedIndex()
				+ "  " +(String)arg);
		else if(evt.target.equals(b)) {
			if(count < description.length);
				c.addItem(description[count++]);
		}
		else
			return super.action(evt,arg);
		return true;
	}
}

//	<applet code=Choice1.class width=250 height=100></applet>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?