Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

How to launch a webpage from a browser from an application and an applet

 
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
I have a component called MyPanel extending JPanel. Now this MyPanel has a JButton called OK_Button. This JPanel can be added both to a frame or an applet. Now I want that on clicking of this button a webpage (say URL is http://mysite.com/webpage.htm) should be opened in a browser. How do I do it for both application and applet(or JApplet).
Also please tell me how a panel at runtime can know if it is added to a applet or frame or into another JPanel.
public void actionPerformed(ActionEvent ae)
{
/*let us assume that the method isStandAlone() contains the code
for determinig whether the panel is added to an applicaiton or applet.
*/
if(isStandAlone())
{
//for application
....
...what should I write here?
.....
}
else
{
//for applet
...
what should I write here
.................
}
}
hope someone will give me an answer soon
regards
Tanveer

------------------
 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To load a page from an applet, you can use the showDocument() method of the AppletContext interface.
There are 2 declarations:
showDocument(URL,String) //String is the name of the destination frame
showDocument(URL)
Here is an example:
void showPage(String filename){
try{
File f=new File(filename);
getAppletContext().showDocument(f.toURL(),"RightFrame");
}catch (MalformedURLException m){}
}
------------------
Fabrizio Gianneschi
Sun Certified Programmer for Java2 Platform
 
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess you probably want this. It will start your browser and display the specified page.
<pre>
Runtime rt = Runtime.getRuntime();
Process ps = rt.exec("cmd /c \"start " + htmlfname + "\"");
</pre>

Thanks!
Roseanne
Join our SCJD Study Group when certified
[This message has been edited by Roseanne Zhang (edited November 29, 2001).]
 
Tanveer Rameez
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the replies.
Roseanne,your code works allright, but the cmd shell appears for a few seconds. I don't want the shell to appear. How do I do that?
I tried another code:

but this gives runtime exception:
java.io.IOException: CreateProcess: IEXPLORE.EXE localhost/IA/jspHtml/Help/IA60.htm?LEDPropertiesdialogbox error=2
at java.lang.Win32Process.create(Native Method)
at java.lang.Win32Process.<init>(Win32Process.java:66)
at java.lang.Runtime.execInternal(Native Method)
at java.lang.Runtime.exec(Runtime.java:551)
at java.lang.Runtime.exec(Runtime.java:477)
at java.lang.Runtime.exec(Runtime.java:443)
If you can prevent the cmd prompt from appearing in your code, that will be fine. If not , can you tell me why my code gives the exception?
Secondly how do I launch the webpage in Solaris and in Linux?
Thirdly, how can a JPanel which has been added to a JDialog which will pop up from a JApplet and a JFrame. At runtime the JPanel has to know if it is a part of a JDialog that has popped up from a standalone applicaton or from an JApplet.
regards
Tanveer
------------------
 
Tanveer Rameez
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
and one thing. In my own code given above(previos reply), I simply called 'IEXPLORE.EXE". But in reality the default browser may be different.
regards
Tanveer
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic