Reputation: 141
I am creating a simple desktop application in java which shows the currently running services. I want to add a Google search bar at the top, which can directly open the Google Search Result (web page) in the default browser for the entered keyword in the application.
Upvotes: 2
Views: 401
Reputation: 40492
You should get query_string
value from input box then use the following:
try {
java.awt.Desktop desktop = java.awt.Desktop.getDesktop();
java.net.URI uri = new java.net.URI( "http", "google.com",
"/search?q=" + query_string );
desktop.browse( uri );
} catch ( Exception e ) {
System.err.println( e.getMessage() );
}
Upvotes: 4