Académique Documents
Professionnel Documents
Culture Documents
java
package ManejodeArchivos;
import java.io.*;
import java.awt.*;
import javax.swing.*;
public class winArchivo extends javax.swing.JFrame
{
public winArchivo()
{
initComponents();
}
private void btnGuardarActionPerformed(java.awt.event.ActionEvent evt) {
String cod = txtCod.getText();
String nom = txtNom.getText();
String suel = txtSuel.getText();
try
{
FileWriter fw = new FileWriter("datos.txt",true);
PrintWriter pw = new PrintWriter(fw);
pw.println(cod + "\t" + nom + "\t\t" + suel);
pw.close();
txtCod.setText(""); txtNom.setText("");
txtSuel.setText("");
txtCod.requestFocus();
} catch (Exception e)
{
String error = e.toString();
JOptionPane.showMessageDialog(this,error);
}
}
private void btnMostrarActionPerformed(java.awt.event.ActionEvent evt) {
String nom, suel;
// Este tipo "monospaced" brinda una letra de un mismo tamaño (ancho)
TxaD.setFont(new Font("monospaced",Font.PLAIN,11));
TxaD.setText(""); // limpiando el JTextArea
try
{
FileReader fr = new FileReader ("datos.txt");
BufferedReader br = new BufferedReader(fr);
String linea;
while((linea = br.readLine())!=null)
TxaD.append(linea + "\n");
br.close(); // cerrando el archivo
}
catch(IOException e)
{
String error = e.toString();
JOptionPane.showMessageDialog(this,error);
}
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new winArchivo().setVisible(true);
}
});
}
winArchivo2Token
package ManejodeArchivos;
import java.io.*;
import java.awt.*;
import javax.swing.*;
import java.util.*;
public class winArchivo2Token extends javax.swing.JFrame
{
public winArchivo2Token()
{
initComponents();
}
private void btnGrabarActionPerformed(java.awt.event.ActionEvent evt) {
String cod = txtCod.getText();
String nom = txtNom.getText();
String area = txtArea.getText();
String suel = txtSuel.getText();
try
{
FileWriter fw = new FileWriter("emple.txt",true);
PrintWriter pw = new PrintWriter(fw);
pw.println(cod + "," +nom + ","+ area+","+suel);
pw.close();
txtCod.setText("");
txtNom.setText("");
txtArea.setText("");
txtSuel.setText("");
txtCod.requestFocus();
} catch (Exception e)
{
String error = e.toString();
JOptionPane.showMessageDialog(this,error);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new winArchivo2Token().setVisible(true);
}
});
}