Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Applet or Application?

Posted on 2003-12-03
8
Medium Priority
?
287 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
Technology Partners: 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 200 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
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:
Suggested Courses

876 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