Ajuda com JAR

18 respostas
C

Pessoal boa noite, alguem pode me ajudar com um probleminha.

Criei meu arquivo JAR de um projeto, criou tudo certinho sem erro apenas com 2 notas nada de mais.
Porem ao executar o arquivo, ele abre normal roda bonitinho, mas tem 3 botões que não funciona, a função do botão é apenas chamar uma outra tela (view), só isso, mais clico e a tela não abre.
Já no net beans abre tudo certinho.

Alguém sabe o que é isso? ou eu que sou muito azarado e devo desistir da programação não é possível.

18 Respostas

R

Verifica se você usou algum tipo de caractere especial, coloca um JOptionPane pra mostrar os erros possíveis erros também.

Manda o código que vc colocou no botão

M

Da alguma exceção? Se sim, posta a stacktrace

C

Então segue os codigos ai para pagina principal na qual tem os botoes, estes botoes apenas chama as outras telas, e não cara não da exceção alguma clico no botao nada acontece, e alguns funciona e o codigo é o mesmo, não estou entendendo.

private void jmiSairActionPerformed(java.awt.event.ActionEvent evt) {                                        
    if (Msg.confirmar(this, "Deseja realmente sair?")) {
        dispose();
    } else {
        return;
    }
}                                       

private void jmiClientesActionPerformed(java.awt.event.ActionEvent evt) {                                            
    new ViewCliente().setVisible(true);
}                                           

private void jmiProdutosActionPerformed(java.awt.event.ActionEvent evt) {                                            
    new ViewProdutos().setVisible(true);
}                                           

private void jmiUsuariosActionPerformed(java.awt.event.ActionEvent evt) {                                            
    new ViewUsuario().setVisible(true);
}                                           

private void jbVendas1ActionPerformed(java.awt.event.ActionEvent evt) {                                          
    new ViewVendas().setVisible(true);
}                                         

private void jbUsuariosActionPerformed(java.awt.event.ActionEvent evt) {                                           
    new ViewUsuario().setVisible(true);
}                                          

private void jbPDVActionPerformed(java.awt.event.ActionEvent evt) {                                      
    new ViewPDV().setVisible(true);
}                                     

private void jbProdutosActionPerformed(java.awt.event.ActionEvent evt) {                                           
    new ViewProdutos().setVisible(true);
}                                          

private void jbClienteActionPerformed(java.awt.event.ActionEvent evt) {                                          
    new ViewCliente().setVisible(true);
}                                         

private void jbNotafActionPerformed(java.awt.event.ActionEvent evt) {                                        
    String url = "C:\\Vendas\\Emissor de Nota Fiscal Eletronica (NF-e) 3.10.lnk";
    ProcessBuilder p = new ProcessBuilder();
    p.command("cmd.exe", "/c", url);
    try {
        p.start();
    } catch (IOException ex) {
        Logger.getLogger(ViewPrincipal.class.getName()).log(Level.SEVERE, null, ex);
    }
}                                       

private void formWindowClosing(java.awt.event.WindowEvent evt) {                                   
    if (Msg.confirmar(this, "Deseja realmente sair?")) {
        dispose();
    } else {
        return;
    }
}
C

Ao construir o arquivo JAR da a mensagem abaixo. as notas ficam em vermelho sera que não é apenas nota e sim erro?

