ev.target instanceof Button???不理解,谁帮忙解释一下啊
public boolean action(Event ev, Object arg) {
if (ev.target instanceof Button) {
String textMsg = inputText.getText().trim();
Applet2 applet2 =
(Applet2)getAppletContext().getApplet("applet2");
if ( applet2 != null ) {
applet2.AppendText( textMsg );
return true;
}
else
return false;
}
return false;
}
一:
public boolean action(Event ev, Object arg) {
if (ev.target instanceof Button) {
这两行不理解??
二:
Applet2 applet2 =
(Applet2)getAppletContext().getApplet("applet2");
if ( applet2 != null ) {
这里的
getAppletContext().前为什么有个(Applet2)???
谢谢了啊,刚学几天。
问题点数:20、回复次数:4Top
1 楼leonwu1981(帝力于我何加焉)回复于 2004-08-01 07:57:06 得分 10
getAppletContext().getApplet("applet2")返回的可能是个Object,所以要(Applet2)强制转换一下为Applet2的实例,这样才能实例化applet2。
类似的:Vector v = new Vector();
v.add("hello");
String str = (String)v.get(i);//这里v.get(i).toString()也可以
if (ev.target instanceof Button) { 这个我也不知道,mark学习
Top
2 楼majy()Oo.冲天剑.oO()(为这个国家做点什么吧)回复于 2004-08-01 08:45:26 得分 5
The key word "instanceof" tells you if an object is an instance of a particular type. It returns a boolean so you use it in the form of a question, like this:
if(x instanceof Dog)
((Dog)x).bark();
The if statement checks to see if the object x belongs to the class Dog before casting x to a Dog. It’s important to use instanceof before a downcast when you don’t have other information that tells you the type of the object; otherwise, you’ll end up with a ClassCastException.
这是Think in java上的摘抄,希望对你有所帮助。
Top
3 楼ntzls()回复于 2004-08-01 08:57:52 得分 0
ev.target instanceof Button
看看ev.target是否是Button的实例了
getAppletContext().前为什么有个(Applet2)
不从Object下传到Applet2调不出getAppletContext()方法了Top
4 楼ntzls()回复于 2004-08-01 09:00:55 得分 5
看错了,删掉“
getAppletContext().前为什么有个(Applet2)
不从Object下传到Applet2调不出getAppletContext()方法了”
应该是
(Applet2)将返回的对象Object下传为Applet2类型吧
Top
相关问题
- SCJP -- about instanceof operator
- instanceof的用法?
- 关于instanceof
- button
- instanceof是什么意思?
- button下面的代码:Response.Redirect("/index.aspx", target = "_blank")怎样表达!
- ¥¥¥¥¥¥“安全退出问题”,button下面的代码:Response.Redirect("/index.aspx", target = "_parent")怎样表达!
- 串口类里的EV_CTS,EV_RXFLAG,EV_BREAK,EV_ERR,EV_RING,EV_RXCHAR是什么意思呀?
- 关键字instanceof的含义和用法?
- instanceof关键字的作用是什么?




