954,523 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

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(<strong>n</strong>ew 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<strong>(</strong>new URL( "http://www.google.co.uk/"));
peter_budo
Code tags enforcer
Moderator
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
 

Are you putting that in a try-catch clause? If so, what does it look like?

server_crash
Postaholic
2,111 posts since Jun 2004
Reputation Points: 113
Solved Threads: 20
 

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/"));
	}
peter_budo
Code tags enforcer
Moderator
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
 

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
            }
	}
server_crash
Postaholic
2,111 posts since Jun 2004
Reputation Points: 113
Solved Threads: 20
 

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...
peter_budo
Code tags enforcer
Moderator
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You