Solved

Applet or Application?

Posted on 2003-12-03
8
283 Views
Last Modified: 2013-11-23
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?

Cheers.
0
Comment
Question by:Cheney
  • 4
  • 3
8 Comments
 
LVL 92

Expert Comment

by:objects
ID: 9871792
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.
0
 
LVL 3

Expert Comment

by:InNoCenT_Ch1ld
ID: 9871804
hmm, how come you dont know what you written?
your class extends JApplet to create an Applet...
0
 
LVL 2

Author Comment

by:Cheney
ID: 9872112
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
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 92

Expert Comment

by:objects
ID: 9872127
the other option is to generate your frame inside main() which is only called by app.
0
 
LVL 2

Author Comment

by:Cheney
ID: 9872167
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:

try{getAppletContext();}
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?
Cheers.
0
 
LVL 92

Accepted Solution

by:
objects earned 50 total points
ID: 9872176
depends a bit on when u want to create your frame, your main could call the method to create the frame.
0
 
LVL 2

Author Comment

by:Cheney
ID: 9872320
Ok, it works...

Thanks.
Rick.
0
 
LVL 92

Expert Comment

by:objects
ID: 9872339
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn different types of Android Layout and some basics of an Android App.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question