Ajuda transformar setText em setInteger

Fala galera beleza?, então alguém poderia me ajudar a transformar essa linha em integer?

txtNome_Produto.setText(produto.getNome_produto());

Obrigado

no parâmetro que você passa pro setText(), o usuário vai digitar campos com letras ou apenas números

entao era pra apenas numeros, porem nao da certo

Faça o seguinte:

[code]int p = Integer.parseInt(produto.getNome_produto());

[/code]

Seria isso? Você quer converter o valor de “produto.getNome_produto()” para inteiro? Se for é assim que faz. Só é estranho o nome de um produto ser inteiro :S

[quote=Matheus terra]Faça o seguinte:

[code]int p = Integer.parseInt(produto.getNome_produto());

[/code]

Seria isso? Você quer converter o valor de “produto.getNome_produto()” para inteiro? Se for é assim que faz. Só é estranho o nome de um produto ser inteiro :S[/quote]

hehehe, na verdade vou converter a variavel “codigo” porém a unica que esta funcionando no codigo é a variavel “nome_produto”, por isso coloquei ela aqui como exemplo hehe, vou testar isso que você disse

O esquema é o mesmo. Você coloca entre os parenteses a sua String que contém os numeros.

Qualquer coisa, dando certo ou não posta ae de novo

tentei e deu o seguinte erro

Posta o código ae…

[quote=Matheus terra]Posta o código ae…

[/quote]

Segue o codigo completo:

OS ERROS ESTAO A PARTIR DA LINHA 428

[code]/*

  • To change this template, choose Tools | Templates
  • and open the template in the editor.
    */
    package Formulario;

import Persistencia.ProdutoDAO;
import javax.swing.JOptionPane;
import Modelo.Produto;
import Persistencia.ProdutoDAO;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.JOptionPane;
import javax.swing.text.MaskFormatter;

/**
*

  • @author Atila
    */
    public class FrmProduto extends javax.swing.JFrame {

    /**

    • Creates new form FrmProduto
      */
      public FrmProduto() {
      initComponents();

    //para centralizar a tela
    java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
    int componentWidth = this.getWidth();
    int componentHeight = this.getHeight();
    this.setBounds((screenSize.width - componentWidth) / 2, (screenSize.height - componentHeight) / 2, componentWidth, componentHeight);
    }
    /**

    • This method is called from within the constructor to initialize the form.

    • WARNING: Do NOT modify this code. The content of this method is always

    • regenerated by the Form Editor.
      */
      @SuppressWarnings(“unchecked”)
      //
      private void initComponents() {

      jPanel2 = new javax.swing.JPanel();
      jLabel1 = new javax.swing.JLabel();
      txtCodigo = new javax.swing.JTextField();
      jLabel4 = new javax.swing.JLabel();
      jLabel5 = new javax.swing.JLabel();
      txtCodigo_Fornecedor = new javax.swing.JTextField();
      jLabel13 = new javax.swing.JLabel();
      txtNome_Produto = new javax.swing.JTextField();
      jLabel2 = new javax.swing.JLabel();
      jLabel3 = new javax.swing.JLabel();
      txtQuantidade_Estoque = new javax.swing.JTextField();
      txtValor_Custo = new javax.swing.JTextField();
      txtValor_Venda = new javax.swing.JTextField();
      jPanel1 = new javax.swing.JPanel();
      btnInclusao = new javax.swing.JButton();
      btnAlteracao = new javax.swing.JButton();
      btnExclusao = new javax.swing.JButton();
      btnConsulta = new javax.swing.JButton();

      setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

      jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

      jLabel1.setText(“Codigo”);

      txtCodigo.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      txtCodigoActionPerformed(evt);
      }
      });

      jLabel4.setText(“Valor Custo”);

      jLabel5.setText(“Valor Venda”);

      txtCodigo_Fornecedor.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      txtCodigo_FornecedorActionPerformed(evt);
      }
      });

      jLabel13.setText(“Codigo Fornecedor”);

      txtNome_Produto.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      txtNome_ProdutoActionPerformed(evt);
      }
      });

      jLabel2.setText(“Nome”);

      jLabel3.setText(“Quantidade Estoque”);

      txtQuantidade_Estoque.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      txtQuantidade_EstoqueActionPerformed(evt);
      }
      });

      txtValor_Custo.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      txtValor_CustoActionPerformed(evt);
      }
      });

      txtValor_Venda.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      txtValor_VendaActionPerformed(evt);
      }
      });

      javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
      jPanel2.setLayout(jPanel2Layout);
      jPanel2Layout.setHorizontalGroup(
      jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(jPanel2Layout.createSequentialGroup()
      .addGap(0, 0, Short.MAX_VALUE)
      .addComponent(jLabel1)
      .addGap(18, 18, 18)
      .addComponent(txtCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addGap(18, 18, 18)
      .addComponent(jLabel13)
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
      .addComponent(txtCodigo_Fornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE))
      .addGroup(jPanel2Layout.createSequentialGroup()
      .addComponent(jLabel4)
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
      .addComponent(txtValor_Custo, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
      .addComponent(jLabel5)
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
      .addComponent(txtValor_Venda, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addGap(44, 44, 44))
      .addGroup(jPanel2Layout.createSequentialGroup()
      .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(jPanel2Layout.createSequentialGroup()
      .addComponent(jLabel2)
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
      .addComponent(txtNome_Produto))
      .addGroup(jPanel2Layout.createSequentialGroup()
      .addContainerGap()
      .addComponent(jLabel3)
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
      .addComponent(txtQuantidade_Estoque)))
      .addContainerGap())
      );
      jPanel2Layout.setVerticalGroup(
      jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(jPanel2Layout.createSequentialGroup()
      .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
      .addComponent(jLabel1)
      .addComponent(txtCodigo_Fornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addComponent(jLabel13)
      .addComponent(txtCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
      .addGap(25, 25, 25)
      .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
      .addComponent(jLabel2)
      .addComponent(txtNome_Produto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
      .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
      .addComponent(txtQuantidade_Estoque, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addComponent(jLabel3))
      .addGap(20, 20, 20)
      .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
      .addComponent(jLabel4)
      .addComponent(jLabel5)
      .addComponent(txtValor_Custo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addComponent(txtValor_Venda, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
      .addContainerGap(148, Short.MAX_VALUE))
      );

      jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

      btnInclusao.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagem/inclusao.png"))); // NOI18N
      btnInclusao.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      btnInclusaoActionPerformed(evt);
      }
      });

      btnAlteracao.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagem/alteracao.png"))); // NOI18N
      btnAlteracao.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      btnAlteracaoActionPerformed(evt);
      }
      });

      btnExclusao.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagem/exclusao.png"))); // NOI18N
      btnExclusao.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      btnExclusaoActionPerformed(evt);
      }
      });

      btnConsulta.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagem/consulta.png"))); // NOI18N
      btnConsulta.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      btnConsultaActionPerformed(evt);
      }
      });

      javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
      jPanel1.setLayout(jPanel1Layout);
      jPanel1Layout.setHorizontalGroup(
      jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(jPanel1Layout.createSequentialGroup()
      .addContainerGap()
      .addComponent(btnInclusao)
      .addGap(33, 33, 33)
      .addComponent(btnAlteracao)
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
      .addComponent(btnExclusao)
      .addGap(18, 18, 18)
      .addComponent(btnConsulta)
      .addGap(18, 18, 18))
      );
      jPanel1Layout.setVerticalGroup(
      jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(jPanel1Layout.createSequentialGroup()
      .addContainerGap()
      .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(btnAlteracao, javax.swing.GroupLayout.Alignment.TRAILING)
      .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
      .addComponent(btnInclusao)
      .addComponent(btnExclusao)
      .addComponent(btnConsulta)))
      .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
      );

      javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
      getContentPane().setLayout(layout);
      layout.setHorizontalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(layout.createSequentialGroup()
      .addContainerGap()
      .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
      .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
      .addContainerGap())
      );
      layout.setVerticalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(layout.createSequentialGroup()
      .addContainerGap()
      .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
      .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
      );

      pack();
      }//

    private void btnInclusaoActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
    //Cria um objeto do tipo aluno
    Produto produto = new Produto();
    //O objeto recebe os atributos que foram digitados pelo usuário no formulário
    produto.setCodigo(Integer.parseInt(txtCodigo.getText()));
    produto.setCodigo_fornecedor(Integer.parseInt(txtCodigo_Fornecedor.getText()));
    produto.setNome_produto(txtNome_Produto.getText());
    produto.setQuantidade_estoque(Integer.parseInt(txtQuantidade_Estoque.getText()));
    produto.setValor_custo(Double.parseDouble(txtValor_Custo.getText()));
    produto.setValor_venda(Double.parseDouble(txtValor_Venda.getText()));
    /* //validação dos campos data deste formulário
    try {
    SimpleDateFormat sdf = new SimpleDateFormat(“dd/MM/yyyy”);
    aluno.setDataNascimento(sdf.parse(fmtTxtDataNascimento.getText()));
    //construtor Date sem parâmetro pega data/hora atual do sistema
    aluno.setDataMatricula(new Date());
    } catch (Exception e) {
    JOptionPane.showMessageDialog(null, “Data de Nascimento não está no formato correto”);
    return;
    }
    produto.setCpf(fmtTxtCpf.getText());
    aluno.setRg(fmtTxtRg.getText());
    aluno.setEmail(txtEmail.getText());
    aluno.setLogin(txtLogin.getText());
    aluno.setSenha(new String(pswSenha.getPassword()));*/
    //Cria um objeto do tipo Dao (persistência)
    ProdutoDAO dao = new ProdutoDAO();
    //Verifica se já existe o Aluno cadastrado
    try {
    if (dao.incluir(produto) == true) {
    JOptionPane.showMessageDialog(null, “Produto incluído com sucesso”);
    } else {
    JOptionPane.showMessageDialog(null, “Produto já existe”);
    }
    //limpar os campos da tela
    txtCodigo.setText("");
    txtNome_Produto.setText("");
    txtQuantidade_Estoque.setText("");
    txtValor_Custo.setText("");
    txtValor_Venda.setText("");

     } catch (Exception e) {
         JOptionPane.showMessageDialog(null, "Falhou. Motivo:" + e.getMessage());
     }
    

    }

    private void btnAlteracaoActionPerformed(java.awt.event.ActionEvent evt) {
    try {
    Produto produto = new Produto(Integer.parseInt(txtCodigo.getText()));
    produto.setCodigo_fornecedor(Integer.parseInt(txtCodigo_Fornecedor.getText()));
    produto.setNome_produto(txtNome_Produto.getText());
    produto.setQuantidade_estoque(Integer.parseInt(txtQuantidade_Estoque.getText()));
    produto.setValor_custo(Double.parseDouble(txtValor_Custo.getText()));
    produto.setValor_venda(Double.parseDouble(txtValor_Venda.getText()));

         ProdutoDAO dao = new ProdutoDAO();
         boolean alterado = dao.alterar(produto);
         if (alterado == true) {
             JOptionPane.showMessageDialog(null, "Produto alterado com sucesso");
             txtCodigo.setText("");
             txtCodigo_Fornecedor.setText("");
             txtNome_Produto.setText("");
             txtQuantidade_Estoque.setText("");
             txtValor_Custo.setText("");
             txtValor_Venda.setText("");
             
             btnAlteracao.setEnabled(false);
             btnExclusao.setEnabled(false);
             txtCodigo.setEnabled(true);
             btnInclusao.setEnabled(true);
    
         } else {
             JOptionPane.showMessageDialog(null, "Produto não pôde ser alterado.");
         }
    
     } catch (Exception e) {
         JOptionPane.showMessageDialog(null, "Ocorreu um erro:" + e.getMessage());
    
     }
     }
    
     private void btnInclusaoAlunoActionPerformed(java.awt.event.ActionEvent evt) {
         //Cria um objeto do tipo aluno
         Produto produto = new Produto();
         //O objeto recebe os atributos que foram digitados pelo usuário no formulário
         produto.setCodigo(Integer.parseInt(txtCodigo.getText()));
         produto.setCodigo_fornecedor(Integer.parseInt(txtCodigo_Fornecedor.getText()));
         produto.setNome_produto(txtNome_Produto.getText());
         produto.setQuantidade_estoque(Integer.parseInt(txtQuantidade_Estoque.getText()));
         produto.setValor_custo(Double.parseDouble(txtValor_Custo.getText()));
          produto.setValor_venda(Double.parseDouble(txtValor_Venda.getText()));
        /* //validação dos campos data deste formulário
         
         */
         //Cria um objeto do tipo Dao (persistência)
         ProdutoDAO dao = new ProdutoDAO();
         //Verifica se já existe o Produto cadastrado
         try {
             if (dao.incluir(produto) == true) {
                 JOptionPane.showMessageDialog(null, "Produto incluído com sucesso");
             } else {
                 JOptionPane.showMessageDialog(null, "Produto já existe");
              }
             //limpar os campos da tela
             txtCodigo.setText("");
             txtCodigo_Fornecedor.setText("");
             txtNome_Produto.setText("");
             txtQuantidade_Estoque.setText("");
             txtValor_Custo.setText("");
             txtValor_Venda.setText("");
             
         } catch (Exception e) {
             JOptionPane.showMessageDialog(null, "Falhou. Motivo:" + e.getMessage());
         }
    

    }

    private void btnExclusaoActionPerformed(java.awt.event.ActionEvent evt) {
    try {
    int opcaoDoUsuario = JOptionPane.showConfirmDialog(null, “Deseja excluir?”,
    “Exclusão”, JOptionPane.YES_NO_OPTION);
    if (opcaoDoUsuario == 0) {
    Produto produto = new Produto(Integer.parseInt(txtCodigo.getText()));
    ProdutoDAO dao = new ProdutoDAO();
    boolean excluido = dao.excluir(produto);
    if (excluido == true) {
    txtCodigo.setText("");
    txtCodigo_Fornecedor.setText("");
    txtNome_Produto.setText("");
    txtQuantidade_Estoque.setText("");
    txtValor_Custo.setText("");
    txtValor_Venda.setText("");

                 JOptionPane.showMessageDialog(null, "Produto excluído com sucesso.");
                 btnExclusao.setEnabled(false);
                 btnAlteracao.setEnabled(false);
                 txtCodigo.setEnabled(true);
                 btnInclusao.setEnabled(true);
             } else {
                 JOptionPane.showMessageDialog(null, "Produto não pôde ser excluído.");
             }
         }
    
     } catch (Exception e) {
         JOptionPane.showMessageDialog(null, "Produto não pôde ser excluído:" + e.getMessage());
     }
    

    }

    private void btnConsultaActionPerformed(java.awt.event.ActionEvent evt) {
    try{
    int codigo = 0;

        /* int codigo_fornecedor = 0;
         int quantidade_estoque = 0;
         double valor_custo = 0;
         double valor_venda =0;*/
         
         try{
             codigo = Integer.parseInt(txtCodigo.getText());
         }
         catch (Exception e){
             JOptionPane.showMessageDialog(null, "Você precisa digitar um código.");
             return;
         }
         Produto produto = new Produto(codigo);
         ProdutoDAO dao = new ProdutoDAO();
         boolean resultado = dao.consultar(produto);
         if (resultado ==  true){
           
           //inicio do erro 
             
             txtCodigo_Fornecedor.setText(produto.getCodigo_fornecedor());
            txtNome_Produto.setText(produto.getNome_produto());                  // unica variavel que funcionou, pelo fato de ser string
             txtQuantidade_Estoque.setText(produto.getQuantidade_estoque()+"");
            
             txtValor_Custo.setText.setText(produto.getValor_custo()));
             txtValor_Venda.setText(Double.valueOf(produto.getValor_venda()));
         
             
            //fim do erro
    
             btnAlteracao.setEnabled(true);
             btnExclusao.setEnabled(true);
             txtCodigo.setEnabled(false);
             btnInclusao.setEnabled(false);
    
         }
         else{
             JOptionPane.showMessageDialog(null, "Produto não foi encontrado.");
         }
    
     }
     catch (Exception e){
         JOptionPane.showMessageDialog(null, "Ocorreu um erro:" + e.getMessage());
     }
    

    }

    private void txtCodigoActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
    }

    private void txtCodigo_FornecedorActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
    }

    private void txtNome_ProdutoActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
    }

    private void txtQuantidade_EstoqueActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
    }

    private void txtValor_CustoActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
    }

    private void txtValor_VendaActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
    }

    /**

    • @param args the command line arguments
      /
      public static void main(String args[]) {
      /
      Set the Nimbus look and feel /
      //
      /
      If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.

      • For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
        */
        try {
        for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
        if (“Nimbus”.equals(info.getName())) {
        javax.swing.UIManager.setLookAndFeel(info.getClassName());
        break;
        }
        }
        } catch (ClassNotFoundException ex) {
        java.util.logging.Logger.getLogger(FrmProduto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
        java.util.logging.Logger.getLogger(FrmProduto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
        java.util.logging.Logger.getLogger(FrmProduto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(FrmProduto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //

      /* Create and display the form */
      java.awt.EventQueue.invokeLater(new Runnable() {
      public void run() {
      new FrmProduto().setVisible(true);
      }
      });
      }
      // Variables declaration - do not modify
      private javax.swing.JButton btnAlteracao;
      private javax.swing.JButton btnConsulta;
      private javax.swing.JButton btnExclusao;
      private javax.swing.JButton btnInclusao;
      private javax.swing.JLabel jLabel1;
      private javax.swing.JLabel jLabel13;
      private javax.swing.JLabel jLabel2;
      private javax.swing.JLabel jLabel3;
      private javax.swing.JLabel jLabel4;
      private javax.swing.JLabel jLabel5;
      private javax.swing.JPanel jPanel1;
      private javax.swing.JPanel jPanel2;
      private javax.swing.JTextField txtCodigo;
      private javax.swing.JTextField txtCodigo_Fornecedor;
      private javax.swing.JTextField txtNome_Produto;
      private javax.swing.JTextField txtQuantidade_Estoque;
      private javax.swing.JTextField txtValor_Custo;
      private javax.swing.JTextField txtValor_Venda;
      // End of variables declaration
      }[/code]

Como eu já previa…

Use o seguinte:

txtCodigo_Fornecedor.setText(""+produto.getCodigo_fornecedor());  
txtNome_Produto.setText(produto.getNome_produto());            
txtQuantidade_Estoque.setText(""+produto.getQuantidade_estoque());  
               
txtValor_Custo.setText.setText(""+produto.getValor_custo()));  
txtValor_Venda.setText(""+produto.getValor_venda()); 

Ao colocar (""+) nas linhas onde o objeto retorna um inteiro, eu “transformei” esse valor numérico para um String, pois ao concatenar uma String vazia, todo o conjunto vira uma String. Não sei por que o setText() de um JTextField só funciona assim com valores numéricos, eu sei que ele espera uma String, mas se for pensar, qualquer coisa é uma String…

Nos diga se deu certo :slight_smile:

[quote=Matheus terra]Como eu já previa…

Use o seguinte:

txtCodigo_Fornecedor.setText(""+produto.getCodigo_fornecedor());  
txtNome_Produto.setText(produto.getNome_produto());            
txtQuantidade_Estoque.setText(""+produto.getQuantidade_estoque());  
               
txtValor_Custo.setText.setText(""+produto.getValor_custo()));  
txtValor_Venda.setText(""+produto.getValor_venda()); 

Ao colocar (""+) nas linhas onde o objeto retorna um inteiro, eu “transformei” esse valor numérico para um String, pois ao concatenar uma String vazia, todo o conjunto vira uma String. Não sei por que o setText() de um JTextField só funciona assim com valores numéricos, eu sei que ele espera uma String, mas se for pensar, qualquer coisa é uma String…

Nos diga se deu certo :)[/quote]

