0

I created a small applet

java.lang.ClassCastException: ssg.com.client.Launcher cannot be cast to java.applet.Applet
    at sun.applet.AppletPanel.createApplet(Unknown Source)
    at sun.applet.AppletPanel.runLoader(Unknown Source)
    at sun.applet.AppletPanel.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

This is my code:

package ssg.com.client.applet;

import java.applet.Applet;

public class GameApplet extends Applet
{

    private static final long serialVersionUID = -3949872561494573440L;

    public GameApplet()
    {

    }
}

The applet launches and shows but I don't like having errors in my code. What can I do?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • `ssg.com.client.Launcher` != `ssg.com.client.applet.GameApplet` – Andrew Thompson Sep 24 '13 at 06:39
  • BTW - 1) Why code an applet? If it is due to spec. by teacher, please refer them to [Why CS teachers should stop teaching Java applets](http://programmers.blogoverflow.com/2013/05/why-cs-teachers-should-stop-teaching-java-applets/). 2) Why AWT rather than Swing? See this answer on [Swing extras over AWT](http://stackoverflow.com/a/6255978/418556) for many good reasons to abandon using AWT components. If you need to support older AWT based APIs, see [Mixing Heavyweight and Lightweight Components](http://www.oracle.com/technetwork/articles/java/mixing-components-433992.html). – Andrew Thompson Sep 24 '13 at 06:40
  • BTW 2 - `public GameApplet() {` Don't create anything in the constructor, the context and stub may not be fully realized by that stage - leave it out completely. Use the `init()` method for setting up the GUI. – Andrew Thompson Sep 24 '13 at 06:50
  • I am calling my GameApplet class from Launcher using new GameApplet(); – Lucas Fray Burchardt Sep 24 '13 at 13:47
  • I figured you were, but that won't work. The applet element in HTML needs to reference an applet. – Andrew Thompson Sep 24 '13 at 13:54

0 Answers0