• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Console to GUI/JFrame

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi! i have a code that shows information about the wheater based on a xml-file. The information prints in the NetBeans console, but i need it to print in a JFrame.
Can somebody please help me?

(Sorry about my english)

Here is the code:

package Xpath;

import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathFactory;
import javax.swing.*;
import javax.xml.xpath.XPathExpressionException;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;

public class AalesundXpath extends JFrame{

public static void main(String[] displayGUI) throws Exception {



XPath xpath = XPathFactory.newInstance().newXPath();
String topicExpression = "/weatherdata/forecast/tabular/time/temperature/@value";
String topicExpression4 = "/weatherdata/location/name";
String topicExpression3 = "weatherdata/observations/weatherstation/windDirection/@name";
String topicExpression1 ="/weatherdata/forecast/tabular/time/@from";
String topicExpression2 ="/weatherdata/forecast/tabular/time/@to";
String topicExpression6 ="/weatherdata/forecast/tabular/time/symbol/@name";
String topicExpression5 ="/weatherdata/observations/weatherstation/windSpeed/@mps";
InputSource inputSource = new InputSource("http://www.yr.no/sted/Norge/M%C3%B8re_og_Romsdal/%C3%85lesund/%C3%85lesund/varsel.xml");


NodeList nodes = (NodeList) xpath.evaluate
(topicExpression, inputSource, XPathConstants.NODESET);
NodeList nodes1 = (NodeList) xpath.evaluate
(topicExpression1, inputSource, XPathConstants.NODESET);
NodeList nodes2 = (NodeList) xpath.evaluate
(topicExpression2, inputSource, XPathConstants.NODESET);
NodeList nodes3 = (NodeList) xpath.evaluate
(topicExpression3, inputSource, XPathConstants.NODESET);
NodeList nodes4 = (NodeList) xpath.evaluate
(topicExpression4, inputSource, XPathConstants.NODESET);
NodeList nodes5 = (NodeList) xpath.evaluate
(topicExpression5, inputSource, XPathConstants.NODESET);
NodeList nodes6 = (NodeList) xpath.evaluate
(topicExpression6, inputSource, XPathConstants.NODESET);

// output the text content of this node and its descendants.
// (includes empty LF because of empty comment (#text))

System.out.println("******************************");
System.out.println("Dagens temperatur gjelder for: "+nodes4.item(0).getTextContent());
System.out.println("******************************");
System.out.println("Dagens temperatur gjelder fra: "+nodes1.item(0).getTextContent());
System.out.println("******************************");
System.out.println("Dagens temperatur gjelder til: "+nodes2.item(0).getTextContent());
System.out.println("******************************");
System.out.println("Dagens temperatur er : "+nodes.item(0).getTextContent()+" grader celsius");
System.out.println("******************************");
System.out.println("Dagens v�rtype er : "+nodes6.item(0).getTextContent());
System.out.println("******************************");
System.out.println("Dagens vindstyrke er : " +nodes5.item(0).getTextContent()+" ms");
System.out.println("******************************");
System.out.println("Dagens vind kommer ifra : "+nodes3.item(0).getTextContent());
System.out.println("******************************");

// display only the "url" nodes for PowerBuidler
NodeList urls = nodes.item(0).getChildNodes();
NodeList urls1 = nodes1.item(0).getChildNodes();
NodeList urls2 = nodes2.item(0).getChildNodes();
NodeList urls3 = nodes3.item(0).getChildNodes();
NodeList urls4 = nodes4.item(0).getChildNodes();
NodeList urls5 = nodes5.item(0).getChildNodes();
NodeList urls6 = nodes6.item(0).getChildNodes();
int j = urls.getLength();

for (int i = 0; i < j ; i++) {
if (urls.item(i).getNodeName().equals("url")) {
System.out.println("url :" + urls.item(i).getTextContent());
}
int k = urls1.getLength();
for (int m = 0; m < k ; m++) {
if (urls1.item(m).getNodeName().equals("url1")) {
System.out.println("url1 :" + urls1.item(m).getTextContent());
}
int b = urls2.getLength();
for (int n = 0; n < b ; n++) {
if (urls2.item(n).getNodeName().equals("url2")) {
System.out.println("url2 :" + urls2.item(b).getTextContent());
}
int c = urls3.getLength();
for (int v = 0; v < c ; v++) {
if (urls3.item(v).getNodeName().equals("url3")) {
System.out.println("url3 :" + urls3.item(v).getTextContent());
}
int d = urls4.getLength();
for (int x = 0; x < d; x++) {
if (urls4.item(x).getNodeName().equals("url4")) {
System.out.println("url4 :" + urls4.item(d).getTextContent());
}
int q = urls5.getLength();
for (int w = 0; w < q; w++) {
if (urls5.item(w).getNodeName().equals("url5")) {
System.out.println("url5 :" + urls5.item(q).getTextContent());
}
int o = urls6.getLength();
for (int p = 0; p < o; p++) {
if (urls6.item(p).getNodeName().equals("url6")) {
System.out.println("url6 :" + urls6.item(o).getTextContent());
}

} }
} }
}// O
}// /|\
}// |
}// / \
}
//_______\\




 
An elephant? An actual elephant. Into the apartment. How is the floor still here. Hold this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic