1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
public class MyThread extends Thread {
public void run(){
try {
SyndFeedInput sfi1 = new SyndFeedInput();
String lien1 = "http://www.planet-libre.org/feed.php?type=rss";
URL rss1 = new URL(lien1);
jEditorPane2.setContentType("text/html");
jEditorPane2.setEditable(false);
StringBuffer buf1 = new StringBuffer();
SyndFeed feed1 = sfi1.build(new XmlReader(rss1) {});
List entries1 = new ArrayList();
entries1 = feed1.getEntries();
for (int i = 0; i < entries1.size(); i++) {
SyndEntry entry1 = (SyndEntry) entries1.get(i);
buf1.append("<br>Article : " + entry1.getTitle() + "<br>");
buf1.append("Date de publication : " + entry1.getPublishedDate() + "<br>");
buf1.append("<a href=" + entry1.getLink() + ">" + "Lire l'article sur le site" + "</a>" + "<br>");
}
jEditorPane2.addHyperlinkListener(new HyperlinkListener() {
@Override
public void hyperlinkUpdate(HyperlinkEvent e) {
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
try {
Desktop desktop1 = Desktop.getDesktop();
if (desktop1.isSupported(Desktop.Action.BROWSE)) {
URI sss = new URI(e.getURL().toString());
desktop1.browse(sss);
}
} catch (Exception ex) {
JOptionPane.showMessageDialog(null, ex.toString(), "Problème" , JOptionPane.ERROR_MESSAGE);
}
}
}
});
jEditorPane2.setText("<html><body>" + buf1.toString() + "</body></html>");
jEditorPane2.setCaretPosition(0);
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e.toString(), "Problème", JOptionPane.ERROR_MESSAGE);
}
}
} |
Partager