View Single Post
  #2 (permalink)  
Old 01-22-2008, 03:25 AM
hardwired hardwired is offline
Senior Member
 
Join Date: Jul 2007
Posts: 1,189
hardwired is on a distinguished road
Using Appletviewer
Your html file applet tag has a missing bracket ( > ) in it.
I usually avoid using html/web launching of applets because of caching problems. The JRE/plug-in and my ms browsers both like to cache Applets and run them irrespective of changes to their class files.
To avoid this I develop with appletviewer, one of the tools in the sdk/jdk bin. To use it include an applet tag in a comment in your source file. Then, after compiling, run it with "appletviewer AppletName.java" at the prompt.
Here's my console output after compiling and running your applet (renamed to avoid name–clashing in your system). Trying to run it as an application generates the error: no main method found in the file.
Code:
C:\jexp>javac hw.java C:\jexp>appletviewer HW.java C:\jexp>java HW Exception in thread "main" java.lang.NoSuchMethodError: main
You can add a convenience main in your applets so you can run them from the prompt with "java" if you like. Make a Frame and add the applet to the center section of the default BorderLayout. Configure and show the frame like you would for an applcation.
Here's the applet I ran in the tests shown above:
Code:
// <applet code="HW" width="200" height="200"></applet> // to run: at the prompt>appletviewer HW.java import java.applet.Applet; import java.awt.*; public class HW extends Applet { /** Creates a new instance of HW */ public void init() { setBackground(Color.pink); } public void paint(Graphics g) { g.drawString("Hello Luong", 50, 25); } }
Reply With Quote