By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,213 Members | 1,086 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,213 IT Pros & Developers. It's quick & easy.

Opening web help page from menu

P: 14
Hi

Need a bit of help here please to point me in the right direction.

I have a java class file here which i wish from a menu item to open a web page which contains a help page.


Expand|Select|Wrap|Line Numbers
  1. ]
  2. } else if (arg.equals(" Help Page")) {
  3.     } else if (arg.equals("BrowserControl")) {
  4.     parent.doconnect();
  5.  


Below is the java file that calls the web page this works fine for some reason I canít call it from the previous java class file

Many thanks for any help

Keith

Expand|Select|Wrap|Line Numbers
  1. import java.io.IOException;
  2. /**
  3.  * A simple, static class to display a URL in the system browser. *
  4.  * Under Unix, the system browser is hard-coded to be 'netscape'.
  5.  * Netscape must be in your PATH for this to work.  This has been
  6.  * tested with the following platforms: AIX, HP-UX and Solaris. *
  7.  * Under Windows, this will bring up the default browser under windows,
  8.  * usually either Netscape or Microsoft IE.  The default browser is
  9.  * determined by the OS.  This has been tested under Windows 95/98/NT. *
  10.  * Examples:
  11.  * Note - you must include the url type -- either "http://" or
  12.  * "file://".
  13.  */
  14. public class BrowserControl
  15. {
  16.     /**
  17.      * Display a file in the system browser.  If you want to display a
  18.      * file, you must include the absolute path name.
  19.      *
  20.      * @param url the file's url (the url must start with either "http://"
  21. or
  22.      * "file://").
  23.      */
  24.     public static void displayURL(String url)
  25.     {
  26.         boolean windows = isWindowsPlatform();
  27.         String cmd = null;
  28.         try
  29.         {
  30.             if (windows)
  31.             {
  32.                 // cmd = 'rundll32 url.dll,FileProtocolHandler http://...'
  33.                 cmd = WIN_PATH + " " + WIN_FLAG + " " + url;
  34.                 Process p = Runtime.getRuntime().exec(cmd);
  35.             }
  36.             else
  37.             {
  38.                 // Under Unix, Netscape has to be running for the "-remote"
  39.                 // command to work.  So, we try sending the command and
  40.                 // check for an exit value.  If the exit command is 0,
  41.                 // it worked, otherwise we need to start the browser.
  42.                 // cmd = 'netscape -remote openURL(http://www.javaworld.com)'
  43.                 cmd = UNIX_PATH + " " + UNIX_FLAG + "(" + url + ")";
  44.                 Process p = Runtime.getRuntime().exec(cmd);
  45.                 try
  46.                 {
  47.                     // wait for exit code -- if it's 0, command worked,
  48.                     // otherwise we need to start the browser up.
  49.                     int exitCode = p.waitFor();
  50.                     if (exitCode != 0)
  51.                     {
  52.                         // Command failed, start up the browser
  53.                         // cmd = 'netscape http://www.javaworld.com'
  54.                         cmd = UNIX_PATH + " "  + url;
  55.                         p = Runtime.getRuntime().exec(cmd);
  56.                     }
  57.                 }
  58.                 catch(InterruptedException x)
  59.                 {
  60.                     System.err.println("Error bringing up browser, cmd='" +
  61.                                        cmd + "'");
  62.                     System.err.println("Caught: " + x);
  63.                 }
  64.             }
  65.         }
  66.         catch(IOException x)
  67.         {
  68.             // couldn't exec browser
  69.             System.err.println("Could not invoke browser, command=" + cmd);
  70.             System.err.println("Caught: " + x);
  71.         }
  72.     }
  73.     /**
  74.      * Try to determine whether this application is running under Windows
  75.      * or some other platform by examing the "os.name" property.
  76.      *
  77.      * @return true if this application is running under a Windows OS
  78.      */
  79.     public static boolean isWindowsPlatform()
  80.     {
  81.         String os = System.getProperty("os.name");
  82.         if ( os != null && os.startsWith(WIN_ID))
  83.             return true;
  84.         else
  85.             return false;
  86.     }
  87.     /**
  88.      * Simple example.
  89.      */
  90.     public static void main(String[] args)
  91.     {
  92.         displayURL("http://www.javaworld.com");
  93.     }
  94.     // Used to identify the windows platform.
  95.     private static final String WIN_ID = "Windows";
  96.     // The default system browser under windows.
  97.     private static final String WIN_PATH = "rundll32";
  98.     // The flag to display a url.
  99.     private static final String WIN_FLAG = "url.dll,FileProtocolHandler";
  100.     // The default browser under unix.
  101.     private static final String UNIX_PATH = "netscape";
  102.     // The flag to display a url.
  103.     private static final String UNIX_FLAG = "-remote openURL";
  104. }
May 26 '07 #1
Share this Question
Share on Google+
4 Replies


pbmods
Expert 5K+
P: 5,821
We'd love to help you, but you've posted this in the JavaScript forum.

I've notified a JavaScript moderator so we can get your post moved to a forum where it will receive more relevant exposure.
May 27 '07 #2

P: 14
Hi

Many thanks sorry I have posted to the wrong forum

Keith
May 27 '07 #3

acoder
Expert Mod 15k+
P: 16,027
Moved to the Java forum.
May 27 '07 #4

Expert 10K+
P: 11,448
Maybe I totally misunderstood your question but have you ever read about Sun's
Java Help System? Here's the link.

kind regards,

Jos
May 28 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.