<applet code = "demo.java" width=400 height=200>
<param name="txt" value ="Hey">
</applet>
That code
parameter is incorrect. It should be the fully qualified class name. Or..
<applet code = "demo" width=400 height=200>
<param name="txt" value ="Hey">
</applet>
To compile & launch it in applet viewer from the command line, do something like:
prompt> javac demo.java
prompt> appletviewer demo.java // (see Note)
Note: Yes I do mean the .java
extension. AppletViewer can launch an applet from that comment embedded in the source code. See the Applet info. page (at To compile and launch:) for another example.
Questions/Comments
Debugging
- Ensure the Java Console is configured to show for applets & JWS apps. If there is no output at the default level, raise it and try again.
- Copy/paste all error & exception output the console provides.
Code
- The applet code itself would be better to declare a
String txt
that is declared as a class attribute and initialized in the init()
method, like this txt = getParameter("txt");
. the paint(Graphics)
method might be called many times.
- Any time a
paint(..)
method is overridden, it should immediately call super.paint(..)
(for the BG color, if nothing else).
Questions
- Why code an applet? If it is due to spec. by teacher, please refer them to Why CS teachers should stop teaching Java applets.
- Why AWT rather than Swing? See my answer on Swing extras over AWT for many good reasons to abandon using AWT components.