Solved

Applet or Application?

Posted on 2003-12-03
8
278 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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)
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
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.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

744 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

13 Experts available now in Live!

Get 1:1 Help Now