当前位置: 技术问答>java相关
大家好,请问这两个程序为什么不能达到同样的效果
来源: 互联网 发布时间:2015-01-15
本文导语: 大家好,我是一名JAVA初学者,下面是书上的代码: import java.awt.*; import java.applet.*; class mydrawstring extends Applet { String str1; public void init() { str1="hello"; } public void paint(Graphics g) { g.drawString(str1,20,20); }...
大家好,我是一名JAVA初学者,下面是书上的代码:
import java.awt.*;
import java.applet.*;
class mydrawstring extends Applet
{
String str1;
public void init()
{
str1="hello";
}
public void paint(Graphics g)
{
g.drawString(str1,20,20);
}
}
下面是我自己写的代码:
import java.awt.*;
import java.applet.*;
class mydrawstring extends Applet
{
String str1;
public void init()
{
str1="hello";
}
public void start()
{
(getGraphics()).drawString(str1,20,20);
}
}
请问为什么两个程序不能达到同样的效果,我错在哪里?如果你愿意的话,请讲一下
init(),start(),paint()几个方法的区别,谢谢!
import java.awt.*;
import java.applet.*;
class mydrawstring extends Applet
{
String str1;
public void init()
{
str1="hello";
}
public void paint(Graphics g)
{
g.drawString(str1,20,20);
}
}
下面是我自己写的代码:
import java.awt.*;
import java.applet.*;
class mydrawstring extends Applet
{
String str1;
public void init()
{
str1="hello";
}
public void start()
{
(getGraphics()).drawString(str1,20,20);
}
}
请问为什么两个程序不能达到同样的效果,我错在哪里?如果你愿意的话,请讲一下
init(),start(),paint()几个方法的区别,谢谢!
|
init()
Called by the browser or applet viewer to inform this applet that it has been loaded into the system.
start()
Called by the browser or applet viewer to inform this applet that it should start its execution.
paint(Graphics g)
Paints the container.
执行顺序init->start->paint
Called by the browser or applet viewer to inform this applet that it has been loaded into the system.
start()
Called by the browser or applet viewer to inform this applet that it should start its execution.
paint(Graphics g)
Paints the container.
执行顺序init->start->paint