Problema com ActionListener

3 respostas
dellandre

Main.java
*

  • Created on 16 de Março de 2010, 17:17
  • To change this template, choose Tools | Template Manager
  • and open the template in the editor.
    */

package teste;

/**
*

  • @author franciscodg
    
    <em>/
    
    import java.beans.EventHandler;
    
    import javax.swing.Action;
    
    import java.awt.event.ActionEvent;
    
    import java.awt.event.ActionListener;
    
    import javax.swing.</em>;
    
    import javax.swing.JOptionPane;
    
    import java.awt.Event;
    
    import javax.swing.JPanel.<em>;
    
    import javax.swing.JLabel;
    
    import javax.swing.JFileChooser;
    
    import java.lang.String;
    
    import javax.swing.Action;
    
    import <a href="http://java.io">java.io</a>.</em>;
    
    public class Main {
    
    /** Creates a new instance of Main */
    
    public Main() {
    
    JLabel label = new JLabel(Diretório:);
    
    JLabel label2 = new JLabel(Palavra:);
    
    JButton localizar = new JButton(Buscar);
    
    JButton arquivo = new JButton (Pesquisar);
    
    JPanel painel = new JPanel();
    
    JFrame frmBusca = new JFrame(Busca Palavra);
    
    JFileChooser fc = new JFileChooser();
    
    JTextField diretorio = new JTextField(20);
    
    JTextField palavra = new JTextField(10);
    
    localizar.addActionListener(new ActionListener(){
          public void actionPerformed(ActionEvent e){
             String x;
             x = diretorio.getText();
             
                         
         }
    

    });

    }

    /**

    • @param args the command line arguments
      */
      public static void main(String[] args) {
      }
      }
      =======================================================================================

se alguém puder me ajudar!!!

está dando erro aqui: x = diretorio.getText();

3 Respostas

ViniGodoy

Ao postar códigos, use a tag code.

Seu código aqui

Senão fica muito difícil da gente ler.

Poneis123

Nos próximos post procura utilizar a dica acima da tag code e deixe ele identado certinho..

Mas vamos aos problemas:

Main.java
/* 
* 
* Created on 16 de Março de 2010, 17:17 
* 
* To change this template, choose Tools | Template Manager 
* and open the template in the editor. 
*/  
  
package teste;  
  
/** 
* 
* @author franciscodg 
*/  
import java.beans.EventHandler;  
import javax.swing.Action;  
import java.awt.event.ActionEvent;  
import java.awt.event.ActionListener;  
import javax.swing.*;  
import javax.swing.JOptionPane;  
import java.awt.Event;  
import javax.swing.JPanel.*;  
import javax.swing.JLabel;  
import javax.swing.JFileChooser;  
import java.lang.String;  
import javax.swing.Action;  
import java.io.*;  

public class Main { 
  
/** Creates a new instance of Main */  
public Main() {
	JLabel label = new JLabel("Diretório:");  
	JLabel label2 = new JLabel("Palavra:");  
	JButton localizar = new JButton("Buscar");  
	JButton arquivo = new JButton ("Pesquisar");  
	JPanel painel = new JPanel();  
	JFrame frmBusca = new JFrame("Busca Palavra");  
	JFileChooser fc = new JFileChooser();  
	JTextField diretorio = new JTextField(20);  
	JTextField palavra = new JTextField(10);  
	  
	  
	localizar.addActionListener(new ActionListener(){
		public void actionPerformed(ActionEvent e){  
			String x;  
			x = diretorio.getText();  
		}  
	});  
}
  
/** 
* @param args the command line arguments 
*/  
public static void main(String[] args) {  
}  
}

-> x = diretorio.getText(); ta com erro pois o método actionPerformed() não consegue enxergar ele, pois ele está declarado dentro do construtor, vc precisaria declarar ele na classe, fora do método contrutor.

WellingtonRamos

Sem o detalhe do erro que está ocorrendo fica difícil ajudar.

Criado 17 de março de 2010
Ultima resposta 17 de mar. de 2010
Respostas 3
Participantes 4