Solved

Applet or Application?

Posted on 2003-12-03
8
285 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
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

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

628 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