Ficheros
Publicado por EdgarTX (13 intervenciones) el 06/02/2007 20:08:23
Hola que tal estan todos??? Una cosa, os dejo por aquí un código e un ejercicio de un fichero directo, que me da 2 errores en las líneas que os he marcado. A que se deben??? Muchas gracias por vuestro tiempo¡¡¡
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class Fichero extends Frame implements ActionListener{
RandomAccessFile fich;
TextField nombre, apellidos, consultN;
Choice edad;
Button grabar,consult,aceptar;
public Fichero(){
try{
fich=new RandomAccessFile("c:\\archivo.dat","rw");
}catch(IOException e){System.out.println(e.getMessage());}
setLayout(new FlowLayout());
nombre=new TextField(10);
apellidos=new TextField(10);
edad=new Choice();
edad.add("Entre 10 y 18");
edad.add("Entre 19 y 30");
edad.add("Entre 31 y 50");
aceptar=new Button ("Grabar");
consultN=new TextField(10);
consult=new Button("Consultar");
//Creación de paneles
Panel pNombre= new Panel();
pNombre.add(new Label("Nombre: "));
pNombre.add(nombre);
Panel pApe= new Panel();
pApe.add(new Label("Apellidos: "));
pApe.add(apellidos);
Panel pEdad= new Panel();
pEdad.add(new Label("Seleccione su edad: "));
pEdad.add(edad);
Panel pBtns= new Panel();
pBtns.add(grabar);
pBtns.add(consultN);
pBtns.add(consult);
add(pNombre);
add(pApe);
add(pEdad);
add(pBtns);
pNombre.setBackground(Color.orange);
pApe.setBackground(Color.orange);
pEdad.setBackground(Color.orange);
pBtns.setBackground(Color.orange);
grabar.addActionListener(this);
consult.addActionListener(this);
setSize(new Dimension (400,150));
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
Fichero.this.windowClosed();
}
});
}
public void actionPerformed(ActionEvent e){
try{
if(e.getActionCommand()=="Grabar"){
fich.seek(fich.length());
fich.writeBytes(cambiar(nombre.getText(),25));
fich.writeBytes(cambiar(apellidos.getText(),25));
String ed=new String(cambiar(edad.getSelectedItem(),15));
fich.writeBytes(ed);
}
if(e.getActionCommand()=="Consultar"){
byte nom[]=new byte[25];
byte ape[]=new byte[25];
byte ed[]=new byte[15];
------------1er Error-------------- fich.seek(Integer.valueOf(consultN.getTex())*65);
fich.readFully(nom);
fich.readFully(ape);
fich.readFully(ed);
String eda=new String(ed);
nombre.setText(new String(nom));
apellidos.setText(new String(ape));
System.out.println("#"+eda+".");
if(eda.equals("Entre 10 y 18")) edad.select(0);
if(eda.equals("Entre 19 y 30")) edad.select(1);
if(eda.equals("Entre 31 y 50")) edad.select(2);
}
}catch(Exception ss){
------------2º Error-------------- System.out.println(ss.Message());
nombre.setText("");
apellidos.setText("");
}
}
protected void windowClosed(){
System.exit(0);
}
public String cambiar(String s, int n){
if(s.length()<n)
for(int x=s.length();x<n;x++)
s=s+"";
return s;
}
}
---ERRORES---
C:\Documents and Settings\salae3\Escritorio\Fichero\src\Fichero.java:87: cannot find symbol
symbol : method getTex()
location: class java.awt.TextField
fich.seek(Integer.valueOf(consultN.getTex())*65);
^
C:\Documents and Settings\salae3\Escritorio\Fichero\src\Fichero.java:105: cannot find symbol
symbol : method Message()
location: class java.lang.Exception
System.out.println(ss.Message());
^
2 errors
Process completed.
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class Fichero extends Frame implements ActionListener{
RandomAccessFile fich;
TextField nombre, apellidos, consultN;
Choice edad;
Button grabar,consult,aceptar;
public Fichero(){
try{
fich=new RandomAccessFile("c:\\archivo.dat","rw");
}catch(IOException e){System.out.println(e.getMessage());}
setLayout(new FlowLayout());
nombre=new TextField(10);
apellidos=new TextField(10);
edad=new Choice();
edad.add("Entre 10 y 18");
edad.add("Entre 19 y 30");
edad.add("Entre 31 y 50");
aceptar=new Button ("Grabar");
consultN=new TextField(10);
consult=new Button("Consultar");
//Creación de paneles
Panel pNombre= new Panel();
pNombre.add(new Label("Nombre: "));
pNombre.add(nombre);
Panel pApe= new Panel();
pApe.add(new Label("Apellidos: "));
pApe.add(apellidos);
Panel pEdad= new Panel();
pEdad.add(new Label("Seleccione su edad: "));
pEdad.add(edad);
Panel pBtns= new Panel();
pBtns.add(grabar);
pBtns.add(consultN);
pBtns.add(consult);
add(pNombre);
add(pApe);
add(pEdad);
add(pBtns);
pNombre.setBackground(Color.orange);
pApe.setBackground(Color.orange);
pEdad.setBackground(Color.orange);
pBtns.setBackground(Color.orange);
grabar.addActionListener(this);
consult.addActionListener(this);
setSize(new Dimension (400,150));
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
Fichero.this.windowClosed();
}
});
}
public void actionPerformed(ActionEvent e){
try{
if(e.getActionCommand()=="Grabar"){
fich.seek(fich.length());
fich.writeBytes(cambiar(nombre.getText(),25));
fich.writeBytes(cambiar(apellidos.getText(),25));
String ed=new String(cambiar(edad.getSelectedItem(),15));
fich.writeBytes(ed);
}
if(e.getActionCommand()=="Consultar"){
byte nom[]=new byte[25];
byte ape[]=new byte[25];
byte ed[]=new byte[15];
------------1er Error-------------- fich.seek(Integer.valueOf(consultN.getTex())*65);
fich.readFully(nom);
fich.readFully(ape);
fich.readFully(ed);
String eda=new String(ed);
nombre.setText(new String(nom));
apellidos.setText(new String(ape));
System.out.println("#"+eda+".");
if(eda.equals("Entre 10 y 18")) edad.select(0);
if(eda.equals("Entre 19 y 30")) edad.select(1);
if(eda.equals("Entre 31 y 50")) edad.select(2);
}
}catch(Exception ss){
------------2º Error-------------- System.out.println(ss.Message());
nombre.setText("");
apellidos.setText("");
}
}
protected void windowClosed(){
System.exit(0);
}
public String cambiar(String s, int n){
if(s.length()<n)
for(int x=s.length();x<n;x++)
s=s+"";
return s;
}
}
---ERRORES---
C:\Documents and Settings\salae3\Escritorio\Fichero\src\Fichero.java:87: cannot find symbol
symbol : method getTex()
location: class java.awt.TextField
fich.seek(Integer.valueOf(consultN.getTex())*65);
^
C:\Documents and Settings\salae3\Escritorio\Fichero\src\Fichero.java:105: cannot find symbol
symbol : method Message()
location: class java.lang.Exception
System.out.println(ss.Message());
^
2 errors
Process completed.
Valora esta pregunta


0