parece que deu certo, o erro nao apresenta mais na linha, porem quando vou executar o formulario consigo incluir, mas lista, alterar ou excluir, nao consigo da um erro que pede para criar um construtor na classe modelo

o erro da nessa parte, quando vou criar um produto

Produto produto = new Produto(Integer.parseInt(txtCodigo.getText()));

Na classe Produto você tem um construtor que espera um parâmetro inteiro?

olha como ficou minha classe produto:

[code]/*

  • To change this template, choose Tools | Templates
  • and open the template in the editor.
    */
    package Modelo;

import java.util.ArrayList;

import java.util.List;
/**
*

  • @author Atila
    */
    public class Produto extends Cliente {
    private int codigo_fornecedor;
    private String nome_produto;
    private int quantidade_estoque;
    private double valor_custo;
    private double valor_venda;

    public Produto() {
    }

    public int getCodigo_fornecedor() {
    return codigo_fornecedor;
    }

    public void setCodigo_fornecedor(int codigo_fornecedor) {
    this.codigo_fornecedor = codigo_fornecedor;
    }

    public String getNome_produto() {
    return nome_produto;
    }

    public void setNome_produto(String nome_produto) {
    this.nome_produto = nome_produto;
    }

    public int getQuantidade_estoque() {
    return quantidade_estoque;
    }

    public void setQuantidade_estoque(int quantidade_estoque) {
    this.quantidade_estoque = quantidade_estoque;
    }

    public double getValor_custo() {
    return valor_custo;
    }

    public void setValor_custo(double valor_custo) {
    this.valor_custo = valor_custo;
    }

    public double getValor_venda() {
    return valor_venda;
    }

    public void setValor_venda(double valor_venda) {
    this.valor_venda = valor_venda;
    }

}
[/code]

