2つの別々のJavaファイル(メインとRSS)があります。RSSクラスの結果をMainクラスに返したいのですが。現在、結果はコンソールに表示されています。代わりに結果をJTextAreaに追加するにはどうすればよいですか?ありがとう!
私のメインクラスでは:
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();
}
私のRSSクラスでは:
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();
}
}