Solved

Applet or Application?

Posted on 2003-12-03
8
281 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
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.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
eclipse formatting 6 87
ForLoop Example 3 47
map related example 6 47
Custom Java Application connects to database: Which one of the 20? 4 27
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This video teaches viewers about errors in exception handling.

815 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now