Article View: borland.public.jbuilder.java.language
Article #20030Re: HTML browser display from Java application / applet...
From: Kurt A. Zarefoss
Date: Tue, 04 Nov 1997 00:00
Date: Tue, 04 Nov 1997 00:00
90 lines
3141 bytes
3141 bytes
If you want the browser to open a specific URL from an Applet, use the
showDocument() method of the AppletContext. The output can go to a new
window, the current window, or a specific frame within the current window.
If it is an application, then (if you don't mind trying yourself to
Windows), write a C/C++ function that contains a main and accepts one
argument (the URL to open). The Java Application would exec this executable
passing in the URL as a "command line argument". The C/C++ app would then
perform a ShellExecute wich will automatically launch the user's default
browser (whatever it is).
Here are some Applet and C/C++ samples:
// Applet showDocument()
// Construct the URL that should be opened. (all of these
steps are not necessary, I just tweaked code I had already written)
String stringURL = new String("http://www.borland.com");
URL commandURL = new URL(stringURL);
// Open the URL.
AppletContext currentContext = applet.getAppletContext();
currentContext.showDocument(commandURL, "_ "); // this open
it in a new window.
// C/C++ code for launching default browser
#include <windows.h>
#include <stdio.h>
#include <string.h>
void main (int argc, char **argv) {
if ((argc != 2) || (*argv[1] == 0)) {
printf ("No file passed into function.");
exit (1);
}
if ((long)ShellExecute(NULL, "open", argv[1], NULL, "", SW_NORMAL) <= 32) {
printf("Error: Unable to start program.");
exit (1);
}
exit(0);
}
You would call this executable like this:
// Execute the command.
Runtime.getRuntime().exec(command); // where command is the
filename.exe URL_to_open
Good luck,
Kurt
David C. Jacobson wrote:
> Hi,
>
> Does anyone have an example of some Java code that causes the Web
> browser goto a given URL (display a specified HTML page)? I've read
> some thread about the JavaSoft HTML bean for displaying HTML within the
> Java applet and/or application, but I'm not interested in something
> quite that advanced.
>
> I just want a JBCL button control in my Java application to cause the
> Web browser to follow a specified URL, or, if it's an applet, to go to
> the URL wiping out the page with the embedded applet, to which I can
> return to by using the browser's "back" button. One step further, is it
> possible to export data out of the Java applet / application into the
> HTML page?
>
> Thanks in advance for any guidance,
>
> David C. Jacobson
> Catapult Systems Corp.
> mailto:dcj@launch.com
--
Kurt A. Zarefoss
hawk@fred.net
Technical Details
Message-ID:
<345F72AA.285F790F@my.signature>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<345EDA6D.23D9C3CB@launch.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,b58e080f3ad2bdce X-Google-Attributes: gidf74b3,public From: "Kurt A. Zarefoss" <see@my.signature> Subject: Re: HTML browser display from Java application / applet... Date: 1997/11/04 Message-ID: <345F72AA.285F790F@my.signature> X-Deja-AN: 287030546 References: <345EDA6D.23D9C3CB@launch.com> Organization: None Newsgroups: borland.public.jbuilder.java.language