ant -f C:\Users\cleit\Desktop\Vendas -Dnb.internal.action.name=rebuild clean jar
init:
deps-clean:
Updating property file: C:\Users\cleit\Desktop\Vendas\build\built-clean.properties
Deleting directory C:\Users\cleit\Desktop\Vendas\build
clean:
init:
deps-jar:
Created dir: C:\Users\cleit\Desktop\Vendas\build
Updating property file: C:\Users\cleit\Desktop\Vendas\build\built-jar.properties
Created dir: C:\Users\cleit\Desktop\Vendas\build\classes
Created dir: C:\Users\cleit\Desktop\Vendas\build\empty
Created dir: C:\Users\cleit\Desktop\Vendas\build\generated-sources\ap-source-output
Compiling 40 source files to C:\Users\cleit\Desktop\Vendas\build\classes
Note: C:\Users\cleit\Desktop\Vendas\src\view\ViewUsuario.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Copying 40 files to C:\Users\cleit\Desktop\Vendas\build\classes
compile:
Created dir: C:\Users\cleit\Desktop\Vendas\dist
Copying 1 file to C:\Users\cleit\Desktop\Vendas\build
Copy libraries to C:\Users\cleit\Desktop\Vendas\dist\lib.
Building jar: C:\Users\cleit\Desktop\Vendas\dist\Vendas.jar
To run this application from the command line without Ant, try:
java -jar “C:\Users\cleit\Desktop\Vendas\dist\Vendas.jar”

R

Não, são só avisos.

Qual botão não tá pegando?

C

O botao vendas, produtos e pdv, todo os outros funcionam, estranho de mais isso, nunca vi.

R

Hmmmm, esses três formulários são conectados com o banco de dados ou chamam algum método? Por exemplo:

public Recados(String porteiro) {
    nomePorteiro = porteiro;
    initComponents();
    preencherCombo();
    preencherCombo2();
    setIcon();
}
C

chaman metodo sim segue codigo fonte dos metodos.

*/
package view;

import Controller.ControllerProdutos;

import Model.ModelProdutos;

import java.util.ArrayList;

import javax.swing.JOptionPane;

import javax.swing.RowFilter;

import javax.swing.table.DefaultTableModel;

import javax.swing.table.TableModel;

import javax.swing.table.TableRowSorter;

import util.Formatador;

