public class Browser extends JPanel {
Browser(int day) {
setLayout(new BorderLayout(5, 5));
final JEditorPane jt = new JEditorPane();
// make read-only
jt.setEditable(false);
// follow links
jt.addHyperlinkListener(new HyperlinkListener() {
public void hyperlinkUpdate(final HyperlinkEvent e) {
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
// Save original
Document doc = jt.getDocument();
try {
URL url = e.getURL();
jt.setPage(url);
} catch (IOException io) {
JOptionPane.showMessageDialog(Browser.this,
"Can't follow link", "Invalid Input",
JOptionPane.ERROR_MESSAGE);
jt.setDocument(doc);
}
}
});
}
}
});
JScrollPane pane = new JScrollPane();
pane.setBorder(BorderFactory.createLoweredBevelBor der());
pane.getViewport().add(jt);
add(pane, BorderLayout.CENTER);
try {
jt.setPage("http://www.gazzetta.it/Calcio/prob_form/" + day
+ "_giornata.shtml");
} catch (IOException ex) {
JOptionPane.showMessageDialog(Browser.this, "Invalid URL",
"Invalid Input", JOptionPane.ERROR_MESSAGE);
}
}
}