Visit url in webbrowser from a link from my application
Hello,
I have a java application. I would like to send my users to a specific URL for example "www.google.com". How do I do that?
I've got this great answere:
import java.lang.reflect.Method;
import javax.swing.JOptionPane;
publicclass test{
public test(){
}
publicstaticvoid main(String[] args){
String osName = System.getProperty("os.name");
String url ="http://www.google.com/";
try{
if (osName.startsWith("Mac OS")){
Class fileMgr = Class.forName("com.apple.eio.FileManager");
Method openURL = fileMgr.getDeclaredMethod("openURL",
new Class[]{String.class});
openURL.invoke(null,new Object[]{url});
}
elseif (osName.startsWith("Windows"))
Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url);
else{//assume Unix or Linux
String[] browsers ={
"gnome-open","firefox","opera","konqueror","epiphany","mozilla","netscape"};
String browser =null;
for (int count = 0; count < browsers.length && browser ==null; count++)
if (Runtime.getRuntime().exec(
new String[]{"which", browsers[count]}).waitFor() == 0)
browser = browsers[count];
if (browser ==null)
thrownew Exception("Could not find web browser");
else
Runtime.getRuntime().exec(new String[]{browser, url});
}
}
catch (Exception e){
JOptionPane.showMessageDialog(null, e.getLocalizedMessage());
}
}
}
The problem
But do you know how I can make it open in the current open webpage after the first time? So its like refreshing the website.
Because now it opens a new tab for every time and I will end up with hundreds of thoose.

