Páginas
Download J Planet
Downloads Java
Fórum
Canal do YouTube
Página no Face
quarta-feira, 16 de janeiro de 2013
Tela de Cadastro com Várias Imagens
-->
Para este exemplo, criei um cadastro para coleção de moedas!
O programa utiliza banco de dados MySQL.
Clique aqui para baixar o código-fonte do programa.
Baixe o executável do programa aqui.
Veja como ficou a classe CadastroMoedaJPanel.java
/** * J Planet 1.3.4 - * http://ateoriadadesevolucao.blogspot.com/p/software-j-planet.html */ /* * CadastroMoedaJPanel.java * * Criado em 16/01/2013, 18:21:28 */ package colecaoMoedas; import java.awt.Color; import java.awt.Graphics; import javax.swing.ImageIcon; import javax.swing.JOptionPane; import javax.swing.border.Border; public class CadastroMoedaJPanel extends javax.swing.JPanel { private Moeda moeda; private GenericDAO dAO; private boolean editando = false; private ColecaoMoedasTeste colecaoMoedasTeste; private final int QTDE_FOTOS = 4; private ImageIcon[] fotos = new ImageIcon[QTDE_FOTOS]; private String[] caminhosFotos = new String[QTDE_FOTOS]; private int indiceFoto = 0; private Border bordaDestacada = javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 153, 51), 3); private Border bordaCinza = javax.swing.BorderFactory.createLineBorder(new java.awt.Color(153, 153, 153)); // Variables declaration - do not modify private javax.swing.JButton jButtonAnterior; private javax.swing.JButton jButtonEditar; private javax.swing.JButton jButtonExcluir; private javax.swing.JButton jButtonIncluirFoto; private javax.swing.JButton jButtonNovo; private javax.swing.JButton jButtonPrimeiro; private javax.swing.JButton jButtonProximo; private javax.swing.JButton jButtonSalvar; private javax.swing.JButton jButtonUltimo; private javax.swing.JButton jButtonVisualizarTudo; private javax.swing.JComboBox jComboBoxGramas; private javax.swing.JComboBox jComboBoxMm; private javax.swing.JComboBox jComboBoxPais; private javax.swing.JFormattedTextField jFormattedTextFieldCunhadaEm; private javax.swing.JFormattedTextField jFormattedTextFieldDiametro; private javax.swing.JFormattedTextField jFormattedTextFieldMoedaID; private javax.swing.JFormattedTextField jFormattedTextFieldPeso; private javax.swing.JFormattedTextField jFormattedTextFieldTiragem; private javax.swing.JLabel jLabelAcabamento; private javax.swing.JLabel jLabelCodigo; private javax.swing.JLabel jLabelComposicao; private javax.swing.JLabel jLabelCunhadaEm; private javax.swing.JLabel jLabelDenominacao; private javax.swing.JLabel jLabelDescricao; private javax.swing.JLabel jLabelDiametro; private javax.swing.JLabel jLabelMoedaID; private javax.swing.JLabel jLabelNome; private javax.swing.JLabel jLabelPais; private javax.swing.JLabel jLabelPeso; private javax.swing.JLabel jLabelSerie; private javax.swing.JLabel jLabelTiragem; private javax.swing.JLabel jLabelTituloCadastroMoeda; private javax.swing.JLabel jLabelValorFacial; private javax.swing.JLabel jLabelVariedadeDaBorda; private javax.swing.JPanel jPanelBotoes; private javax.swing.JPanel jPanelCapa; private javax.swing.JPanel jPanelFoto; private javax.swing.JPanel jPanelFoto1; private javax.swing.JPanel jPanelFoto2; private javax.swing.JPanel jPanelFoto3; private javax.swing.JPanel jPanelTitulo; private javax.swing.JScrollPane jScrollPaneDescricao; private javax.swing.JTextArea jTextAreaDescricao; private javax.swing.JTextField jTextFieldAcabamento; private javax.swing.JTextField jTextFieldCodigo; private javax.swing.JTextField jTextFieldComposicao; private javax.swing.JTextField jTextFieldDenominacao; private javax.swing.JTextField jTextFieldNome; private javax.swing.JTextField jTextFieldSerie; private javax.swing.JTextField jTextFieldValorFacial; private javax.swing.JTextField jTextFieldVariedadeDaBorda; // End of variables declaration /** * Creates new form CadastroMoedaJPanel */ public CadastroMoedaJPanel() { for (ImageIcon foto : fotos) { foto = null; } initComponents(); } // fim do construtor CadastroMoedaJPanel /** * 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() { java.awt.GridBagConstraints gridBagConstraints; jLabelMoedaID = new javax.swing.JLabel(); jFormattedTextFieldMoedaID = new javax.swing.JFormattedTextField(); jLabelCodigo = new javax.swing.JLabel(); jTextFieldCodigo = new javax.swing.JTextField(); jLabelNome = new javax.swing.JLabel(); jTextFieldNome = new javax.swing.JTextField(); jLabelPais = new javax.swing.JLabel(); jComboBoxPais = new javax.swing.JComboBox(); jLabelSerie = new javax.swing.JLabel(); jTextFieldSerie = new javax.swing.JTextField(); jLabelCunhadaEm = new javax.swing.JLabel(); jFormattedTextFieldCunhadaEm = new javax.swing.JFormattedTextField(); jLabelValorFacial = new javax.swing.JLabel(); jTextFieldValorFacial = new javax.swing.JTextField(); jLabelComposicao = new javax.swing.JLabel(); jTextFieldComposicao = new javax.swing.JTextField(); jLabelAcabamento = new javax.swing.JLabel(); jTextFieldAcabamento = new javax.swing.JTextField(); jLabelPeso = new javax.swing.JLabel(); jFormattedTextFieldPeso = new javax.swing.JFormattedTextField(); jComboBoxGramas = new javax.swing.JComboBox(); jLabelDiametro = new javax.swing.JLabel(); jFormattedTextFieldDiametro = new javax.swing.JFormattedTextField(); jComboBoxMm = new javax.swing.JComboBox(); jLabelDenominacao = new javax.swing.JLabel(); jTextFieldDenominacao = new javax.swing.JTextField(); jLabelTiragem = new javax.swing.JLabel(); jFormattedTextFieldTiragem = new javax.swing.JFormattedTextField(); jLabelVariedadeDaBorda = new javax.swing.JLabel(); jTextFieldVariedadeDaBorda = new javax.swing.JTextField(); jLabelDescricao = new javax.swing.JLabel(); jScrollPaneDescricao = new javax.swing.JScrollPane(); jTextAreaDescricao = new javax.swing.JTextArea(); jPanelFoto = new javax.swing.JPanel() { protected void paintComponent(Graphics g) { super.paintComponent(g); if (fotos[indiceFoto] != null) { int width; int height; if (fotos[indiceFoto].getIconHeight() > fotos[indiceFoto].getIconWidth()) { width = getHeight() * fotos[indiceFoto].getIconWidth() / fotos[indiceFoto].getIconHeight(); g.drawImage(fotos[indiceFoto].getImage(), 0, 0, width, getHeight(), this); } else { height = getWidth() * fotos[indiceFoto].getIconHeight() / fotos[indiceFoto].getIconWidth(); g.drawImage(fotos[indiceFoto].getImage(), 0, 0, getWidth(), height, this); } // fim do else } // fim do if externo } // fim do metodo paintComponent }; jPanelCapa = new javax.swing.JPanel() { protected void paintComponent(Graphics g) { super.paintComponent(g); if (fotos[0] != null) { g.drawImage(fotos[0].getImage(), 0, 0, getWidth(), getHeight(), this); } } // fim do metodo paintComponent }; jPanelFoto1 = new javax.swing.JPanel(){ protected void paintComponent(Graphics g) { super.paintComponent(g); if (fotos[1] != null) { g.drawImage(fotos[1].getImage(), 0, 0, getWidth(), getHeight(), this); } } // fim do metodo paintComponent }; jPanelFoto2 = new javax.swing.JPanel(){ protected void paintComponent(Graphics g) { super.paintComponent(g); if (fotos[2] != null) { g.drawImage(fotos[2].getImage(), 0, 0, getWidth(), getHeight(), this); } } // fim do metodo paintComponent }; jPanelFoto3 = new javax.swing.JPanel(){ protected void paintComponent(Graphics g) { super.paintComponent(g); if (fotos[3] != null) { g.drawImage(fotos[3].getImage(), 0, 0, getWidth(), getHeight(), this); } } // fim do metodo paintComponent }; jButtonIncluirFoto = new javax.swing.JButton(); jPanelTitulo = new javax.swing.JPanel(); jLabelTituloCadastroMoeda = new javax.swing.JLabel(); jButtonUltimo = new javax.swing.JButton(); jButtonProximo = new javax.swing.JButton(); jButtonAnterior = new javax.swing.JButton(); jButtonPrimeiro = new javax.swing.JButton(); jPanelBotoes = new javax.swing.JPanel(); jButtonNovo = new javax.swing.JButton(); jButtonSalvar = new javax.swing.JButton(); jButtonEditar = new javax.swing.JButton(); jButtonExcluir = new javax.swing.JButton(); jButtonVisualizarTudo = new javax.swing.JButton(); jLabelMoedaID.setText("Moeda ID:"); jFormattedTextFieldMoedaID.setColumns(5); jFormattedTextFieldMoedaID.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#0")))); jFormattedTextFieldMoedaID.setText("1"); jLabelCodigo.setText("Código:"); jTextFieldCodigo.setColumns(20); jLabelNome.setText("Nome:"); jTextFieldNome.setColumns(20); jLabelPais.setText("País:"); jComboBoxPais.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Afeganistão", "África do Sul", "Albânia", "Alemanha", "Andorra", "Angola", "Antígua e Barbuda", "Arábia Saudita", "Argélia", "Argentina", "Arménia", "Austrália", "Áustria", "Azerbaijão", "Bahamas", "Bahrein", "Bangladesh", "Barbados", "Bélgica", "Belize", "Benin", "Bielorrússia", "Birmânia", "Bolívia", "Bósnia e Herzegovina", "Botswana", "Brasil", "Brunei", "Bulgária", "Burkina Faso", "Burundi", "Butão", "Cabo Verde", "Camarões", "Camboja", "Canadá", "Cazaquistão", "Central Africano República", "Chade", "Chile", "China", "Chipre", "Colômbia", "Comores", "Coréia do Norte", "Coreia do Sul", "Costa do Marfim", "Costa Rica", "Croácia", "Cuba", "Dinamarca", "Djibouti", "Dominica", "Egito", "El Salvador", "Emirados Árabes Unidos", "Equador", "Eritreia", "Eslováquia", "Eslovénia", "Espanha", "Estados Federados da Micronésia", "Estados Unidos da América", "Estónia", "Etiópia", "Fiji", "Filipinas", "Finlândia", "França", "Gabão", "Gâmbia", "Gana", "Geórgia", "Grécia", "Grenada", "Guatemala", "Guiana", "Guiné", "Guiné Equatorial", "Guiné-Bissau", "Haiti", "Holanda", "Honduras", "Hungria", "Iémen", "Ilhas Marshall", "Ilhas Salomão", "Índia", "Indonésia", "Irão", "Iraque", "Irlanda", "Islândia", "Israel", "Itália", "Jamaica", "Japão", "Jordan", "Kiribati", "Kuwait", "Laos", "Lesoto", "Letónia", "Líbano", "Libéria", "Líbia", "Liechtenstein", "Lituânia", "Luxemburgo", "Macedónia", "Madagascar", "Malásia", "Malawi", "Maldivas", "Mali", "Malta", "Marrocos", "Maurícias", "Mauritânia", "México", "Moçambique", "Moldávia", "Mónaco", "Mongólia", "Montenegro", "Namíbia", "Nauru", "Nepal", "Nicarágua", "Níger", "Nigéria", "Noruega", "Nova Zelândia", "Omã", "Palau", "Panamá", "Papua Nova Guiné", "Paquistão", "Paraguai", "Peru", "Polónia", "Portugal", "Qatar", "Quénia", "Quirguistão", "Reino Unido", "República Checa", "República Democrática do Congo", "República do Congo", "República Dominicana", "Roménia", "Ruanda", "Rússia", "Samoa", "Santa Lúcia", "São Cristóvão e Nevis", "São Marino", "São Tomé e Príncipe", "São Vicente e Granadinas", "Senegal", "Serra Leoa", "Sérvia", "Seychelles", "Singapura", "Síria", "Somália", "Sri Lanka", "Suazilândia", "Sudão", "Suécia", "Suíça", "Suriname", "Tailândia", "Taiwan", "Tajiquistão", "Tanzânia", "Timor Leste", "Togo", "Tonga", "Trinidad e Tobago", "Tunísia", "Turquemenistão", "Turquia", "Tuvalu", "Ucrânia", "Uganda", "Uruguai", "Uzbequistão", "Vanuatu", "Venezuela", "Vietname", "Zâmbia", "Zimbabué" })); jComboBoxPais.setSelectedItem("Item 1"); jLabelSerie.setText("Série:"); jTextFieldSerie.setColumns(20); jLabelCunhadaEm.setText("Cunhada em:"); jFormattedTextFieldCunhadaEm.setColumns(4); jFormattedTextFieldCunhadaEm.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter(new java.text.SimpleDateFormat("yyyy")))); jLabelValorFacial.setText("Valor facial:"); jTextFieldValorFacial.setColumns(20); jLabelComposicao.setText("Composição:"); jTextFieldComposicao.setColumns(20); jLabelAcabamento.setText("Acabamento:"); jTextFieldAcabamento.setColumns(20); jLabelPeso.setText("Peso:"); jFormattedTextFieldPeso.setColumns(10); jFormattedTextFieldPeso.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#0.00")))); jComboBoxGramas.setEditable(true); jComboBoxGramas.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "gramas" })); jComboBoxGramas.setSelectedItem("gramas"); jLabelDiametro.setText("Diâmetro:"); jFormattedTextFieldDiametro.setColumns(10); jFormattedTextFieldDiametro.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#0.0")))); jComboBoxMm.setEditable(true); jComboBoxMm.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "mm" })); jComboBoxMm.setSelectedItem("mm"); jComboBoxMm.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jComboBoxMmActionPerformed(evt); } }); jLabelDenominacao.setText("Denominação:"); jTextFieldDenominacao.setColumns(20); jLabelTiragem.setText("Tiragem:"); jFormattedTextFieldTiragem.setColumns(10); jFormattedTextFieldTiragem.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#,##0")))); jLabelVariedadeDaBorda.setText("Variedade da borda:"); jTextFieldVariedadeDaBorda.setColumns(20); jLabelDescricao.setText("Descrição:"); jTextAreaDescricao.setColumns(20); jTextAreaDescricao.setRows(3); jScrollPaneDescricao.setViewportView(jTextAreaDescricao); jPanelFoto.setPreferredSize(new java.awt.Dimension(250, 250)); javax.swing.GroupLayout jPanelFotoLayout = new javax.swing.GroupLayout(jPanelFoto); jPanelFoto.setLayout(jPanelFotoLayout); jPanelFotoLayout.setHorizontalGroup( jPanelFotoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 250, Short.MAX_VALUE) ); jPanelFotoLayout.setVerticalGroup( jPanelFotoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 250, Short.MAX_VALUE) ); jPanelCapa.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(153, 153, 153))); jPanelCapa.setPreferredSize(new java.awt.Dimension(45, 45)); jPanelCapa.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { jPanelCapaMouseClicked(evt); } }); javax.swing.GroupLayout jPanelCapaLayout = new javax.swing.GroupLayout(jPanelCapa); jPanelCapa.setLayout(jPanelCapaLayout); jPanelCapaLayout.setHorizontalGroup( jPanelCapaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 43, Short.MAX_VALUE) ); jPanelCapaLayout.setVerticalGroup( jPanelCapaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 0, Short.MAX_VALUE) ); jPanelFoto1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(153, 153, 153))); jPanelFoto1.setPreferredSize(new java.awt.Dimension(45, 45)); jPanelFoto1.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { jPanelFoto1MouseClicked(evt); } }); javax.swing.GroupLayout jPanelFoto1Layout = new javax.swing.GroupLayout(jPanelFoto1); jPanelFoto1.setLayout(jPanelFoto1Layout); jPanelFoto1Layout.setHorizontalGroup( jPanelFoto1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 43, Short.MAX_VALUE) ); jPanelFoto1Layout.setVerticalGroup( jPanelFoto1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 0, Short.MAX_VALUE) ); jPanelFoto2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(153, 153, 153))); jPanelFoto2.setPreferredSize(new java.awt.Dimension(45, 45)); jPanelFoto2.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { jPanelFoto2MouseClicked(evt); } }); javax.swing.GroupLayout jPanelFoto2Layout = new javax.swing.GroupLayout(jPanelFoto2); jPanelFoto2.setLayout(jPanelFoto2Layout); jPanelFoto2Layout.setHorizontalGroup( jPanelFoto2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 43, Short.MAX_VALUE) ); jPanelFoto2Layout.setVerticalGroup( jPanelFoto2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 0, Short.MAX_VALUE) ); jPanelFoto3.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(153, 153, 153))); jPanelFoto3.setPreferredSize(new java.awt.Dimension(45, 45)); jPanelFoto3.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { jPanelFoto3MouseClicked(evt); } }); javax.swing.GroupLayout jPanelFoto3Layout = new javax.swing.GroupLayout(jPanelFoto3); jPanelFoto3.setLayout(jPanelFoto3Layout); jPanelFoto3Layout.setHorizontalGroup( jPanelFoto3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 43, Short.MAX_VALUE) ); jPanelFoto3Layout.setVerticalGroup( jPanelFoto3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 0, Short.MAX_VALUE) ); jButtonIncluirFoto.setIcon(new javax.swing.ImageIcon(getClass().getResource("/colecaoMoedas/img/images.png"))); // NOI18N jButtonIncluirFoto.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButtonIncluirFotoActionPerformed(evt); } }); jPanelTitulo.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)); jLabelTituloCadastroMoeda.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N jLabelTituloCadastroMoeda.setText("Cadastro Moeda"); jButtonUltimo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/colecaoMoedas/img/seta_direita_dupla.png"))); // NOI18N jButtonUltimo.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButtonUltimoActionPerformed(evt); } }); jButtonProximo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/colecaoMoedas/img/seta_direita.png"))); // NOI18N jButtonProximo.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButtonProximoActionPerformed(evt); } }); jButtonAnterior.setIcon(new javax.swing.ImageIcon(getClass().getResource("/colecaoMoedas/img/seta_esquerda.png"))); // NOI18N jButtonAnterior.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButtonAnteriorActionPerformed(evt); } }); jButtonPrimeiro.setIcon(new javax.swing.ImageIcon(getClass().getResource("/colecaoMoedas/img/seta_esquerda_dupla.png"))); // NOI18N jButtonPrimeiro.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButtonPrimeiroActionPerformed(evt); } }); jPanelBotoes.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)); jPanelBotoes.setLayout(new java.awt.GridBagLayout()); jButtonNovo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/colecaoMoedas/img/novo.png"))); // NOI18N jButtonNovo.setText("Novo"); jButtonNovo.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButtonNovoActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.weightx = 0.1; gridBagConstraints.insets = new java.awt.Insets(6, 10, 6, 0); jPanelBotoes.add(jButtonNovo, gridBagConstraints); jButtonSalvar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/colecaoMoedas/img/salvar.png"))); // NOI18N jButtonSalvar.setText("Salvar"); jButtonSalvar.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButtonSalvarActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.weightx = 0.1; gridBagConstraints.insets = new java.awt.Insets(6, 10, 6, 0); jPanelBotoes.add(jButtonSalvar, gridBagConstraints); jButtonEditar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/colecaoMoedas/img/editar.png"))); // NOI18N jButtonEditar.setText("Editar"); jButtonEditar.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButtonEditarActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.weightx = 0.1; gridBagConstraints.insets = new java.awt.Insets(6, 10, 6, 0); jPanelBotoes.add(jButtonEditar, gridBagConstraints); jButtonExcluir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/colecaoMoedas/img/excluir.png"))); // NOI18N jButtonExcluir.setText("Excluir"); jButtonExcluir.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButtonExcluirActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.weightx = 0.1; gridBagConstraints.insets = new java.awt.Insets(6, 10, 6, 0); jPanelBotoes.add(jButtonExcluir, gridBagConstraints); jButtonVisualizarTudo.setText("Visualizar Tudo"); jButtonVisualizarTudo.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButtonVisualizarTudoActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.weightx = 0.1; gridBagConstraints.insets = new java.awt.Insets(6, 6, 6, 10); jPanelBotoes.add(jButtonVisualizarTudo, gridBagConstraints); javax.swing.GroupLayout jPanelTituloLayout = new javax.swing.GroupLayout(jPanelTitulo); jPanelTitulo.setLayout(jPanelTituloLayout); jPanelTituloLayout.setHorizontalGroup( jPanelTituloLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelTituloLayout.createSequentialGroup() .addContainerGap() .addGroup(jPanelTituloLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jPanelBotoes, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(jPanelTituloLayout.createSequentialGroup() .addComponent(jLabelTituloCadastroMoeda) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jButtonPrimeiro) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButtonAnterior) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButtonProximo) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButtonUltimo))) .addContainerGap()) ); jPanelTituloLayout.setVerticalGroup( jPanelTituloLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanelTituloLayout.createSequentialGroup() .addContainerGap() .addGroup(jPanelTituloLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabelTituloCadastroMoeda) .addComponent(jButtonUltimo) .addComponent(jButtonProximo) .addComponent(jButtonAnterior) .addComponent(jButtonPrimeiro)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jPanelBotoes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jPanelFoto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(layout.createSequentialGroup() .addComponent(jPanelCapa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jPanelFoto1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jPanelFoto2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jPanelFoto3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButtonIncluirFoto, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGap(34, 34, 34) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabelValorFacial) .addComponent(jLabelComposicao) .addComponent(jLabelAcabamento) .addComponent(jLabelPeso) .addComponent(jLabelDenominacao) .addComponent(jLabelTiragem) .addComponent(jLabelVariedadeDaBorda) .addComponent(jLabelDescricao) .addComponent(jLabelDiametro) .addComponent(jLabelMoedaID) .addComponent(jLabelCodigo) .addComponent(jLabelNome) .addComponent(jLabelPais) .addComponent(jLabelSerie) .addComponent(jLabelCunhadaEm)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jFormattedTextFieldMoedaID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jFormattedTextFieldCunhadaEm, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jFormattedTextFieldTiragem, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) .addComponent(jFormattedTextFieldDiametro, javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jFormattedTextFieldPeso, javax.swing.GroupLayout.Alignment.LEADING)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jComboBoxGramas, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jComboBoxMm, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))) .addGap(71, 71, 71)) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jTextFieldCodigo) .addComponent(jTextFieldNome) .addComponent(jTextFieldSerie) .addComponent(jTextFieldComposicao) .addComponent(jTextFieldAcabamento) .addComponent(jTextFieldDenominacao) .addComponent(jTextFieldVariedadeDaBorda) .addComponent(jScrollPaneDescricao) .addComponent(jTextFieldValorFacial) .addComponent(jComboBoxPais, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addContainerGap()))) .addComponent(jPanelTitulo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(jPanelTitulo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jFormattedTextFieldMoedaID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabelMoedaID)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabelCodigo) .addComponent(jTextFieldCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabelNome) .addComponent(jTextFieldNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabelPais) .addComponent(jComboBoxPais, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabelSerie) .addComponent(jTextFieldSerie, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabelCunhadaEm) .addComponent(jFormattedTextFieldCunhadaEm, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabelValorFacial) .addComponent(jTextFieldValorFacial, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabelComposicao) .addComponent(jTextFieldComposicao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabelAcabamento) .addComponent(jTextFieldAcabamento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabelPeso) .addComponent(jFormattedTextFieldPeso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jComboBoxGramas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabelDiametro) .addComponent(jFormattedTextFieldDiametro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jComboBoxMm, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabelDenominacao) .addComponent(jTextFieldDenominacao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGroup(layout.createSequentialGroup() .addComponent(jPanelFoto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jPanelCapa, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jPanelFoto1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jPanelFoto2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jPanelFoto3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jButtonIncluirFoto, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabelTiragem) .addComponent(jFormattedTextFieldTiragem, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabelVariedadeDaBorda) .addComponent(jTextFieldVariedadeDaBorda, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabelDescricao) .addComponent(jScrollPaneDescricao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap(18, Short.MAX_VALUE)) ); }//
private void jPanelCapaMouseClicked(java.awt.event.MouseEvent evt) { // TODO add your handling code here: setBordaPaineis(0); jPanelFoto.repaint(); } private void jPanelFoto1MouseClicked(java.awt.event.MouseEvent evt) { // TODO add your handling code here: setBordaPaineis(1); jPanelFoto.repaint(); } private void jPanelFoto2MouseClicked(java.awt.event.MouseEvent evt) { // TODO add your handling code here: setBordaPaineis(2); jPanelFoto.repaint(); } private void jPanelFoto3MouseClicked(java.awt.event.MouseEvent evt) { // TODO add your handling code here: setBordaPaineis(3); jPanelFoto.repaint(); } private void jButtonIncluirFotoActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: ImagemJDialog imagemJDialog = new ImagemJDialog(colecaoMoedasTeste, true, caminhosFotos); imagemJDialog.setVisible(true); if (imagemJDialog.isOK()) { JOptionPane.showMessageDialog(colecaoMoedasTeste, "Clique em \"Salvar\" para armazenar as fotos!"); caminhosFotos = imagemJDialog.getCaminhosFotos(); for (int i = 0; i < caminhosFotos.length; i++) { if (caminhosFotos[i] == null) { fotos[i] = null; } else { fotos[i] = new ImageIcon(caminhosFotos[i]); } } alteraFoto(); } } private void jButtonUltimoActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: restauraCampos(4); } private void jButtonProximoActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: moeda = (Moeda) dAO.consultaSeta( jFormattedTextFieldMoedaID.getText(), 3); // consulta proximo registro if (moeda == null) { jButtonUltimo.setEnabled(false); jButtonProximo.setEnabled(false); } // fim do if else { setDados(moeda); habilitaCampos(false, false); habilitaBotoes(false); jButtonEditar.setEnabled(true); jButtonExcluir.setEnabled(true); } // fim do else jButtonPrimeiro.setEnabled(true); jButtonAnterior.setEnabled(true); } private void jButtonAnteriorActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: moeda = (Moeda) dAO.consultaSeta( jFormattedTextFieldMoedaID.getText(), 2); // consulta registro anterior if (moeda == null) { jButtonPrimeiro.setEnabled(false); jButtonAnterior.setEnabled(false); } // fim do if else { setDados(moeda); habilitaCampos(false, false); habilitaBotoes(false); jButtonEditar.setEnabled(true); jButtonExcluir.setEnabled(true); } // fim do else jButtonUltimo.setEnabled(true); jButtonProximo.setEnabled(true); } private void jButtonPrimeiroActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: restauraCampos(1); } private void jButtonNovoActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: colecaoMoedasTeste.consultaMoedaJPanel.limpaSelecao(); limpaCampos(); jButtonEditar.setEnabled(false); jButtonExcluir.setEnabled(false); editando = false; } private void jButtonSalvarActionPerformed(java.awt.event.ActionEvent evt) { moeda = getDados(); if (moeda != null) { if (editando) { dAO.altera(moeda); } else { dAO.adiciona(moeda); } jButtonEditar.setEnabled(true); jButtonExcluir.setEnabled(true); restauraCampos(1); colecaoMoedasTeste.consultaMoedaJPanel.atualizaTabela(null); editando = false; } // fim do if } private void jButtonEditarActionPerformed(java.awt.event.ActionEvent evt) { habilitaCampos(false, true); habilitaBotoes(true); jButtonEditar.setEnabled(true); jButtonExcluir.setEnabled(true); editando = true; } private void jButtonExcluirActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: int id = Integer.parseInt( jFormattedTextFieldMoedaID.getText()); int op = JOptionPane.showConfirmDialog(colecaoMoedasTeste, "Tem certeza que deseja excluir MoedaID " + id + "?"); if (op == JOptionPane.YES_OPTION) { dAO.remove(id); restauraCampos(1); colecaoMoedasTeste.consultaMoedaJPanel.atualizaTabela(null); editando = false; } } private void jButtonVisualizarTudoActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: colecaoMoedasTeste.exibeJInternalFrameConsultaMoeda(); } private void jComboBoxMmActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: } protected void setDados(Moeda moeda) { // labels dos campos de preenchimento obrigatorio jLabelMoedaID.setForeground(Color.BLACK); // jFormattedTextFieldMoedaID.setText("" + moeda.getMoedaID()); jTextFieldCodigo.setText(moeda.getCodigo()); jTextFieldNome.setText(moeda.getNome()); jComboBoxPais.setSelectedItem(moeda.getPais()); jTextFieldSerie.setText(moeda.getSerie()); jFormattedTextFieldCunhadaEm.setText(moeda.getCunhadaEm()); jTextFieldValorFacial.setText(moeda.getValorFacial()); jTextFieldComposicao.setText(moeda.getComposicao()); jTextFieldAcabamento.setText(moeda.getAcabamento()); jFormattedTextFieldPeso.setText(String.format("%.2f", moeda.getPeso())); jFormattedTextFieldDiametro.setText(String.format("%.2f", moeda.getDiametro())); jTextFieldDenominacao.setText(moeda.getDenominacao()); jFormattedTextFieldTiragem.setText("" + moeda.getTiragem()); jTextFieldVariedadeDaBorda.setText(moeda.getVariedadeDaBorda()); jTextAreaDescricao.setText(moeda.getDescricao()); caminhosFotos = moeda.getCaminhosFotos() == null ? (new String[QTDE_FOTOS]) : moeda.getCaminhosFotos(); setBordaPaineis(0); alteraFoto(); } // fim do metodo setDados protected Moeda getDados() { moeda = null; // destaca labels dos campos de preenchimento obrigatorio jLabelMoedaID.setForeground(Color.RED); boolean continua = true; RegraDeNegocio regraDeNegocio = new RegraDeNegocio(); try { regraDeNegocio.validaInteiro(jFormattedTextFieldMoedaID.getText().trim()); if (!editando && dAO.listaPorID(Integer.parseInt( jFormattedTextFieldMoedaID.getText())) != null) { System.out.println(jLabelMoedaID.getText() + " possui valor duplicado!"); JOptionPane.showMessageDialog(null, jLabelMoedaID.getText() + " possui valor duplicado!"); continua = false; } else { jLabelMoedaID.setForeground(Color.BLACK); } } catch (EmptyFiledException ex) { System.out.println(jLabelMoedaID.getText() + " deve ser preenchido!"); JOptionPane.showMessageDialog(null, jLabelMoedaID.getText() + " deve ser preenchido!"); } catch (NumberFormatException ex) { System.out.println(jLabelMoedaID.getText() + " possui valor incorreto!\n" + "Digite somente numeros inteiros."); JOptionPane.showMessageDialog(null, jLabelMoedaID.getText() + " possui valor incorreto!\n" + "Digite somente numeros inteiros."); continua = false; } // fim do catch if (continua) { moeda = new Moeda(); moeda.setMoedaID(Integer.parseInt( jFormattedTextFieldMoedaID.getText())); moeda.setCodigo(jTextFieldCodigo.getText()); moeda.setNome(jTextFieldNome.getText()); moeda.setPais("" + jComboBoxPais.getSelectedItem()); moeda.setSerie(jTextFieldSerie.getText()); moeda.setCunhadaEm(jFormattedTextFieldCunhadaEm.getText()); moeda.setValorFacial(jTextFieldValorFacial.getText()); moeda.setComposicao(jTextFieldComposicao.getText()); moeda.setAcabamento(jTextFieldAcabamento.getText()); try { moeda.setPeso(Double.parseDouble( jFormattedTextFieldPeso.getText().replace(",", "."))); } catch (NumberFormatException ex) { moeda.setPeso(0); } try { moeda.setDiametro(Double.parseDouble( jFormattedTextFieldDiametro.getText().replace(",", "."))); } catch (NumberFormatException ex) { moeda.setDiametro(0); } moeda.setDenominacao(jTextFieldDenominacao.getText()); try { moeda.setTiragem(Integer.parseInt( jFormattedTextFieldTiragem.getText().replace(".", ""))); } catch (NumberFormatException ex) { moeda.setTiragem(0); } moeda.setVariedadeDaBorda(jTextFieldVariedadeDaBorda.getText()); moeda.setDescricao(jTextAreaDescricao.getText()); moeda.setCaminhosFotos(caminhosFotos); } // fim do if continua return moeda; } // fim do metodo getDados public final void restauraCampos(int seta) { moeda = (Moeda) dAO.consultaSeta("", seta); if (moeda != null) { setDados(moeda); habilitaBotoes(false); jButtonEditar.setEnabled(true); jButtonExcluir.setEnabled(true); jButtonIncluirFoto.setEnabled(false); switch (seta) { case 1: jButtonPrimeiro.setEnabled(false); jButtonAnterior.setEnabled(false); jButtonUltimo.setEnabled(true); jButtonProximo.setEnabled(true); break; case 4: jButtonPrimeiro.setEnabled(true); jButtonAnterior.setEnabled(true); jButtonUltimo.setEnabled(false); jButtonProximo.setEnabled(false); break; } // fim do switch habilitaCampos(false, false); } // fim do if else { limpaCampos(); jButtonPrimeiro.setEnabled(false); jButtonAnterior.setEnabled(false); jButtonUltimo.setEnabled(false); jButtonProximo.setEnabled(false); } // fim do else } // fim do metodo restauraCampos protected void limpaCampos() { jFormattedTextFieldMoedaID.setText("" + dAO.consultaProximoID()); jTextFieldCodigo.setText(""); jTextFieldNome.setText(""); jComboBoxPais.setSelectedItem("Item 1"); jTextFieldSerie.setText(""); jFormattedTextFieldCunhadaEm.setText(""); jTextFieldValorFacial.setText(""); jTextFieldComposicao.setText(""); jTextFieldAcabamento.setText(""); jFormattedTextFieldPeso.setText("0,00"); jComboBoxGramas.setSelectedItem("gramas"); jFormattedTextFieldDiametro.setText("0,00"); jComboBoxMm.setSelectedItem("mm"); jTextFieldDenominacao.setText(""); jFormattedTextFieldTiragem.setText("0"); jTextFieldVariedadeDaBorda.setText(""); jTextAreaDescricao.setText(""); caminhosFotos[0] = null; caminhosFotos[1] = null; caminhosFotos[2] = null; caminhosFotos[3] = null; tiraBordaDestacada(); alteraFoto(); habilitaBotoes(true); jButtonEditar.setEnabled(false); jButtonExcluir.setEnabled(false); habilitaCampos(true, true); } // fim do metodo limpaCampos protected void habilitaCampos(boolean habilitadoID, boolean habilitado) { jFormattedTextFieldMoedaID.setEditable(habilitadoID); jTextFieldCodigo.setEditable(habilitado); jTextFieldNome.setEditable(habilitado); jComboBoxPais.setEnabled(habilitado); jTextFieldSerie.setEditable(habilitado); jFormattedTextFieldCunhadaEm.setEditable(habilitado); jTextFieldValorFacial.setEditable(habilitado); jTextFieldComposicao.setEditable(habilitado); jTextFieldAcabamento.setEditable(habilitado); jFormattedTextFieldPeso.setEditable(habilitado); jComboBoxGramas.setEnabled(habilitado); jFormattedTextFieldDiametro.setEditable(habilitado); jComboBoxMm.setEnabled(habilitado); jTextFieldDenominacao.setEditable(habilitado); jFormattedTextFieldTiragem.setEditable(habilitado); jTextFieldVariedadeDaBorda.setEditable(habilitado); jTextAreaDescricao.setEditable(habilitado); } // fim do metodo habilitaCampos private void habilitaBotoes(boolean habilitado) { jButtonSalvar.setEnabled(habilitado); jButtonIncluirFoto.setEnabled(habilitado); } // fim do metodo habilitaBotoes protected void editaRegistro(int id) { moeda = (Moeda) dAO.listaPorID(id); setDados(moeda); habilitaCampos(false, true); habilitaBotoes(true); jButtonEditar.setEnabled(true); jButtonExcluir.setEnabled(true); editando = true; } // fim do metodo editaRegistro protected void excluiRegistro(int id) { dAO.remove(id); editando = false; restauraCampos(1); } // fim do metodo excluiRegistro private void alteraFoto() { for (int i = 0; i < caminhosFotos.length; i++) { if (caminhosFotos[i] == null) { fotos[i] = null; } else { fotos[i] = new ImageIcon(caminhosFotos[i]); } } jPanelFoto.repaint(); jPanelCapa.repaint(); jPanelFoto1.repaint(); jPanelFoto2.repaint(); jPanelFoto3.repaint(); } // fim do medoto alteraFoto private void setBordaPaineis(int indice) { switch (indice) { case 0: if (caminhosFotos[0] != null) { indiceFoto = 0; tiraBordaDestacada(); jPanelCapa.setBorder(bordaDestacada); } break; case 1: if (caminhosFotos[1] != null) { indiceFoto = 1; tiraBordaDestacada(); jPanelFoto1.setBorder(bordaDestacada); } break; case 2: if (caminhosFotos[2] != null) { indiceFoto = 2; tiraBordaDestacada(); jPanelFoto2.setBorder(bordaDestacada); } break; case 3: if (caminhosFotos[3] != null) { indiceFoto = 3; tiraBordaDestacada(); jPanelFoto3.setBorder(bordaDestacada); } else { jPanelFoto3.setBorder(bordaCinza); } break; } // fim do switch } // fim do metodo setBordaPaineis private void tiraBordaDestacada() { jPanelCapa.setBorder(bordaCinza); jPanelFoto1.setBorder(bordaCinza); jPanelFoto2.setBorder(bordaCinza); jPanelFoto3.setBorder(bordaCinza); } protected void setFrame(ColecaoMoedasTeste frame) { colecaoMoedasTeste = frame; dAO = new MoedaDAOImp(); restauraCampos(1); } // fim do metodo setFrame } // fim da classe CadastroMoedaJPanel
Nenhum comentário:
Postar um comentário
Postagem mais recente
Postagem mais antiga
Página inicial
Assinar:
Postar comentários (Atom)
Nenhum comentário:
Postar um comentário