Erro

3 respostas
B

se alguem souber me dizer qual eh o deslize q eu to comentendo..

o compilador "diz":cannot resolve symbol -> na linha :this.comandoRecebido(a); ....

codigo:

import javax.swing.*; 
import java.awt.*; 
import java.awt.event.*; 
import java.util.*;
import java.util.StringTokenizer; 

public class Bia extends JFrame { 

   JTextField frase; 
   JButton botao; 
   
   private String a, arrayComandos[]={"depende","instala","retira","usando","lista","fim"},arrayRecebido[], arrayPrinc_Dep[][];
   private int i=0, cont=0;   

   public Bia() 
   { 
      frase = new JTextField( 30 ); 
      botao = new JButton( "Executa" ); //botão que executa o comando

      botao.addActionListener( 
         new ActionListener() {
            public void actionPerformed( ActionEvent e ) 
            { 
               if ( frase.getText().equals( "fim" ) ) 
                  System.exit( 0 );
               a=frase.getText();
               this.comandoRecebido(a);
               JOptionPane.showMessageDialog( null, frase.getText() );// ação exibida 
            } 
         } 
     ); 
      Container box = getContentPane(); 
      box.setLayout( new FlowLayout() ); 
      box.add( frase ); 
      box.add( botao ); 
      pack(); 
      show(); 
   } 
//----------------P U B L I C  V O I D  C O M A N D O  R E C E B I D O----------------

       public void comandoRecebido(String t){   
       arrayRecebido=new String[6];
       arrayPrinc_Dep=new String[6][6]; 
           
        StringTokenizer st = new StringTokenizer(t);
       
        while (st.hasMoreTokens()) {         arrayRecebido[i]=st.nextToken();
                                             i++; }                            
                                           
    if(arrayRecebido[0].equals(arrayComandos[0])){
        System.out.println("sim//soh pra teste");
        this.dep();
        
        }
}

//--------------------------P U B L I C  V O I D  D E P----------------------------------------
         public void dep(){
            
            for(int j=0;j<i-1;j++){  arrayPrinc_Dep[cont][j]=arrayRecebido[j+1];
                                    System.out.println("arrayPrinc_dep["+cont+"]["+j+"]="+arrayPrinc_Dep[cont][j]);
                                    
                                 }
                                 cont++;
        }
//-----------------------------V O I D  M A I N-----------------------------------------

   public static void main( String[] args ) 
   { 
      Bia bia = new Bia(); 

      bia.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); 

   } 

}

[size="11"][color="green"]* Post editado para conter a tag CODE no seu código, não exite em usar esta tag, ela esta ai pra deixar seu código identado e mais legível. - matheus[/color][/size]

3 Respostas

W
botao.addActionListener(
         new ActionListener() {
            public void actionPerformed( ActionEvent e )
            {
               if ( frase.getText().equals( "fim" ) )
                  System.exit( 0 );
               a=frase.getText();
               this.comandoRecebido(a);
               JOptionPane.showMessageDialog( null, frase.getText() );// ação exibida
            }
         }
     );

Vc aqui criou uma outra classe (classe anônima ou conf. New_Radical: Inner Class). Vc está chamando, com o this, um método que “supostamente” faria parte dessa classe anônima, ou Inner Class. Retirando o this, vc estaria chamando o método da classe Bia.

B

BRIGADOS :smiley:

N

Tire o this!

Pq qnd vc o usa, vc está dizendo para ele referencia somente a essa classe.
E como vc criou uma Inner Class, ele só irá referencia a ela.

[]'s

Criado 11 de abril de 2004
Ultima resposta 11 de abr. de 2004
Respostas 3
Participantes 3