import
java.awt.Graphics;
//
在进行显示输出时,需要用到类Graphics的对象;
import java.applet.Applet; // Applet类是所有的javaapplet的父类;
public class HelloEducation extends Applet {
public Strings;
public void init() {
s = new String( " HelloWorld! " );
}
public void paint(Graphicsg) {
g.drawString(s, 15 , 15 );
}
}
import java.applet.Applet; // Applet类是所有的javaapplet的父类;
public class HelloEducation extends Applet {
public Strings;
public void init() {
s = new String( " HelloWorld! " );
}
public void paint(Graphicsg) {
g.drawString(s, 15 , 15 );
}
}
HelloEducation.java程序经过编译以后就生成了HelloEducation.class文件。java applet的执行方式与java application完全不同,java applet程序必须嵌入到html文件中才能够执行,因此必须编写相应的html文件。下面为HelloEducaiton.html文件的内容:
<
html
>
< applet code =HelloEducation.class width =200 height =200 >
</ applet >
</ html >
< applet code =HelloEducation.class width =200 height =200 >
</ applet >
</ html >
然后可以通过JDK所提供的命令"appletviewer",在命令行下面执行java applet程序。如果是在windows操作系统中,就可以在"命令提示符"下敲入"appletviewer HelloEducation.html"
如图:
此时系统会弹出另外一个窗口运行该applet程序
如图:
如图: