2

I am trying to run a java applet with instruction on the textbook. The code is as below.But when I run the appletviewer in cmd the appletviewer is not running. The CMD command is as below

import java.awt.Graphics;
import java.awt.Font;
import java.awt.Color;

public class HelloAgainApplet extends java.applet.Applet{

    Font f = new Font ("TimesRoman" ,Font.BOLD,36);

    public void paint(Graphics g){
        g.setFont(f);
        g.setColor(Color.red);
        g.drawString("HelloAgain!", 5, 50);
    }
}

C:\HTML>appletviewer -debug HelloAgainApplet.class Initializing jdb
 ...
 > run run sun.applet.Main HelloAgainApplet.class VM start exception: VM initialization failed for: C:\Program Files
 (x86)\Java\jdk1.8.0_66\jre\bin\java -Djava.class.path=C:\Program Files
 (x86)\Java\jdk1.8.0_66\jre\phony -Xdebug
 -Xrunjdwp:transport=dt_shmem,address=javadebug66917,suspend=y sun.applet.Main HelloAgainApplet.class

 Error: Could not find or load main class Files

 Fatal error: Target VM failed to initialize.

May I know why the error occurs? Is it that I had not set the classpath for the java appletviewer?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
lawrence
  • 151
  • 1
  • 8
  • You need to pass it the html page *"appletviewer url(s)*" – MadProgrammer Dec 11 '15 at 02:14
  • But I just want the appletviewer to show applet without the html page. – lawrence Dec 11 '15 at 04:48
  • But that's not how the appletviewer works, it uses the html to find and load the applet classes – MadProgrammer Dec 11 '15 at 04:49
  • Look at the example code in the [applet info. page](http://stackoverflow.com/tags/applet/info), It includes the HTML in the source code. Then it can be run using something like `appletviewer HelloWorld.java` (note it is **`.java`** not **`.class`**). – Andrew Thompson Dec 12 '15 at 01:49
  • Thanks You @MadProgrammer. As you say I run the applet in HTML Pages.Now my applet viewer can be running.But I can't run that file in my firefox.Is there any issues.I had enable the security signning in the java control panel with local address of the file import java.awt.Graphics; import java.awt.Font; import java.awt.Color; //import java.applet.*; public class HelloAgainApplet extends java.applet.Applet { Font f = new Font ("TimesRoman" ,Font.BOLD,36); public void paint(Graphics g){ g.setFont(f); g.setColor(Color.red); g.drawString("HelloAgain!", 5, 50); } } – lawrence Dec 12 '15 at 06:00
  • It's been years (literally 10+) since I had to deal with applets at any serious level. I believe that now, your applet MUST be signed before any browser will even look at it, which in my opinion, makes it a dead technology, with many other, better solutions available. Have a look at [Java Applets](https://docs.oracle.com/javase/tutorial/deployment/applet/) for more details – MadProgrammer Dec 12 '15 at 07:30
  • @MadProgrammer. Thanks You. Many thanks to your helping hand.I learn a lot now.And also Andrew Thompson.Thanks You. – lawrence Dec 13 '15 at 03:59

0 Answers0