The source code of Java Applet is as follows:
import java.applet.*; import java.awt.*; public class HelloWorldApplet extends Applet { public void paint(Graphics g){ g.drawString("Hello,world" ,40,60); } }
Under Eclipse, you can directly click Run-->Run after programming the program to run the Java Applet program.
In the JDK environment, you need to create an html file in your own Java directory. The file I created here is 1.html. First compile the source program, and then run 1.html with the appletviewer command.
java:
html:
cmd:
Running results:
Open 1.html directly:
Results of running under cmd:
The above is the whole process of how to write and run Java Applets under JDK and Eclipse. I hope it will be helpful to everyone's learning.