/**
*

  • @author cleit
    */
    public class ViewProdutos extends javax.swing.JFrame {

    ArrayList listaModelProdutos = new ArrayList<>();
    
    ControllerProdutos controllerProdutos = new ControllerProdutos();
    
    ModelProdutos modelProdutos = new ModelProdutos();
    
    Formatador formatador = new Formatador();
    
    String salvarAlterar;
    

    /**

    • Creates new form ViewProdutos
      */
      public ViewProdutos() {
      initComponents();
      carregarProdutos();
      setLocationRelativeTo(null);
      habilitarDesabilitarCampos(false);
      }

    /**

    • 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() {
      
      jPanel1 = new javax.swing.JPanel();
      
      jLabel1 = new javax.swing.JLabel();
      
      jtfCodigo = new javax.swing.JTextField();
      
      jtfNome = new javax.swing.JTextField();
      
      jLabel2 = new javax.swing.JLabel();
      
      jLabel3 = new javax.swing.JLabel();
      
      jLabel4 = new javax.swing.JLabel();
      
      jLabel5 = new javax.swing.JLabel();
      
      jtfPesquisar = new javax.swing.JTextField();
      
      jbProcurar = new javax.swing.JButton();
      
      jScrollPane1 = new javax.swing.JScrollPane();
      
      jtableProdutos = new javax.swing.JTable();
      
      jbNovo = new javax.swing.JButton();
      
      jbAlterar = new javax.swing.JButton();
      
      jbCancelar = new javax.swing.JButton();
      
      jbExcluir = new javax.swing.JButton();
      
      jbSalvar = new javax.swing.JButton();
      
      jtfEstoque = new javax.swing.JFormattedTextField();
      
      jtfValor = new javax.swing.JFormattedTextField();
      
      jbRelatorio = new javax.swing.JButton();
      
      jMenuBar1 = new javax.swing.JMenuBar();
      
      jMenu1 = new javax.swing.JMenu();
      
      jMenuItem1 = new javax.swing.JMenuItem();
      

      setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
      setTitle(“Produtos”);

      jLabel1.setText(“Código:”);

      jtfCodigo.setEnabled(false);

      jLabel2.setText(“Descrição do Produto:”);

      jLabel3.setText(“Estoque:”);

      jLabel4.setText(“ValorR$:”);

      jLabel5.setText(“Pesquisar”);

      jtfPesquisar.addActionListener(new java.awt.event.ActionListener() {
      
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      
      jtfPesquisarActionPerformed(evt);
      
      }
      
      });
      
      jbProcurar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/18 x 18/procurar.png"))); // NOI18N
      
      jbProcurar.setText(Procurar);
      
      jbProcurar.addActionListener(new java.awt.event.ActionListener() {
      
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      
      jbProcurarActionPerformed(evt);
      
      }
      
      });
      

      jtableProdutos.setModel(new javax.swing.table.DefaultTableModel(
      new Object [][] {

      },
       new String [] {
           "Codigo", "Descrição do Produto", "Estoque", "Valor R$"
       }
      
      ) {
      
      boolean[] canEdit = new boolean [] {
      
      true, false, true, true
      
      };
      
      public boolean isCellEditable(int rowIndex, int columnIndex) {
           return canEdit [columnIndex];
       }
      
      });
      
      jScrollPane1.setViewportView(jtableProdutos);
      
      if (jtableProdutos.getColumnModel().getColumnCount() > 0) {
      
      jtableProdutos.getColumnModel().getColumn(0).setMinWidth(60);
      
      jtableProdutos.getColumnModel().getColumn(0).setPreferredWidth(60);
      
      jtableProdutos.getColumnModel().getColumn(0).setMaxWidth(60);
      
      jtableProdutos.getColumnModel().getColumn(2).setMinWidth(90);
      
      jtableProdutos.getColumnModel().getColumn(2).setPreferredWidth(90);
      
      jtableProdutos.getColumnModel().getColumn(2).setMaxWidth(90);
      
      jtableProdutos.getColumnModel().getColumn(3).setMinWidth(90);
      
      jtableProdutos.getColumnModel().getColumn(3).setPreferredWidth(90);
      
      jtableProdutos.getColumnModel().getColumn(3).setMaxWidth(90);
      
      }
      
      jbNovo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/18 x 18/novo.png"))); // NOI18N
      
      jbNovo.setText(Novo);
      
      jbNovo.addActionListener(new java.awt.event.ActionListener() {
      
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      
      jbNovoActionPerformed(evt);
      
      }
      
      });
      
      jbAlterar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/18 x 18/editar.png"))); // NOI18N
      
      jbAlterar.setText(Alterar);
      
      jbAlterar.addActionListener(new java.awt.event.ActionListener() {
      
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      
      jbAlterarActionPerformed(evt);
      
      }
      
      });
      
      jbCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/18 x 18/cancelar.png"))); // NOI18N
      
      jbCancelar.setText(Cancelar);
      
      jbCancelar.addActionListener(new java.awt.event.ActionListener() {
      
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      
      jbCancelarActionPerformed(evt);
      
      }
      
      });
      
      jbExcluir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/18 x 18/excluir.png"))); // NOI18N
      
      jbExcluir.setText(Excluir);
      
      jbExcluir.addActionListener(new java.awt.event.ActionListener() {
      
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      
      jbExcluirActionPerformed(evt);
      
      }
      
      });
      
      jbSalvar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/18 x 18/salvar.png"))); // NOI18N
      
      jbSalvar.setText(Salvar);
      
      jbSalvar.addActionListener(new java.awt.event.ActionListener() {
      
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      
      jbSalvarActionPerformed(evt);
      
      }
      
      });
      

      jtfEstoque.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#0"))));

      jtfValor.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#,##0.00"))));

      jbRelatorio.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/18 x 18/impressao.png"))); // NOI18N
      
      jbRelatorio.setText(Relatório);
      
      jbRelatorio.addActionListener(new java.awt.event.ActionListener() {
      
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      
      jbRelatorioActionPerformed(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()
      
      .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      
      .addComponent(jScrollPane1)
      
      .addGroup(jPanel1Layout.createSequentialGroup()
      
      .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      
      .addComponent(jtfCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
      
      .addComponent(jLabel1))
      
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
      
      .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      
      .addGroup(jPanel1Layout.createSequentialGroup()
      
      .addComponent(jLabel2)
      
      .addGap(0, 0, Short.MAX_VALUE))
      
      .addComponent(jtfNome)))
      
      .addGroup(jPanel1Layout.createSequentialGroup()
      
      .addComponent(jLabel5)
      
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
      
      .addComponent(jtfPesquisar, javax.swing.GroupLayout.PREFERRED_SIZE, 480, javax.swing.GroupLayout.PREFERRED_SIZE)
      
      .addGap(18, 18, 18)
      
      .addComponent(jbProcurar, javax.swing.GroupLayout.DEFAULT_SIZE, 112, Short.MAX_VALUE))
      
      .addGroup(jPanel1Layout.createSequentialGroup()
      
      .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      
      .addComponent(jLabel3)
      
      .addComponent(jtfEstoque, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))
      
      .addGap(18, 18, 18)
      
      .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      
      .addComponent(jLabel4)
      
      .addComponent(jtfValor, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))
      
      .addGap(0, 0, Short.MAX_VALUE))
      
      .addGroup(jPanel1Layout.createSequentialGroup()
      
      .addComponent(jbNovo)
      
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
      
      .addComponent(jbAlterar)
      
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
      
      .addComponent(jbCancelar)
      
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
      
      .addComponent(jbExcluir)
      
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
      
      .addComponent(jbRelatorio)
      
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
      
      .addComponent(jbSalvar)))
      
      .addContainerGap())
      
      );
      
      jPanel1Layout.setVerticalGroup(
      
      jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      
      .addGroup(jPanel1Layout.createSequentialGroup()
      
      .addContainerGap()
      
      .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
      
      .addComponent(jLabel1)
      
      .addComponent(jLabel2))
      
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
      
      .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
      
      .addComponent(jtfCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
      
      .addComponent(jtfNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
      
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
      
      .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
      
      .addComponent(jLabel3)
      
      .addComponent(jLabel4))
      
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
      
      .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
      
      .addComponent(jtfEstoque, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
      
      .addComponent(jtfValor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
      
      .addGap(18, 18, 18)
      
      .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
      
      .addComponent(jLabel5)
      
      .addComponent(jtfPesquisar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
      
      .addComponent(jbProcurar))
      
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
      
      .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 329, Short.MAX_VALUE)
      
      .addGap(18, 18, 18)
      
      .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
      
      .addComponent(jbNovo)
      
      .addComponent(jbAlterar)
      
      .addComponent(jbCancelar)
      
      .addComponent(jbExcluir)
      
      .addComponent(jbSalvar)
      
      .addComponent(jbRelatorio))
      
      .addContainerGap())
      
      );
      

      jMenu1.setText(“Arquivo”);

      jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ESCAPE, 0));
      
      jMenuItem1.setText(Fechar);
      
      jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
      
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      
      jMenuItem1ActionPerformed(evt);
      
      }
      
      });
      
      jMenu1.add(jMenuItem1);
      

      jMenuBar1.add(jMenu1);

      setJMenuBar(jMenuBar1);

      javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
      
      getContentPane().setLayout(layout);
      
      layout.setHorizontalGroup(
      
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      
      .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
      
      );
      
      layout.setVerticalGroup(
      
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      
      .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
      
      );
      

      pack();
      }//

    private void jbSalvarActionPerformed(java.awt.event.ActionEvent evt) {
    
    if (salvarAlterar.equals(salvar)) {
    
    this.salvarProduto();
    
    } else if (salvarAlterar.equals(alterar)) {
    
    this.alterarProduto();
    
    }
    
    }
    
    private void jbExcluirActionPerformed(java.awt.event.ActionEvent evt) {
    
    // TODO add your handling code here:
    
    int linha = jtableProdutos.getSelectedRow();
    
    int codigoProduto = (int) jtableProdutos.getValueAt(linha, 0);
    
    if (controllerProdutos.excluirProdutocontroller(codigoProduto)) {
    
    JOptionPane.showMessageDialog(this, Produto excluido com sucesso!, PARABENS, JOptionPane.WARNING_MESSAGE);
    
    carregarProdutos();
    
    habilitarDesabilitarCampos(false);
    
    } else {
    
    JOptionPane.showMessageDialog(this, Erro Produto não excluido!, ERRO, JOptionPane.ERROR_MESSAGE);
    
    }
    
    }
    
    private void jbNovoActionPerformed(java.awt.event.ActionEvent evt) {
    
    // TODO add your handling code here:
    
    habilitarDesabilitarCampos(true);
    
    salvarAlterar = salvar;
    
    }
    
    private void jbCancelarActionPerformed(java.awt.event.ActionEvent evt) {
    
    // TODO add your handling code here:
    
    habilitarDesabilitarCampos(false);
    
    limparCampos();
    
    }
    
    private void jbAlterarActionPerformed(java.awt.event.ActionEvent evt) {
    
    // TODO add your handling code here:
    
    salvarAlterar = alterar;
    
    habilitarDesabilitarCampos(true);
    
    int linha = this.jtableProdutos.getSelectedRow();
    
    try {
    
    int codigoProduto = (int) this.jtableProdutos.getValueAt(linha, 0);
    
    modelProdutos = controllerProdutos.retornarProdutoController(codigoProduto);
         this.jtfCodigo.setText(String.valueOf(modelProdutos.getIdProdutos()));
         this.jtfNome.setText(modelProdutos.getProNome());
         this.jtfEstoque.setText(String.valueOf(modelProdutos.getProEstoque()));
         this.jtfValor.setText(String.valueOf(modelProdutos.getProValor()));
     } catch (Exception e) {
         JOptionPane.showMessageDialog(this, "Código invalido ou nenhum registro selecionado!", "ERRO", JOptionPane.ERROR_MESSAGE);
     }
    

    }

    private void jbProcurarActionPerformed(java.awt.event.ActionEvent evt) {
    
    // TODO add your handling code here:
    
    entrar();
    
    }
    
    private void jbRelatorioActionPerformed(java.awt.event.ActionEvent evt) {
    
    // TODO add your handling code here:
    
    final ViewAguarde carregando = new ViewAguarde();
    
    carregando.setVisible(true);
    
    Thread t = new Thread() {
    
    public void run() {
             try {
                 controllerProdutos.relatorioProdutosDAO();
                 carregando.dispose();
             } catch (Exception e) {
                 JOptionPane.showMessageDialog(null, "Erro  ao gerar relatorio!", "ERRO", JOptionPane.ERROR_MESSAGE);
             }
    
         }
     };
     t.start();
    

    }

    private void jtfPesquisarActionPerformed(java.awt.event.ActionEvent evt) {
    
    // TODO add your handling code here:
    
    entrar();
    
    }
    
    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {
    
    // TODO add your handling code here:
    
    dispose();
    
    }
    

    /**

    • @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(ViewProdutos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
        java.util.logging.Logger.getLogger(ViewProdutos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
        java.util.logging.Logger.getLogger(ViewProdutos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(ViewProdutos.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 ViewProdutos().setVisible(true);
      
      }
      
      });
      
      }
      
    private void entrar() {
    
    DefaultTableModel modelo = (DefaultTableModel) jtableProdutos.getModel();
    
    final TableRowSorter classificador = new TableRowSorter<>(modelo);
    
    this.jtableProdutos.setRowSorter(classificador);
    
    String texto = jtfPesquisar.getText();
    
    classificador.setRowFilter(RowFilter.regexFilter(texto, 1));
    
    }
    
    private void salvarProduto() {
    
    //salva novo produto
    
    modelProdutos.setProNome(this.jtfNome.getText());
    
    modelProdutos.setProEstoque(Integer.parseInt(this.jtfEstoque.getText()));
    
    modelProdutos.setProValor(formatador.converterVirgulaParaPonto(this.jtfValor.getText()));
    
    if (controllerProdutos.salvarProdutoController(modelProdutos) > 0) {
    
    JOptionPane.showMessageDialog(this, Produto Cadastrado com sucesso!, PARABENS, JOptionPane.WARNING_MESSAGE);
    
    carregarProdutos();
    
    limparCampos();
    
    habilitarDesabilitarCampos(false);
    
    } else {
    
    JOptionPane.showMessageDialog(this, Erro Produto não cadastrado!, ERRO, JOptionPane.ERROR_MESSAGE);
    
    }
    
    }
    
    private void alterarProduto() {
    
    //altera produto
    
    modelProdutos.setProNome(this.jtfNome.getText());
    
    modelProdutos.setProEstoque(Integer.parseInt(this.jtfEstoque.getText()));
    
    modelProdutos.setProValor(formatador.converterVirgulaParaPonto(this.jtfValor.getText()));
    
    if (controllerProdutos.alterarProdutoController(modelProdutos)) {
    
    JOptionPane.showMessageDialog(this, Produto Alterado com sucesso!, PARABENS, JOptionPane.WARNING_MESSAGE);
    
    carregarProdutos();
    
    limparCampos();
    
    habilitarDesabilitarCampos(false);
    
    } else {
    
    JOptionPane.showMessageDialog(this, Erro Produto não Alterado!, ERRO, JOptionPane.ERROR_MESSAGE);
    
    }
    
    }
    
    private void habilitarDesabilitarCampos(boolean condicao) {
    
    jtfNome.setEnabled(condicao);
    
    jtfEstoque.setEnabled(condicao);
    
    jtfValor.setEnabled(condicao);
    
    jbSalvar.setEnabled(condicao);
    

    }

    private void limparCampos() {
    
    jtfNome.setText("");
    
    jtfEstoque.setText("");
    
    jtfValor.setText("");
    
    }
    
    private void carregarProdutos() {
    
    listaModelProdutos = controllerProdutos.retornarListaProdutosController();
    
    DefaultTableModel modelo = (DefaultTableModel) jtableProdutos.getModel();
    
    modelo.setNumRows(0);
    
    //inserir produtos na tabela
    
    int cont = listaModelProdutos.size();
    
    for (int i = 0; i < cont; i++) {
    
    modelo.addRow(new Object[]{
    
    listaModelProdutos.get(i).getIdProdutos(),
    
    listaModelProdutos.get(i).getProNome(),
    
    listaModelProdutos.get(i).getProEstoque(),
    
    listaModelProdutos.get(i).getProValor()
    
    });
    
    }
    
    }
    
R

Faz o seguinte então, deixa só o initComponents();

Exemplo:

public ViewProdutos() {
initComponents();
//carregarProdutos();
//setLocationRelativeTo(null);
//habilitarDesabilitarCampos(false);
}

Quando for mandar o código aqui, aperta no botão </>, depois das aspas, pra ficar tudo formatado

C

A obrigado farei isso.

Então deixando apenas i init como falou, não carrega a tabela.

R

Sim, você tirou todos os métodos. Se o formulário abrir, você saberá que o problema está nos métodos e não nos botões.

C

Fiz o teste, e continua o mesmo, criei um outro projeto copiei os dados, e este projeto teste não executa o JAR, nossa estou entendendo mais nada.

R

Tem como salvar o projeto em algum lugar pra eu ver?

C

tem sim este projeto é propio posso te mandar sem problema, como vc acha melhor eu te enviar?
Agradeço se puder me dar esta força.

R

Manda pro mega, media fire, só me manda o link depois.

C

Segue o link

https://mega.nz/fm/JnYlCS6Z

R

Não é esse link não. Clica no arquivo com o botão direito e depos “Administrar Link”, aí você manda

C

foi mal Abner copiei o link errado mesmo, segue o correto

https://mega.nz/#F!wyRRFYDR!lSY-AgFTbf5Nh6xnqQzgyA

Criado 17 de julho de 2018
Ultima resposta 18 de jul. de 2018
Respostas 18
Participantes 3