Foros del Web » Programación para mayores de 30 ;) » Java »

guardar en txt

Estas en el tema de guardar en txt en el foro de Java en Foros del Web. necesito guardar los datos ingresador a un txt y le agresco su ayuda // ValidateFrame.java // Validate user information using regular expressions. import java.awt.*; import ...
  #1 (permalink)  
Antiguo 30/07/2008, 23:45
 
Fecha de Ingreso: julio-2008
Mensajes: 2
Antigüedad: 15 años, 9 meses
Puntos: 0
guardar en txt

necesito guardar
los datos ingresador a un txt y le agresco su ayuda

// ValidateFrame.java
// Validate user information using regular expressions.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class ValidateFrame extends JFrame {
private JTextField phoneTextField, celularTextField, faxTextField, stateTextField,
cargoTextField, companiaTextField, firstTextField, lastTextField;

public ValidateFrame()
{
super( "Validate" );

// create the GUI components
JLabel phoneLabel = new JLabel( "Telefono" );
JLabel faxLabel = new JLabel( "Fax" );
JLabel stateLabel = new JLabel( "Celular" );
JLabel cargoLabel = new JLabel( "Cargo" );
JLabel companiaLabel = new JLabel( "Compañia" );
JLabel firstLabel = new JLabel( "Nombre" );
JLabel lastLabel = new JLabel( "Apellidos" );

JButton okButton = new JButton( "OK" );
okButton.addActionListener(

new ActionListener() { // inner class

public void actionPerformed( ActionEvent event ) {
validateDate();
}

} // end inner class

); // end call to addActionListener

phoneTextField = new JTextField( 8 );
faxTextField = new JTextField( 8 );
stateTextField = new JTextField( 8 );
cargoTextField = new JTextField( 12 );
companiaTextField = new JTextField( 20 );
firstTextField = new JTextField( 20 );
lastTextField = new JTextField( 30 );

JPanel firstName = new JPanel();
firstName.add( firstLabel );
firstName.add( firstTextField );

JPanel lastName = new JPanel();
lastName.add( lastLabel );
lastName.add( lastTextField );

JPanel compania1 = new JPanel();
compania1.add( companiaLabel );
compania1.add( companiaTextField );

JPanel address2 = new JPanel();
address2.add( cargoLabel );
address2.add( cargoTextField );
address2.add( stateLabel );
address2.add( stateTextField );
address2.add( faxLabel );
address2.add( faxTextField );

JPanel phone = new JPanel();
phone.add( phoneLabel );
phone.add( phoneTextField );


JPanel ok = new JPanel();
ok.add( okButton );

// add the components to the application
Container container = getContentPane();
container.setLayout( new GridLayout( 7, 2 ) );

container.add( firstName );
container.add( lastName );
container.add( compania1 );
container.add( address2 );
container.add( phone );
//container.add( celular );
container.add( ok );

setSize( 525, 325 );
setVisible( true );

} // end ValidateFrame constructor

public static void main( String args[] )
{
ValidateFrame application = new ValidateFrame();
application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
}

// handles okButton action event
private void validateDate()
{
// ensure that no textboxes are empty
if ( lastTextField.getText().equals( "" ) ||
firstTextField.getText().equals( "" ) ||
companiaTextField.getText().equals( "" ) ||
cargoTextField.getText().equals( "" ) ||
stateTextField.getText().equals( "" ) ||
faxTextField.getText().equals( "" ) ||
phoneTextField.getText().equals( "" ) ) // end condition

JOptionPane.showMessageDialog( this, "Please fill all fields" );

// if first name format invalid show message
else if ( !firstTextField.getText().matches( "[A-Z][a-zA-Z]*" ) )
JOptionPane.showMessageDialog( this, "Invalid first name" );

// if last name format invalid show message
else if ( !lastTextField.getText().matches( "[A-Z][a-zA-Z]*" ) )
JOptionPane.showMessageDialog( this, "Invalid last name" );

// if address format invalid show message
else if ( !companiaTextField.getText().matches(
"[A-Z][a-zA-Z]*" ) )
JOptionPane.showMessageDialog( this, "Invalid address" );

// if cargo format invalid show message
else if ( !cargoTextField.getText().matches(
"([a-zA-Z]+|[a-zA-Z]+\\s[a-zA-Z]+)" ) )
JOptionPane.showMessageDialog( this, "Invalid city" );

//if state format invalid show message
else if ( !stateTextField.getText().matches("[8][1-9]\\d{6}" ) )
JOptionPane.showMessageDialog( this, "Invalid Celular" );

// if fax code format invalid show message
else if ( !faxTextField.getText().matches( "[2][1-9]\\d{6}" ) )
JOptionPane.showMessageDialog( this, "Invalid fax code" );

// if phone number format invalid show message
else if ( !phoneTextField.getText().matches(
"[2][1-9]\\d{6}" ) )
JOptionPane.showMessageDialog( this, "Invalid phone number" );

else // information is valid, signal user

JOptionPane.showMessageDialog( this, "Thank you" );

} // end method validateDate

} // end class ValidateFrame
  #2 (permalink)  
Antiguo 31/07/2008, 06:04
 
Fecha de Ingreso: julio-2008
Ubicación: Ukraine, Donetsk
Mensajes: 43
Antigüedad: 15 años, 9 meses
Puntos: 0
Respuesta: guardar en txt

¿Y qué problema?
http://www.javapractices.com/topic/TopicAction.do?Id=42
Hay otro solucción: redirect system.out al fichero: http://www.devx.com/tips/Tip/5616 (redirect de system.out analogico) y simple escribir datos con System.out.println()
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 08:16.