EchoApplet.java
with the Java code shown
here:
import java.applet.Applet; import java.awt.Graphics; public class EchoApplet extends Applet { String s; public void init () { s = getParameter("text"); if (s == null) s = "What, no parameter to echo?"; } public void paint(Graphics g) { g.drawString(s, 40, 50); g.drawString(s, 40, 70); } }
If compilation succeeds, the compiler creates a file namedjavac EchoApplet.java
EchoApplet.class
. This file contains the
bytecodes of your applet, i.e. the code that is suitable
for the hypothetical system called Java Virtual Machine to run
your program on.
If compilation fails, make sure you typed in and named the program
exactly as shown above.
EchoApplet.html
in the same directory that contains EchoApplet.class
.
This HTML file should contain the following text:
<HTML> <HEAD> <TITLE>The Echo Applet</TITLE> </HEAD> <BODY> <APPLET CODE="EchoApplet.class" WIDTH=200 HEIGHT=100> <PARAM name="text" value="Hello Ana and Bob"> </APPLET> </BODY> </HTML>
appletviewer EchoApplet.html