getItemSelectable()不懂呀

hailun 2005-11-20 10:05:38
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class Example13_2 extends Applet implements ItemListener
{
Checkbox box1,box2,box3,box4;
TextArea text;
public void init()
{
box1=new Checkbox("->");box2=new Checkbox(" ");//向上符号不会输入呵呵
box3=new Checkbox("<- ");box4=new Checkbox(" ");//向下的也不会就空下了
box1.addItemListener(this);
box2.addItemListener(this);
box3.addItemListener(this);
box4.addItemListener(this);
text=new TextArea(16,18);
add(box1);add(box2);
add(box3);add(box4);
add(text);
}
public void itemStateChanged(ItemEvent e)
{
Checkbox box=(Checkbox)e.getItemSelectable(); //返回的事件源是什么?为什么要转换成Checkbox类类型呢
if(box.getState())
{
int n=text.getCaretPosition();
text.insert(box.getLabel(),n);
box.setState(false);
}
}
}
...全文
194 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Sun_Java_Fan 2005-11-21
  • 打赏
  • 举报
回复
我做扫雷的时候刚好也遇到了这个问题,现在终于知道如何处理了。
zhuyan911 2005-11-20
  • 打赏
  • 举报
回复
ItemListener的监听事件
静如流水 2005-11-20
  • 打赏
  • 举报
回复
public ItemSelectable getItemSelectable()

Returns:
the ItemSelectable object that originated the event.

The interface for objects which contain a set of items for which zero or more can be selected.

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