Applet or Application?

I have written a Java app/applet - the program works whether it is started as an applet in IE/netscape/etc, or started by calling javaw.exe.

The problem I have is that I need to know if the program is running as an application, or as an applet inside IE(or other).

Is there anyway I can find this information?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mick BarryJava DeveloperCommented:
a few ways depending on how you've implemented it.
If you are using an Applet subclass in both then getAppletContext() will return null if not an applet.
If you aren't using an Applet subclass for your application then you should be able to derive it from that.
hmm, how come you dont know what you written?
your class extends JApplet to create an Applet...
CheneyAuthor Commented:
What I've written is a program that although extends JApplet, works as a standalone app as well.  When running as a standalone the program needs to create a JFrame to run in, however when running as an applet, the frame is already there - hence the need for the prog. to know wheather it is running as an applet or an application.

Thanks objects, I'll test that then give you the points
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

Mick BarryJava DeveloperCommented:
the other option is to generate your frame inside main() which is only called by app.
CheneyAuthor Commented:
Ok, that didnt quite work.

I tried simply:

if(getAppletContext() == null)
    ... do JFrame creation stuff

however my program exited after a NullPointerException was thrown from inside Applet.getAppletContext().

So, i tried this:

catch(NullPointerException e)
     ... do JFrame creation

which worked... except a NullPointerException is still thrown even if the program IS running as an applet (well, in AppletViewer anyway...).

Any ideas?
Mick BarryJava DeveloperCommented:
depends a bit on when u want to create your frame, your main could call the method to create the frame.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CheneyAuthor Commented:
Ok, it works...

Mick BarryJava DeveloperCommented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.