image对象的getwidth(this)什么意思

fxbird 2004-08-07 12:23:53
它的参数是什么?
...全文
650 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
registered 2004-08-07
  • 打赏
  • 举报
回复
this
代表"这个"类(Class)的对象(Object)或叫实例(instance)
zkjbeyond 2004-08-07
  • 打赏
  • 举报
回复
Abstract class SuperClass
{
float Width;
float getWidth(SuperClass obj);
}

class A extend SuperClass
{
public A(float t)
{
Width=t;
}
public float getWidth(SuperClass obj)
{
return Width;
}
}

class B extend SuperClass

{
public B(float t)
{
Width=t;
}
public float getWidth(SuperClass obj)
{
return Width;
}
}

A a=new A("23.32");
float AWidth=a.getWidth(this);
fxbird 2004-08-07
  • 打赏
  • 举报
回复
可能用于装载网络图片吧,那时会比较慢,但依赖于图片装载的下一步操作如何知道是否装载完呢
zkjbeyond 2004-08-07
  • 打赏
  • 举报
回复
Abstract class SuperClass
{
public public float getWidth();
}

zkjbeyond 2004-08-07
  • 打赏
  • 举报
回复
class A extend SuperClass
{
private float Width;
public float getWidth()
{
return this.Width;
}
}

class B extend SuperClass
{
private float Width;
public float getWidth()
{
return this.Width;
}
}
fxbird 2004-08-07
  • 打赏
  • 举报
回复
我是想问这个方法的参数是什么意思
zncn2 2004-08-07
  • 打赏
  • 举报
回复
其实我从没用到过observer,我建立Image时每次observer参数都传入null,调用getHeight和getWidth也传入null就行了。我觉得observer好像没什么大的用处,看看Graphics中的这个方法

drawImage public abstract boolean drawImage(Image img,
int x,int y,ImageObserver observer)

Draws as much of the specified image as is currently available. ······
If the image has not yet been completely loaded, then drawImage returns false.
As more of the image becomes available, the process that draws the image notifies the specified image observer.

从字面上看他无非就担当一个类似监听者的作用,如果图片文件载入完成,则向这个observer发notify以唤醒之(可能之前observer由于某个原因被阻塞了)

不知他人有何高见?
fxbird 2004-08-07
  • 打赏
  • 举报
回复
observer有什么用?它是如何起作用的?怎么才知道文件已经装载完
zncn2 2004-08-07
  • 打赏
  • 举报
回复
从JDK文档是摘的
------------------------
getWidth

public abstract int getWidth(ImageObserver observer)

Determines the width of the image. If the width is not yet known, this method returns -1 and the specified ImageObserver object is notified later.

Parameters:
observer - an object waiting for the image to be loaded.

Returns:
the width of this image, or -1 if the width is not yet known.

See Also: getHeight(java.awt.image.ImageObserver), ImageObserver

---------------------------------
public interface ImageObserver

An asynchronous update interface for receiving notifications about Image information as the Image is constructed

All Known Implementing Classes:
Component
---------------------------------
Class Component java.lang.Object
|
+--java.awt.Component

All Implemented Interfaces:

ImageObserver, MenuContainer, Serializable
---------------------------------
Component是所有组件的父类,明白了吧
fxbird 2004-08-07
  • 打赏
  • 举报
回复
你们搞错了,我是问image对象的这个方法需要什么参数,this我再不知道,我就不搞java了。

62,622

社区成员

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

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