Na linha que está apresentando o erro, você está querendo instanciar um objeto com um construtor que não existe.

Deixa só assim:

Produto produto = new Produto();

[quote=Matheus terra]Na linha que está apresentando o erro, você está querendo instanciar um objeto com um construtor que não existe.

Deixa só assim:

Produto produto = new Produto();

opa, resolveu, porem na execucao do programa ele nao consegue puxar o codigo nessa parte, ele da a mensagem de nao encontrado:

[code]
try{
codigo = Integer.parseInt(txtCodigo.getText());
}
catch (Exception e){
JOptionPane.showMessageDialog(null, “Você precisa digitar um código.”);
return;
}
Produto produto = new Produto();
ProdutoDAO dao = new ProdutoDAO();
boolean resultado = dao.consultar(produto);
if (resultado == true){

            txtCodigo_Fornecedor.setText(""+produto.getCodigo_fornecedor());
           txtNome_Produto.setText(""+produto.getNome_produto());
            txtQuantidade_Estoque.setText(""+produto.getQuantidade_estoque());
           
            txtValor_Custo.setText(""+produto.getValor_custo());
            txtValor_Venda.setText(""+produto.getValor_venda());
        
            
           

            btnAlteracao.setEnabled(true);
            btnExclusao.setEnabled(true);
            txtCodigo.setEnabled(false);
            btnInclusao.setEnabled(false);

        }
        else{
            JOptionPane.showMessageDialog(null, "Produto não foi encontrado.");
        }[/code]

Na linha 10 você tem que passar o codigo, e não o produto, certo? Por que você está passando um objeto produto que você acabou de instanciar e está vazio…

e o produto mesmo, o codigo da erro, sera que tem como voce dar uma olhada no projeto ?, eu hospedo ele em algum lugar o te envio por emai,l por favor?

Eu até poderia mas agora não dá, estou no trabalho. Tenta colocar um break point no try e vai vendo os valores que vai passando, pois você está passando um objeto vazio como parâmetro, você deveria fazer com que essa consulta do produto serja feita pelo código, ai teria que alterar o método de consulta…

o icncluir esta funcionando, so que

quando vou alterar da o seguinte erro: for input string: “”
quando vou consultar o erro que da e: Column ‘Nome’ not found
e quando vou excluir da o erro: for input string: “” tambem