import java.applet.*; import java.awt.*; public class HiWorld extends Applet { public void paint (Graphics g) { g.drawString ("Hi, world!", 50, 100); } } |
This time, however, you need the following additional file:
<html> <head> <title> Hi World Applet </title> </head> <body> <applet code="HiWorld.class" width=300 height=200></applet> </body> </html> |
To run this program,
HiWorld.java
. (If you are on a PC, you may need to
name the file HiWorld.jav
.) Do not give the file
some other name.
HiWorld.html
is the name
used in this example, but it really doesn't matter.
javac HiWorld.java
HiWorld.class
(I'm not
sure what it is if you only have 3-character extensions.)
appletviewer HiWorld.html
HiWorld.html
in your favorite
browser. (Make sure Java is enabled in your browser.)HiWorld
, then it must be in a file named
HiWorld.java
. For PCs that can't have a four-letter
extension, the name must end in .jav
instead.
If your operating system has case-sensitive file names, the
first part of the file name (HiWorld
in this case)
must be capitalized the same way as in your program.
javac
requires the name of the
file (as you would expect), that is,
HiWorld.java
.
appletviewer
nor your browser cares what the
name of your HTML file is; it only cares that the name specified
after code=
is correct.