How to open website using Java URL and URL connection class
I am trying to create a GUI-based program in Java that has a 'Submit'
button and when clicked, it takes you to a website.
I have read about the URL and URLConnection classes online and the
connection to the website is established but the program does not open the
link... This is what I have so far:
if(command.equals("Submit data"))
{
try {
URL myURL = new URL("http://google.com/");
URLConnection myURLConnection = myURL.openConnection();
myURLConnection.connect();
}
catch (MalformedURLException q)
{
// new URL() failed
// ...
}
catch (IOException t) {
// openConnection() failed
// ...
}
}
The connection seems to be established but I want the program to open up
the browser and take to the website.. I've tried everything and no luck..
Thank you
No comments:
Post a Comment