开始:Applet没有初始化 [英] Start: Applet is not initialized
问题描述
package firstjavaapplet;
import java.awt.Graphics; //程序使用类图形
import javax.swing.JApplet; //程序使用类JApplet
public class FirstJavaApplet extends JApplet
{
//在applet的背景上绘制文本
@Override
public void paint(Graphics g)
{
//调用超类版本的方法paint
super.paint(g);
//在x坐标25和y坐标25处绘制一个String
g.drawString(欢迎使用Java编程!,25,25);
} // end method paint
public static void main(String [] args)
{
FirstJavaApplet obj = new FirstJavaApplet();
}
}
以下是我正在使用的HTML文件将小程序包含在网页中。
< body>
< applet code =FirstJaveApplet.classwidth =300height =300>
< / applet>
< / body>
< / html>
当我在appletviewer FirstJaveApplet.html中运行Applet时,我得到以下内容:
不显示字符串开始:小程序未初始化
< applet code =FirstJaveApplet.classwidth =300height =300>
< / applet>
代码
属性值应为全合格的类名称,而不是applet文件名。所以这应该是:
< applet code =firstjavaapplet.FirstJavaAppletwidth =300 height =300>
< / applet>
请注意,JRE将在名为 firstjavaapplet
。除非课程出现在正确的地方,问题会继续下去。
I am beginner to Applets. Here is code for a basic applet to display string.
package firstjavaapplet;
import java.awt.Graphics; // program uses class Graphics
import javax.swing.JApplet; // program uses class JApplet
public class FirstJavaApplet extends JApplet
{
// draw text on applet’s background
@Override
public void paint( Graphics g )
{
// call superclass version of method paint
super.paint( g );
// draw a String at x-coordinate 25 and y-coordinate 25
g.drawString( "Welcome to Java Programming!", 25, 25 );
} // end method paint
public static void main(String[] args)
{
FirstJavaApplet obj = new FirstJavaApplet();
}
}
Following is HTML file I am using to include applet in webpage.
<body>
<applet code = "FirstJaveApplet.class" width = "300" height = "300">
</applet>
</body>
</html>
When I run Applet in appletviewer FirstJaveApplet.html , I get following:
String is not being displayed rather "Start: applet is not initialized."
<applet code = "FirstJaveApplet.class" width = "300" height = "300">
</applet>
The code
attribute value should be the Fully Qualified Class name as opposed to the applet file name. So that should read:
<applet code = "firstjavaapplet.FirstJavaApplet" width = "300" height = "300">
</applet>
Note that the JRE will search for the class in a sub-directory of the HTML directory named firstjavaapplet
. Unless the class is present in the right place, the problem will continue.
这篇关于开始:Applet没有初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!