The problem is simply that you do not have a URL in your call to
desktop.browse(oURL);
.
You try to capture the contents of
turl
at the time that you are creating the frame window, but there is no text there at that point. You should change your code to call String
url=turl.getText();
inside the button handler, thus:
b1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
try {
String url = turl.getText();
Desktop desktop = java.awt.Desktop.getDesktop();
URI oURL = new URI(url);
desktop.browse(oURL);
} catch (Exception e) {
e.printStackTrace();
}
}
});