Mensajes [1] - Enviado el Miércoles 14 de Noviembre de 2007 a las 23:14hs
la duda es la siguiente en c?digo que dejo mas abajo necesito grabar en un archivo txt la variable "total" que guarda todos los datos que ingresaron el los diferentes TextField si me pueden ayudar con el codigo muchas gracias ya que llevo 3 dias en esto y no me sale nada
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
public class Ingresoc extends Frame
{
Panel p1 = new Panel();
Panel p2 = new Panel();
Panel p3 = new Panel();
Button btn1 = new Button("Grabar");
Button btn2 = new Button("Buscar");
Button btn3 = new Button("Salir");
TextField txt1 = new TextField(10);
TextField txt2 = new TextField(10);
TextField txt3 = new TextField(10);
TextField txt4 = new TextField(10);
TextField txt5 = new TextField(10);
TextField txt6 = new TextField(10);
TextField txt7 = new TextField(10);
TextField txt8 = new TextField(10);
TextField txt9 = new TextField(10);
Label lbl1 = new Label("Rut: ");
Label lbl2 = new Label("Nombres: ");
Label lbl3 = new Label("Apellido Paterno: ");
Label lbl4 = new Label("Apellido Materno: ");
Label lbl5 = new Label("Fecha de Nacimiento:");
Label lbl6 = new Label("Edad: ");
Label lbl7 = new Label("Direcci?n: ");
Label lbl8 = new Label("Tel?fono: ");
Label lbl9 = new Label("Mail: ");
public Ingresoc()
{
super("Clientes");
setSize(300,320);
setLocation(300,300);
setResizable(false);
p2.add(lbl1,BorderLayout.WEST);
p2.add(txt1,BorderLayout.EAST);
p2.add(lbl2,BorderLayout.WEST);
p2.add(txt2,BorderLayout.EAST);
p2.add(lbl3,BorderLayout.WEST);
p2.add(txt3,BorderLayout.EAST);
p2.add(lbl4,BorderLayout.WEST);
p2.add(txt4,BorderLayout.EAST);
p2.add(lbl5,BorderLayout.WEST);
p2.add(txt5,BorderLayout.EAST);
p2.add(lbl6,BorderLayout.WEST);
p2.add(txt6,BorderLayout.EAST);
p2.add(lbl7,BorderLayout.WEST);
p2.add(txt7,BorderLayout.EAST);
p2.add(lbl8,BorderLayout.WEST);
p2.add(txt8,BorderLayout.EAST);
p2.add(lbl9,BorderLayout.WEST);
p2.add(txt9,BorderLayout.EAST);
p3.add(btn1,BorderLayout.SOUTH);
p3.add(btn2,BorderLayout.SOUTH);
p3.add(btn3,BorderLayout.SOUTH);
btn1.addActionListener(new oyente());
btn1.setActionCommand("Grabar");
btn2.addActionListener(new oyente2());
btn2.setActionCommand("Buscar");
btn3.addActionListener(new oyente3());
btn3.setActionCommand("Salir");
add(p1,BorderLayout.WEST);
add(p2,BorderLayout.CENTER);
add(p3,BorderLayout.SOUTH);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent evt){
System.exit(0);
}
});
show();
}
public class oyente implements ActionListener
{
public void actionPerformed (ActionEvent e)
{
String Str = e.getActionCommand();
if (Str.compareTo("Grabar")==0)
{
int a=0;
//---------------------------------------------------------------------------------------------------
String Rut = new String(txt1.getText());
String Nomb = new String(txt2.getText());
String apepat = new String(txt3.getText());
String apemat = new String(txt4.getText());
String fchnac = new String(txt5.getText());
String edad = new String(txt6.getText());
String direcc = new String(txt7.getText());
String telefo = new String(txt8.getText());
String mail = new String(txt9.getText());
if(Rut.length()==10)
{
valida rut=new valida();
int r = rut.val(Rut);
if(r==50){
a = a + 1;
}else
{
JOptionPane.showMessageDialog (null,"Rut incorrecto ");
}
}else
{
JOptionPane.showMessageDialog (null,"Rut incorrecto ");
}
nombre nom=new nombre();
int n = nom.nombr(Nomb);
int m = Nomb.length();
if(n==5){
if(m > 2){
a = a + 1;
}else
{
JOptionPane.showMessageDialog (null,"El Nombre es incorrecto");
}
}else
{
JOptionPane.showMessageDialog (null,"El Nombre es incorrecto ");
}
nombre apell=new nombre();
int x = apell.nombr(apepat);
int k = apepat.length();
if(x==5){
if(k > 4){
a = a + 1;
}else
{
JOptionPane.showMessageDialog (null,"El Apellido paterno es incorrecto ");
}
}else
{
JOptionPane.showMessageDialog (null,"El Apellido paterno es incorrecto ");
}
nombre mater=new nombre();
int t = mater.nombr(apemat);
int q = apemat.length();
if(t==5){
if(q > 4){
a = a + 1;
}else
{
JOptionPane.showMessageDialog (null,"El Apellido Materno es incorrecto ");
}
}else
{
JOptionPane.showMessageDialog (null,"El Apellido Materno es incorrecto ");
}
int p;
char com;
if((p=fchnac.length()) > 7){
if(p == 8){
if((com = fchnac.charAt(2)) == '/'){
if((com = fchnac.charAt(5)) == '/'){
a = a + 1;
}
else{
JOptionPane.showMessageDialog (null,"La fecha es incorrecta xx/xx/xx 1");
}
}
else{
JOptionPane.showMessageDialog (null,"La fecha es incorrecta xx/xx/xx 2");
}
}
else{
JOptionPane.showMessageDialog (null,"La fecha es incorrecta xx/xx/xx 3");
}
}
else{
JOptionPane.showMessageDialog (null,"La fecha es incorrecta xx/xx/xx 4");
}
valida tele = new valida();
int te = tele.num(telefo);
if(te == 5){
a = a + 1;
}
else{
JOptionPane.showMessageDialog (null,"En Telefono : solo se aceptan n?meros");
}
if(a == 6){
String total = new String(Rut+"/"+Nomb+"/"+apepat+"/"+apemat+"/"+fchnac+"/"+edad+"/"+direcc+"/"+telefo+"/"+mail);
graba g = new graba();
boolean res=g.cadena(total);
}
}
}
}
public class oyente2 implements ActionListener
{
public void actionPerformed (ActionEvent e)
{
String Str = e.getActionCommand();
if (Str.compareTo("Buscar")==0)
{
JOptionPane.showMessageDialog (null,"");
}
}
}
public class oyente3 implements ActionListener
{
public void actionPerformed (ActionEvent e)
{
String Str = e.getActionCommand();
if (Str.compareTo("Salir")==0)
{
dispose();
}
}
}
Mensajes [1] - Enviado el Martes 05 de Mayo de 2009 a las 23:33hs
Tengo la misma duda solo quiero saber como grabar un archivo Txt el Java, igualmente como borrarlo
Mensajes [3] - Enviado el Miércoles 06 de Mayo de 2009 a las 20:44hs
Aqui hay una respuesta es en consola pero guarda lo que se quiere escribir en una variable, solo seria reemplazar lo que se quiere cambiar
http://kayrosfuacnet.webs.com/apps/forums/topics/show/683282-actividad-flujos-java?page=last
Espero les sirva