• Post Reply Bookmark Topic Watch Topic
  • New Topic

loading applet from a frame....  RSS feed

 
karan, chopra
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi guys,i wanted to know if its possible to execute an applet from a frame or not..i mean like is there a way so that if i click a certain button on a frame and it loads the applet for me?if yes then please elaborate on the same.i would really appreciate it.
thanks a lot
regards
karan
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

you know that applets exist only in browsers don't you!
well other than local testing with applet-viewer.
- satya
 
karan, chopra
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey,i know that.i guess u didnt understand what i wanted..i wanted to know that if theres a way so that on clicking a button in a frame a browser window opens up and then i pass the applet URL as a string to the browser so that it loads it(this is what i have in mind,there might be some other way also to do this)..i hope i made myself clear this time
regards
karan
 
Amit Agarwal
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Karan,
for executing the applet in a browser window you can use:
Runtime.getRuntime().exec("start c:\\xyz\\abc.html");
on a Windows system. I'm sorry i cannot say anything about other platforms. This command will execute the html page in the default browser, and just a dos command prompt window will flash once.
Also, if you want you can use the Applet from within a JFrame. The applet extends the Panel class, so you can add the applet as any other panel to the content pane of the JFrame. You will have to specifically call the init() method after instantiation of the applet class, and the start() method after the call to the show() or the setVisible(true) of the JFrame.
This can be also done very easily using sun.j3d.utils.applet.MainFrame which comes with the Java3D API. For using this you will have to define a main function in the applet. I am posting hereunder the main function as defined in one of the samples of Java3D.

---------
Amit
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know where people come up with these things...

Applet extends java.awt.Panel, so, of course, you can add it to a Frame just like you would add a regular Panel...

Of course, you can't do some "applet only" things with your applet, such as call getImage(), getCodeBase(), etc. because they rely on the browser to supply these.

To prove that applets can run in a frame, just try this code... replacing someApplet with your applet, of course. If your applet doesn't use any "applet specific" methods you should not have a problem... if it does, you will have to modify your applet. ( For example, having the frame load images and send them to the applet instead of the applet loading them itself. )



-Nate
[This message has been edited by Nathan Pruett (edited June 28, 2001).]
 
karan, chopra
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi nathan,thanks for the help,i tried the code but it gives me the following exception when i click the launch applet button:
Exception occurred during event dispatching:
java.lang.NullPointerException
at Simple.stop(Simple.java:874)
at AppletLauncher$WindowExit.windowClosing(AppletLauncher.java:50)
at java.awt.Window.processWindowEvent(Unknown Source)
at java.awt.Window.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
my applets name is Simple.please help.....
regards
gaurav
PS-and i am sorry for reposting this problem in the other forum..
 
karan, chopra
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh btw,following is my stop method of the applet where the exception is being thrown:
public void stop() {
f.setVisible(false); //line 874,the exception line
}
here f is a frame which i am displaying in the applet and in the stop method i am hiding it.
regards
karan
 
karan, chopra
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if i comment out the line number 874 then i can load the applet.but the line has to be there.so basically now i just have 3 questions:
1.)i am using getcodebase in my applet in order to read data from a text file,so as u mentioned when i execute the applet from the frame,i cannot get the applet read any data from the text file,how can this be taken care of?can i pass something from the frame to the applet?
2.)how can the nullpointerexception in line 874 be taken care of?
3.)the applet opens up in the same window as the frame..can i open it in a separate window and let the frame be there in the background?
please help.i would really appreciate it.
regards
karan
[This message has been edited by karan, chopra (edited June 28, 2001).]
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Karan:
With all due respect,
I don't think this is a good approach. Think about it.
Seems to me that I should start a Stand alone Java
application do something with it. Then it has a button,
when I press this button, it fires up another client
(a browser this time) and runs an Applet.
From a usbility point, IMHO this would not be my choice.
My two cents worth.
regds.
- satya
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!