JavaApplet程序编译注意事项

首先附上一JavaApplet的Helloworld程序,及在html中的嵌入代码:
源代码路径:JavaAppletsrcHelloworld.java
JavaAppletbinJavaTest.html

import java.awt.*;
import java.applet.*;
public class HelloWorld extends Applet
{
	public void paint(Graphics g)
	{
		g.drawString("Hello World!", 5, 35);
	}
}
<HTML>
<HEAD><TITLE>JavaApplet-Text</TITLE></HEAD>
<BODY>
<applet code = "HelloWorld.class" width = 200 height = 200></applet>
</BODY>
</HTML>

要使上述代码正常运行要注意以下几点:
1、Helloworld.java编译成功后会在…bin中生成Helloworld.class文件,要将html文件同class文件放在同一目录下。若不在同一目录,则要在html中加入”codebase”代码,即

<applet code = "HelloWorld.class" codebase= "location" width = 200 height = 200></applet>

2、确保Java是最新版
3、在控制面板->程序->Java->安全设置中,把安全等级调到最低
4、不要为Helloworld创建包(package),否则要在html中指定包名。P.S.目前DS还不会指定包名=。=!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.