Swing comando button

Bom dia pessoal !

então eu criei um programa semelhante ao substituir do bloco de notas até ai tudo bem eu passo duas variaveis como parametro …

então uso o comando replace para substituir , .
o problema foi quando eu fui criar um frame eu criei 2 campos textField e queria que as strings recebecem o que o usuario digita ,

e assin jogar a minha funçao ler dentro de um comando button … ai o usuario digita as duas palavras ele captura em uma string
e quando clicar no comando button ele executa a substituiçao ai segue o código me descupem pela bagunça é que sou novo em java

:slight_smile:



public class telate {   
      
   Frame me =new Frame();   
      
      
      
    String  procurarPor;    
     String  procurar1;   
     String substitui= "053";   
     String substituirPor = "ATP";      
     String arquivo = "teste.sql";    
        
  
   public void ler () throws IOException{   
         
         
// NESTA PARTE ELE FAZ A SUBSTUIÇÃO    
          
      
    //ler o arquivo      
    List<String> linhas = new ArrayList<String>();      
    BufferedReader reader = new BufferedReader(new FileReader(arquivo));      
    String linhaArquivo;      
    while(((linhaArquivo = reader.readLine())!= null)){      
        //substituir o conteudo    
          
      
    //ESSAS SÃO AS VARIAVEIS QUE PRECISAM RECEBER O QUE FOR DIGITADO    
          
        linhaArquivo = linhaArquivo.replace(procurarPor, substituirPor).replace(procurar1,substitui); ;      
        linhas.add(linhaArquivo);   
           
          
       
        //C:/Documents and Settings/Administrador/Meus documentos/teste.sql   
           
           
    }      
  
       
       
   reader.close();   
          
    //gravar arquivo      
    PrintWriter writer = new PrintWriter(new FileWriter(arquivo), true);      
    for (String linha : linhas) {      
        writer.println(linha);      
    }      
    writer.close();    
       
    String msg = " os paramêtros foram alterados com sucesso " + "" + "!";   
   JOptionPane.showMessageDialog(null, msg);   
      
   }   
  
       
    
   }  

essa é a classe que tem o método ler


public class Frame extends principal implements ActionListener {   
      
   principal prin = new principal();   
      
      
  
      
      
      
public JLabel label;   
public JLabel label2;   
public JTextField textField;   
public JTextField textField2;   
public JTextField textField33;   
public JButton button;   
public JPanel panel;   
public JFrame frame;   
  
  
public void montarFormulario() {   
  
label = new JLabel("Nome do Banco de Dados:");   
textField = new JTextField(20);   
  
button = new JButton("Alterar");   
label2 = new JLabel("Nome da Operação:");   
textField2 = new JTextField(20);   
button.addActionListener(this);   
textField33 = new JTextField(20);   
panel = new JPanel();   
  
panel.add(label);   
panel.add(textField);   
panel.add(label2);   
panel.add(textField2);   
panel.add(button);   
panel.add(textField33);   
  
frame = new JFrame("Configuração do Banco Scorpions");   
  
frame.setIconImage (new ImageIcon ("a.JPEG").getImage());   
frame.add(panel);   
frame.pack();   
frame.show();   
frame.setVisible(true);   
  
  
  
  
  
}   
  
  
  
public void actionPerformed (ActionEvent e) {   
  String procurarPor =textField.getText();   
  textField2.getText();   
  
JOptionPane.showMessageDialog(frame, procurarPor);   
  
  
}   
public void botao() {      
    this.button.addActionListener(      
                new ActionListener() {      
                        public void actionPerformed(ActionEvent evt) {      
                                  String procurarPor  = textField.getText();      
                                 String procurar1  = textField2.getText();      
                               System.out.println(procurarPor);   
                               System.out.println(procurar1);   
                        }      
                });      
}      
  
  
  
  
  
  
  
  
  
  
  
}  

aqui eu crio o meu frame


public class principal  {   
  
   /**  
    * @param args  
    * @throws IOException   
    */  
   public static void main(String[] args) throws IOException {   
         
         
      telate ler = new telate();   
         
      
         
      Frame frame = new Frame();   
         
  
         
         
         
       frame.label = new JLabel("Nome do Banco de Dados:");   
        frame.textField = new JTextField(20);   
  
        frame.button = new JButton("Alterar");   
        frame.label2 = new JLabel("Nome da Operação:");   
        frame.textField2 = new JTextField(20);   
          
           
        frame.panel = new JPanel();   
  
        frame.panel.add(frame.label);   
        frame.panel.add(frame.textField);   
        frame.panel.add(frame.label2);   
        frame.panel.add(frame.textField2);   
        frame.panel.add(frame.button);   
           
  
        frame.frame = new JFrame("ALTERAÇÃO DO BANCO DE DADOS");   
        frame.frame.add(frame.panel);   
        frame.frame.pack();   
        frame.frame.setVisible(true);   
         
           
      String  procurarPor= frame.textField.getText();     
     String  procurar1= frame.textField2.getText();   
     String substitui= "053";   
     String substituirPor = "PARABENS";      
     String arquivo = "teste.sql";   
        
     // EU NÃO CONSIGO IMPLEMENTAR ESSE COMANDO NESTA CLASSE     
     frame.botao();   
       
        
     if (procurarPor != "" ){   
        
        ler.ler();   
           
     }   
           
        System.out.println(procurar1);   
           
         
  
   }   
  
      
   }   
      

esta é a do programa principal …

alguem me ajude por favor

Não sei os outros, mas eu não entendi o que vc quer.

então amigo assim como eu falei anteriormente eu fiz um progrma igual ao substituir do bloco de notas …

eu pego duas strings e altero em um txt até ai rodou normal …

mais eu criei um frame que contem dois campos textos aonde eu quero que o usuario entre com o valor …

eu não consigo atribuir o valor que o osuario digita em um textField e jogar na minha string para executar o comando replace que vai substituir no txt.,

e o frame tem um comando button eu queria jogar a minha funçao que substitui dentro do comando button …

resumindo ai quando o usuario clicar no comando button o programa executa o método e altera o txt …

alguem por favor me ajude !!!

Não sei se esta totalmente correto mas se não me engado é assim que voce define o metodo para o botão

meubotao.addActionListener(
                        new ActionListener() {

                            public void actionPerformed(ActionEvent e) {
                               //aqui o que o botão ira fazer      
                            }
                        });