Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.gui > #2419 > unrolled thread
| Started by | "Pseudo Silk Kimono" <pseudo.silk.kimono@THRWHITE.remove-dii-this> |
|---|---|
| First post | 2011-04-27 15:38 +0000 |
| Last post | 2011-04-27 15:39 +0000 |
| Articles | 6 — 5 participants |
Back to article view | Back to comp.lang.java.gui
[Swing] Is it possible to "Pseudo Silk Kimono" <pseudo.silk.kimono@THRWHITE.remove-dii-this> - 2011-04-27 15:38 +0000
Re: [Swing] Is it possibl "Real Gagnon" <real.gagnon@THRWHITE.remove-dii-this> - 2011-04-27 15:39 +0000
Re: [Swing] Is it possibl "Pseudo Silk Kimono" <pseudo.silk.kimono@THRWHITE.remove-dii-this> - 2011-04-27 15:39 +0000
Re: Is it possible to inv "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this> - 2011-04-27 15:39 +0000
Re: [Swing] Is it possibl "Roedy Green" <roedy.green@THRWHITE.remove-dii-this> - 2011-04-27 15:39 +0000
Re: [Swing] Is it possibl "Frank Meyer" <frank.meyer@THRWHITE.remove-dii-this> - 2011-04-27 15:39 +0000
| From | "Pseudo Silk Kimono" <pseudo.silk.kimono@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:38 +0000 |
| Subject | [Swing] Is it possible to |
| Message-ID | <fc700o$f71$1@registered.motzarella.org> |
To: comp.lang.java.gui
I am in the process of designing a very simple menu system which will
have a series of button, a sort of hierarchical system if you will.
What I would like to do is have each button open a webpage in the user's
default browser. Is this possible and if so, are there any examples
that someone would be willing to share? I have googled, but either I am
not searching for the right thing, or there are NO websites which meet
my criteria.
--
What were you? A jock or a brain?" http://blinkynet.net/comp/uip5.html
"I was a ghost." PSK - RLU 452647
Warrick Brown and Gil Grissom (Bully for You)
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [next] | [standalone]
| From | "Real Gagnon" <real.gagnon@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:39 +0000 |
| Subject | Re: [Swing] Is it possibl |
| Message-ID | <Xns99A8B60B12D3Erealhowtowwwrgagnonc@140.99.99.130> |
| In reply to | #2419 |
To: comp.lang.java.gui
Pseudo Silk Kimono <Pseudo_Silk_Kimono@marillion.com> wrote in
news:fc700o$f71$1@registered.motzarella.org:
> I am in the process of designing a very simple menu system which will
> have a series of button, a sort of hierarchical system if you will.
> What I would like to do is have each button open a webpage in the
> user's default browser. Is this possible and if so, are there any
> examples that someone would be willing to share? I have googled, but
> either I am not searching for the right thing, or there are NO
> websites which meet my criteria.
>
If using 1.6, java.awt.Desktop is the way to go.
try {
Desktop.browse(new URL("http://www.rgagnon.com");
}
catch (MalformedURLException e1) {
e1.printStackTrace();
}
catch (DesktopException e2) {
e2.printStackTrace();
}
For pre 1.6, you need to use Runtime.exec() and the file association
mechanism of the OS.
Bye.
--
Real Gagnon from Quebec, Canada
* Java, Javascript, VBScript and PowerBuilder code snippets
* http://www.rgagnon.com/howto.html
* http://www.rgagnon.com/bigindex.html
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "Pseudo Silk Kimono" <pseudo.silk.kimono@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:39 +0000 |
| Subject | Re: [Swing] Is it possibl |
| Message-ID | <Xns99A8D3916B329misplacedChildhood88@85.214.62.108> |
| In reply to | #2420 |
To: comp.lang.java.gui
On Tue, 11 Sep 2007 21:51:18 GMT, Real Gagnon expounded upon us in
comp.lang.java.gui :
> http://www.rgagnon.com
Thanks for the help. Since I don't know what JDK will be used by
the people invoking my screen, I had to go with the Runtime.exec()
option
private void jButton30ActionPerformed(java.awt.event.ActionEvent
evt) {
// TODO add your handling code here:
String url = "http://www.rgagnon.com";
try {
Runtime.getRuntime().exec("cmd /C start
http://www.rgagnon.com");
} catch (IOException ex) {
ex.printStackTrace();
}
}
Is there a way to draw horizontal and vertical lines on a screen
like this
Main
------|------
| | |
F1 F2 F3
where Main, F1, F2 and F3 are JButtons?
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:39 +0000 |
| Subject | Re: Is it possible to inv |
| Message-ID | <1189555909.200071.218990@z24g2000prh.googlegroups.com> |
| In reply to | #2421 |
To: comp.lang.java.gui On Sep 12, 9:47 am, Pseudo Silk Kimono <misplacedchildho...@marillion.com> wrote: ... > ...Since I don't know what JDK will be used by > the people invoking my screen, I had to go with the Runtime.exec() > option Note that approach is explored in some detail in the code of BrowserLauncher2. Also, JWS apps. have access to the BasicService.showDocument() method, and applets might use the (utterly unreliable) AppletContext.showDocument(). Both of those are avialable since 'inception' (1.1 for the applet, 1.2 for JWS) Andrew T. --- * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet! --- Synchronet 3.15a-Win32 NewsLink 1.92 Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "Roedy Green" <roedy.green@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:39 +0000 |
| Subject | Re: [Swing] Is it possibl |
| Message-ID | <hr1fe3ppqku2iqed8mtbn932h30lsmnqc3@4ax.com> |
| In reply to | #2419 |
To: comp.lang.java.gui On Tue, 11 Sep 2007 21:06:32 +0000 (UTC), Pseudo Silk Kimono <Pseudo_Silk_Kimono@marillion.com> wrote, quoted or indirectly quoted someone who said : >I am in the process of designing a very simple menu system which will >have a series of button, a sort of hierarchical system if you will. >What I would like to do is have each button open a webpage in the user's >default browser. Is this possible and if so, are there any examples >that someone would be willing to share? I have googled, but either I am >not searching for the right thing, or there are NO websites which meet >my criteria. see http://mindprod.com/jgloss/htmlrendering.html -- Roedy Green Canadian Mind Products The Java Glossary http://mindprod.com --- * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet! --- Synchronet 3.15a-Win32 NewsLink 1.92 Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "Frank Meyer" <frank.meyer@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:39 +0000 |
| Subject | Re: [Swing] Is it possibl |
| Message-ID | <46e9810f$0$7691$9b4e6d93@newsspool2.arcor-online.net> |
| In reply to | #2419 |
To: comp.lang.java.gui
See below - works with older Java versions.
public class BrowserControl {
// Used to identify the windows platform.
private static final String WIN_ID = "Windows";
// Used to identify the mac platform.
private static final String MAC_ID = "Mac";
// The default system browser under windows.
private static final String WIN_PATH = "rundll32";
// The flag to display a url.
private static final String WIN_FLAG = "url.dll,FileProtocolHandler";
// The default system browser under mac.
private static final String MAC_PATH = "open";
// The default browser under unix.
private static final String UNIX_PATH = "netscape";
// The flag to display a url.
private static final String UNIX_FLAG = "-remote openURL";
/**
* Display a file in the system browser. If you want to display a
* file, you must include the absolute path name.
*
* @param url the file's url (the url must start with either "http://"
* or
* "file://").
*/
public static void displayURL(String url) {
boolean windows = isWindowsPlatform();
boolean mac = isMacPlatform();
String cmd = null;
try {
if (windows) {
// cmd = 'rundll32 url.dll,FileProtocolHandler http://...'
cmd = WIN_PATH + ' ' + WIN_FLAG + ' ' + url;
Runtime.getRuntime().exec(cmd);
} else if (mac) {
cmd = MAC_PATH + ' ' + url;
Runtime.getRuntime().exec(cmd);
} else {
// Under Unix, Netscape has to be running for the "-remote"
// command to work. So, we try sending the command and
// check for an exit value. If the exit command is 0,
// it worked, otherwise we need to start the browser.
// cmd = 'netscape -remote openURL(http://www.javaworld.com)'
cmd = UNIX_PATH + ' ' + UNIX_FLAG + '(' + url + ')';
Process p = Runtime.getRuntime().exec(cmd);
try {
// wait for exit code -- if it's 0, command worked,
// otherwise we need to start the browser up.
int exitCode = p.waitFor();
if (exitCode != 0) {
// Command failed, start up the browser
// cmd = 'netscape http://www.javaworld.com'
cmd = UNIX_PATH + ' ' + url;
Runtime.getRuntime().exec(cmd);
}
} catch (InterruptedException x) {
System.err.println("Error bringing up browser, cmd='" + cmd
+ '\'');
System.err.println("Caught: " + x);
}
}
} catch (IOException x) {
// couldn't exec browser
System.err.println("Could not invoke browser, command=" + cmd);
System.err.println("Caught: " + x);
}
}
private static boolean isMacPlatform() {
String os = System.getProperty("os.name");
return os != null && os.startsWith(MAC_ID);
}
/**
* Try to determine whether this application is running under Windows
* or some other platform by examing the "os.name" property.
*
* @return true if this application is running under a Windows OS
*/
public static boolean isWindowsPlatform() {
String os = System.getProperty("os.name");
return os != null && os.startsWith(WIN_ID);
}
/**
* Simple example.
*/
public static void main(String[] args) {
displayURL("http://www.javaworld.com");
}
}
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.gui
csiph-web