3 Replies Latest reply: Jun 25, 2007 2:25 PM by 807605 RSS

    Exporting to a text file in an applet..

    807605
      Hey all,

      I've been working on an applet for simulating different nodal configurations on a 2D map. What I need to be able to do is export, on the click of a button, all of the nodal coordinates (x,y) to a text file. However, using the standard FileWrite hasn't been working for me. The code compiles and the applet runs fine, but I haven't been able to create the text file on the click of a button. Any ideas?

      Here's what I've got so far. Basically, on the button push, it's supposed goes through an array of ellipses (what I use for nodes) and gets the x and y coords for each and output them to a text file. The applet doesn't freeze or anything when I push the button either, it just does nothing.
      void stop_actionPerformed(ActionEvent e){
                  try
                      {
                          String fileName = "NodeCoords.txt";
                          FileWriter fileWriter = new FileWriter( fileName );
                          BufferedWriter bufferedWriter = new BufferedWriter( fileWriter );
                          String tmpCoordinates;
                          int ID;
      
                          //for looop through x-y coordinates
                          for (int i = 0; i < node.length; i++){
                              ID = i+1;
                              tmpCoordinates = "Node: " + String.valueOf(nodeID[ID]) + "  X: " + String.valueOf(node.getX()) + " Y: " + String.valueOf(node[i].getY()) + "\n";
      bufferedWriter.write(tmpCoordinates);
      }

      bufferedWriter.close();
      }
      catch( IOException p )
      {
      p.printStackTrace();
      }
      }