I have 2 separate java files (Main & RSS). I would like to return the result from my RSS class to my Main class. Right now the results are displayed in console. How can I append the results to my JTextArea instead? Thanks!
In my Main class:
public void news()
{
news = new JPanel();
news.setLayout( null );
JTextArea textArea = new JTextArea();
textArea.setBackground(SystemColor.window);
textArea.setBounds(10, 11, 859, 512);
textArea.setWrapStyleWord(true);
news.add(textArea);
TextSamplerDemo reader = TextSamplerDemo.getInstance();
reader.writeNews();
}
In my RSS class:
public void writeNews(){
try{
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
URL u = new URL("http://rss.cnn.com/rss/cnn_world.rss");
Document doc = builder.parse(u.openStream());
NodeList nodes = doc.getElementsByTagName("item");
for(int i=0;i<nodes.getLength();i++){
Element element = (Element)nodes.item(i);
System.out.println("Title: " + getElementValue(element,"title"));
System.out.println("Link: " + getElementValue(element,"link"));
}
}
catch(Exception ex){
ex.printStackTrace();
}
}
If you modify your RSS.writeNews method to return the parsed RSS feed, the Main class can easily insert the data into the text area.