Código:
public class Uf { public static void Ufdeldia(String[] args) { int i=1; int n=1; String uf=null; String palabra; try { // Indicamos la URL donde nos conectamos URL url = new URL("http://valoruf.cl/"); // Buffer con los datos recibidos BufferedReader in = null; try { // Volcamos lo recibido al buffer in = new BufferedReader(new InputStreamReader(url.openStream())); } catch(Throwable t){} // Transformamos el contenido del buffer a texto String inputLine; String inputText=""; // Mientras haya cosas en el buffer las volcamos a las // cadenas de texto while ((inputLine = in.readLine()) != null) { StringTokenizer stk =new StringTokenizer (inputLine); inputText = inputText +"\n"+ inputLine; while (stk.hasMoreTokens()) { palabra = stk.nextToken(); // System.out.print(i+"."); // System.out.print(n); if(i==58 & n==6) { uf=palabra; System.out.println(palabra); } n=n+1; } i=i+1; n=1; } // Mostramos el contenido y cerramos la entrada // System.out.println("El contenido de la URL es: " + inputText); // in.close(); } catch (MalformedURLException me) { System.out.println("URL erronea"); } catch (IOException ioe) { System.out.println("Error IO"); } char arregloChar[] = new char[9]; uf.getChars( 0, 9, arregloChar, 0 ); // for ( int cuenta = 0; cuenta < arregloChar.length; cuenta++ ) // salida += arregloChar[ cuenta ]; System.out.print(arregloChar); } }
y esta es la frame que al precionar un botos quiero que me muestre el arreglo "arregloChar" en un texfile
Código:
me imagino que debe ser simple pero me he complicado un monton, por eso les agradesco su ayuda, saludos public class Ventana extends javax.swing.JFrame { String palabra; /** Creates new form Ventana */ public Ventana () { initComponents(); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { jPanel1 = new javax.swing.JPanel(); jButton1 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); jScrollPane1 = new javax.swing.JScrollPane(); jTextArea1 = new javax.swing.JTextArea(); jScrollPane2 = new javax.swing.JScrollPane(); jTextArea2 = new javax.swing.JTextArea(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jButton1.setText("Uf del dia"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); jButton2.setText("Noticia del dia"); jTextArea1.setColumns(20); jTextArea1.setRows(5); jScrollPane1.setViewportView(jTextArea1); jTextArea2.setColumns(20); jTextArea2.setRows(5); jScrollPane2.setViewportView(jTextArea2); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addGap(22, 22, 22) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 146, Short.MAX_VALUE) .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, 146, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(60, 60, 60)) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addGap(96, 96, 96) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jButton1) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 32, Short.MAX_VALUE) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jButton2) .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) ); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) ); pack(); }// </editor-fold> private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { System.out.println(); System.out.println("eeee"); // jTextArea1.setText(palabra); jTextArea1.setText("eee" + palabra); } /** * @param args the command line arguments */ // public static void main(String args[]) { // // java.awt.EventQueue.invokeLater(new Runnable() { // public void run() { // new Ventana().setVisible(true); // } // }); // } // Variables declaration - do not modify private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private javax.swing.JPanel jPanel1; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane2; private javax.swing.JTextArea jTextArea1; private javax.swing.JTextArea jTextArea2; // End of variables declaration }