DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Java (http://www.daniweb.com/forums/forum9.html)
-   -   Java open internet browser (http://www.daniweb.com/forums/thread39405.html)

peter_budo Feb 10th, 2006 4:54 am
Java open internet browser
 
Can somebody please provide my with usefull info how to open internet browser from java program? The way how this should work, work cross platform & open default browser don't force certain browser

I tried to use info from this page but couldn't get it work. Together with tutor we downloaded requered libraries. But when implemented compiler give us following errors, red parts mark erorr place

C:\CW1 - Game\Game.java:174: 
unreported exception java.net.MalformedURLException;
must be caught or declared to be thrown
Desktop.browse(new URL  ( "http://www.google.co.uk/"));
                                     
C:\CW1 - Game\Game.java:174:
unreported exception org.jdesktop.jdic.desktop.DesktopException;
must be caught or declared to be thrown
Desktop.browse(new URL( "http://www.google.co.uk/"));

server_crash Feb 10th, 2006 7:32 am
Re: Java open internet browser
 
Are you putting that in a try-catch clause? If so, what does it look like?

peter_budo Feb 10th, 2006 8:58 am
Re: Java open internet browser
 
No I don't, just simple check for action event which is build on if statement

else if(evt.getSource() == menuItemRules)
        {
                Desktop.browse(new URL( "http://www.google.co.uk/"));
        }

server_crash Feb 10th, 2006 4:46 pm
Re: Java open internet browser
 
Anytime you mess with a URL you'll need to catch a malformedURLException and for the desktop thing,

else if(evt.getSource() == menuItemRules)
        {
            try
            {
                Desktop.browse(new URL( "http://www.google.co.uk/"));
            }
            catch(MalformedURLException mue)
            {
              //error message
            }
            catch(DesktopException de)
            {
              //error message
            }
        }

peter_budo Feb 10th, 2006 6:51 pm
Re: Java open internet browser
 
Can you translate this :cheesy:
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/jdesk
top/jdic/desktop/internal/impl/ServiceManagerStub
        at org.jdesktop.jdic.desktop.internal.ServiceManager.getService(Unknown
Source)
        at org.jdesktop.jdic.desktop.Desktop.browse(Unknown Source)
        at MainWindow.actionPerformed(Game.java:176)
        at java.awt.MenuItem.processActionEvent(MenuItem.java:597)
        at java.awt.MenuItem.processEvent(MenuItem.java:556)
        at java.awt.MenuComponent.dispatchEventImpl(MenuComponent.java:298)
        at java.awt.MenuComponent.dispatchEvent(MenuComponent.java:286)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:466)
        at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh
read.java:242)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.java:163)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)

        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)

        at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
Press any key to continue...


All times are GMT -4. The time now is 7:19 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC