繁体   English   中英

为什么不将java.awt.Image视为java.awt.Component?

[英]Why java.awt.Image is not considered as java.awt.Component?

我试图在组件和图像之间切换面板的内容,它适用于组件:

imgpanel.removeAll();
Component comp;
if ((comp = player.getVisualComponent()) != null) {
    imgpanel.add(comp);
}

不适用于图片:

btoi = new BufferToImage((VideoFormat) buf.getFormat());
img = btoi.createImage(buf);
imgpanel.removeAll();
imgpanel.add(img);//The method add(Component) in the type Container is not applicable for the arguments (Image)

我该怎么办?

为什么java.awt.Image不被视为java.awt.Component

Image扩展Object IE浏览器

  • Object
    • Image

Component还扩展了Object IE浏览器

  • Object
    • Component

由于既没有Component扩展Image ,也没有Image扩展Component ,所以两者都不存在彼此之间的关系。 OTOH两者仅与Object 关系。 IE Image Object ,而Component Object

我该怎么办?

在用于显示图像的Component中显示图像,例如JLabel (中的ImageIcon )。 因此可能看起来像这样:

panel.add( new JLabel( new ImageIcon(image) ) );

对于此概念的更多详细信息,请参阅继承教程的“接口和继承”部分。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM