• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

opening new browser window from applet

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am working on an applet that contains an Internet usage policy for our library patrons to view and "accept" (by clicking on the acceptance button). I have the applet working so that when a patron chooses to browse the Internet from our menu the applet appears. When the patron clicks on the acceptance button, the browser loads Google in the same page. That works for us. Is it possible to have the applet launch in a browser window that does not have an address bar or navigation buttons? If so, I would need help with rewriting the actionPerformed method so that when the patron clicks on the acceptance button that window closes and a new browser window opens.
I hope I am being clear enough. Any help would be greatly appreciated. Thanks in advance. Here is my actionPerformed method:
//This method opens Google when the acceptance button is clicked
public void actionPerformed(ActionEvent evt)
{
if (evt.getSource() == jbtAgree)
{
try
{
AppletContext context = getAppletContext();
URL url = new URL("http://www.google.com");
context.showDocument(url);
}
catch(MalformedURLException ex)
{
}
}
}
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's a two-argument form of "showDocument()" which takes a frame name in addition to the URL; the document is shown in that frame. If you use a non-existent name, a new window is created. Otherwise, I think there's a special name you can use ("__new" ?) which always opens a new frame, although I forget the specifics; maybe someone else remembers.
As this is not an advanced question, I'm moving this to "Applets" for further follow-ups.
 
Donny Frank-Rice
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry about that. Anyway, I figured out how to open up a new browser window by using context.showDocument(url, "_blank");.
I still need to know two things. First, once the new window is open, how do I get the original window (the one with the applet) to close? And second, I would still like to have the applet window without buttons or address bar.
 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To close the window that opened the new window use syntax

to open without adressbar use
 
Donny Frank-Rice
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, Mathias. I'll give it a try and let you know.
 
Donny Frank-Rice
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mathias,
I am not too sure where to place the code you suggested I try. I am still a bit new to java. Could I email you the code to my program and you could tell me where to place it? Thanks.
 
Mathias Nilsson
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I didn't mean that you should put the code snippet in your class file. Rather in your html document that holds the applet attribut.
// Mathias
 
Donny Frank-Rice
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, I am new to this still.
So at which point would I place those lines, if this is my html file:
 
Mathias Nilsson
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!
If I understand you right you have a window that contains a applet. From that window would you like to open another window and close the parent window.
If you shall open a new window without toolbar etc from the applet then i don't know, but if you click a link in the document containg the applet then you can do it with javascript. When the new window opens you can close the parent window.
// First html page with the applet

When you have pressed the link and the other window opens
 
Mathias Nilsson
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It seems to me that you can use the
netscape.javascript.*; package. It enables opening a new window from
an Applet without the toolbar. Search google for this.
here is a good page on the matter
// Mathias
[ April 14, 2004: Message edited by: Mathias Nilsson ]
 
Mathias Nilsson
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok! I've managed to open a new window from java without a toolbar.
First! Add netscape.javascript to your classpath. If you are using jdk1.4
then you can reference jdk1.4\jre\lib\jaws.jar. It contains the netscape package.
when this is done you create your html file. Dont forget to add the element
MAYSCRIPT to your applet description.
Se example. ( HTML file that contains the applet )

And here is our Test class.

Try it out. Pretty cool
 
Donny Frank-Rice
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a bunch. I don't have time to try it out right now (and probably won't until tomorrow), but I will give it a try as soon as I can and let you know if it works out. Again, thank you for taking the time. I am still something of a newbie here.
 
reply
    Bookmark Topic Watch Topic
  • New Topic