Manipulação de arquivos

2 respostas
van_bommel
public class regAgenda {
   
   
   
      private String nome ;
   
      private String end ;
   
      private String tel ;
   
   
   
       public regAgenda ( String nome , String end , String tel ){
         this.nome = nome ;
         this.end = end ;
         this.tel = tel ;
      
      }
      
       public String mostraNome () {
      
         return nome ;
      }
   	 
       public String mostraEnd () {
      
         return end ;
      
      }
   	
   	 
       public String mostraTel () {
      
         return tel ;
      }
      
   	
   
   
   }
   import java.io.*;

    public class TestaAgenda {
   
       public static void main ( String args [] ){
      
         try {
         // declaro uma variavel para receber os caracteres ;
            BufferedReader entrada ;
         
            entrada = new BufferedReader ( new InputStreamReader( System.in));
         
         
            BufferedWriter saida ;
            saida = new BufferedWriter ( new FileWriter ( "agenda.txt", true ));
         
         
            System.out.println ( " digite o nome" ); 
            String nome = entrada.readLine();
         
            System.out.println ( " digite o Endereço" ); 
            String end = entrada.readLine();
            System.out.println ( " digite o Telefone" ); 
            String tel = entrada.readLine();
         
         
            regAgenda agenda = new  regAgenda  (nome,end , tel );
         
         
            saida.write (agenda.mostraNome() + "\t" );   
            saida.write (agenda.mostraEnd() + "\t" );   
            saida.write (agenda.mostraTel() + "\n\n" );   
         
            saida.flush();
            saida.close();
         }
             catch ( Exception e ) {
               System.out.println ( " erro de gravação" ); 
            }
      }
   }

Eaiii galeraa...como façoo para fazer essa classe com entrada do teclado usando a classe JOptionPane.

2 Respostas

Thiago_Luis

Fala cara, blza?

É só importar javax.swing.JOptionPane;
E ao invés de usar

BufferedReader entrada ; entrada = new BufferedReader ( new InputStreamReader( System.in));
Já atribua direto:

String nome = JOptionPane.showInputDialog(null,"Digite seu nome");

Ah, showInputDialog() retorna sempre String, se vc quiser manipular um interio, por exemplo, vai precisar parsear.

Abraço.

lina

Thiago Luis:
Fala cara, blza?

É só importar javax.swing.JOptionPane;
E ao invés de usar

BufferedReader entrada ; entrada = new BufferedReader ( new InputStreamReader( System.in));
Já atribua direto:

String nome = JOptionPane.showInputDialog(null,"Digite seu nome");

Ah, showInputDialog() retorna sempre String, se vc quiser manipular um interio, por exemplo, vai precisar parsear.

Abraço.

Oi,

E para mostrar o resultado, você pode fazer.:

JOptionPane.showMessageDialog(null,nome);

Tchauzin!

Criado 15 de agosto de 2009
Ultima resposta 17 de ago. de 2009
Respostas 2
Participantes 3