【发布时间】:2014-06-19 11:50:14
【问题描述】:
谁能解释一下super.paint(g) 的用途,其中g 是Applets 或awt 或swings 或Java 中的Graphics 变量。
我研究了一下,发现是用来override的,但是这个override有什么用呢?
我是初学者。如果可能的话,你能用小号example 解释paint(g) 和super.paint(g) 之间的区别吗?或者请帮我处理这段代码?
/*
Let us consider this code
This has only one paint declaration i.e; subclass's paint method declaration, no declaration for superclass's paint function... when we explicitly call superclass's paint function
what is the use of super.paint(g) and is it going to use superclass's paint declaration??
*/
import java.awt.*;
import java.applet.*;
/*
<applet code="superpaintDemo" height=768 width=1366>
</applet>
*/
class superpaintDemo extends Applet
{
public void paint(Graphics g)
{
super.paint(g);
g.drawString("This is Demo",200,200);
}
}
【问题讨论】:
-
你说的是来自 awt/swing 的油漆吗?我不明白你想了解什么... super 它曾经从父级调用 smthing ,而 paint(g) 到 ... paint (: 看看这里oracle.com/technetwork/java/painting-140037.html 和文档
-
我不会继续修复你的帖子。请查看the help center,了解如何创建好帖子。
-
你能告诉我哪里出错了......格式化时?感谢您的帮助
标签: java applet awt paint super