XML : Java applet: can't display xml values on labels or other gui element

I'm building a very small Java Applet example. Normally, I program in C# instead of Java. Don't blame me for not using a layoutmanager, I know things could be more efficient. My problem is that I can't display the received XML values which are saved in the ArrayList called "weerAttribuutValueLabelList" on a label or textfield. When I inspect the ArrayList all the values received from the XML file are present.

It must be a small stupid thing which differs from C# or something like that I think. I hope someone can help me out, I already tried a lot to find the cause, but now I'm running out of ideas. Thank you very much.

The codeblock:

  import java.awt.*;   import java.applet.*;   import java.awt.event.*;   import javax.xml.parsers.DocumentBuilderFactory;  import javax.xml.parsers.DocumentBuilder;  import org.w3c.dom.Document;  import org.w3c.dom.NodeList;  import org.w3c.dom.Node;  import org.w3c.dom.Element;  import java.net.*;  import java.io.*;  import java.util.ArrayList;    public class ReadXml extends Applet implements ActionListener   {      NodeList xmlValueList;      ArrayList<Label> weerAttribuutLabelList;      ArrayList<Label> weerAttribuutValueLabelList;        int weerAttribuutLabelMargin = 20;      int weerAttribuutValueLabelMargin = 20;    public ReadXml()  {      // Location for every generated label      weerAttribuutLabelList = new ArrayList <Label>();      weerAttribuutValueLabelList = new ArrayList <Label>();        // Generate the static labels with defined text label at first      staticLabel();        // Download the xml, put the xml values in a label and save them in the ArrayList      readXmlFile();        labelAligning();      }    // Every static label gets a defined text label from the array  public void staticLabel()  {      String[] regentHetInXmlNames = {"Datum:", "Tijd:", "Temperatuur (°C):", "Trend (/uur):", "Max. temperatuur:", "Min. temperatuur:", "Gevoelstemperatuur:", "Min. gevoelstemp.:", "Dauwpunt:", "Trend (/uur):", "Max. dauwpunt:", "Min. dauwpunt:", "Luchtvochtigheid:", "Trend (/uur):", "Max. luchtvochtigheid:", "Min. luchtvochtigheid:", "Neerslag:", "Luchtdruk:", "Trend (/uur):", "Max. luchtdruk:", "Min. luchtdruk", "Windsnelheid:", "Windsnelheid (10 min):", "Max. windstoot:", "Windrichting:", "UV:", "Max. UV:"};        for(String name : regentHetInXmlNames)      {          weerAttribuutLabelList.add(new Label(name));      }  }    // Read xml  public void readXmlFile()  {      try       {          DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();          DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();          Document regenthetinXml = dBuilder.parse(new URL("http://regenthet.in/data/regenthetin.xml").openStream());            regenthetinXml.getDocumentElement().normalize();            String[] regentHetInXmlNodes = {"stationDate", "stationTime", "outsideTemp", "tempChangeLastHour", "hiOutsideTemp", "lowOutsideTemp", "windchill", "lowWindchill", "outsideDewPt", "dewChangeLastHour", "hiDewpoint", "lowDewpoint", "outsideHumidity", "humChangeLastHour", "hiHumidity", "lowHumidity", "dailyRain", "pressure", "pressChangeLastHour", "hiPressure", "lowPressure", "windSpeed", "wind10Avg", "hiWindSpeed", "windDirection", "uv", "hiUV"};            xmlValueList = regenthetinXml.getElementsByTagName("station_almelo");          Node nNode = xmlValueList.item(0);            Element eElement = (Element) nNode;          for(int i = 0; i <= 26; i++)          {              weerAttribuutValueLabelList.add(new Label(eElement.getElementsByTagName(regentHetInXmlNodes[i]).item(0).getTextContent()));              //System.out.println(eElement.getElementsByTagName(regentHetInXmlNodes[i]).item(0).getTextContent());          }               }        catch(Exception e)      {}  }    public void labelAligning()  {      // Visual default aspects      setLayout(null);      setBackground(Color.lightGray);        for(Label item : weerAttribuutLabelList)      {          item.setBounds(20,weerAttribuutLabelMargin,150,20);          add(item);          weerAttribuutLabelMargin = weerAttribuutLabelMargin + 20;          //System.out.println(item);      }        for(Label item : weerAttribuutValueLabelList)      {          item.setBounds(250,weerAttribuutValueLabelMargin,150,20);          add(item);          weerAttribuutValueLabelMargin = weerAttribuutValueLabelMargin + 20;          System.out.println(item);      }  }    public void actionPerformed(ActionEvent event)  {            }  }    

Image, for clarifying

No comments:

Post a Comment