Apollo
Apollo

Reputation: 21

Calling a class in the Main()

I have written a class that is an applet and doesn't contain a main(). Is there any possible way for me to just pass the entire class to main to run it because I can't call all the methods through main, I just use so many things it's impossible.

public static void main(String[] args){ }
public class Travel extends Applet implements MouseListener{
}

It seems Applets don't run main().

Upvotes: 1

Views: 403

Answers (2)

Andrew Thompson
Andrew Thompson

Reputation: 168845

This hybrid demo can not only be run as either an applet or application, but be launched direct from the command line using the source in the applet viewer.

E.G.

prompt> javac HybridApplet.java
prompt> java HybridApplication // Note the 'Application'
prompt> appletviewer HybridApplet.java // Note the '.java'

Exiting the applet in the browser should redirect to the source. It will have no effect in the applet viewer. Applet viewer does not support showDocument(), unlike Appleteer, which does ;).


Edit: Note though, that many things designed as applets leverage methods & classes useful to applets - getClip(), getDocumentBase()..

These are for convenience and mostly have equivalents in other non-applet classes.

Upvotes: 2

Ryan Fernandes
Ryan Fernandes

Reputation: 8536

Create a main method in your applet class and instantiate it from within the main method. If you really want to run the applet though, I suggest using the appletviewer

Upvotes: 0

Related Questions