Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package jschool.gui;
- import java.util.ArrayList;
- import javax.swing.DefaultComboBoxModel;
- import jschool.dao.CidadeDAO;
- import jschool.dao.InstituicaoDAO;
- import jschool.dao.EstadoDAO;
- import jschool.entidade.Cidade;
- import jschool.entidade.Estado;
- import jschool.entidade.IEntidade;
- import jschool.entidade.Instituicao;
- import jschool.infra.Formatador;
- import jschool.infra.Mensagem;
- /**
- *
- * @author andre
- */
- public class JIFrameInstituicaoEnsino extends javax.swing.JInternalFrame {
- /**
- * Creates new form JIFrameInstituicaoEnsino
- */
- public JIFrameInstituicaoEnsino() {
- initComponents();
- carregarEstados();
- carregarInstituicao();
- }
- private void carregarInstituicao() {
- Instituicao instituicao = (Instituicao) new InstituicaoDAO().consultarId(0);
- if (instituicao != null) {
- jtfId.setText(Integer.toString(instituicao.getId()));
- jtfNome.setText(instituicao.getNome());
- jtfCnpj.setText(instituicao.getCnpj());
- jtfIe.setText(instituicao.getInscricaoEstadual());
- jtfTelefone.setText(instituicao.getTelefone());
- jtfEmail.setText(instituicao.getEmail());
- jtfSite.setText(instituicao.getSite());
- jtfLogradouro.setText(instituicao.getLogradouro());
- jtfNumero.setText(instituicao.getNumero());
- jtfBairro.setText(instituicao.getBairro());
- jtfComplemento.setText(instituicao.getComplemento());
- jcbUf.setSelectedItem(instituicao.getCidade().getEstado());
- jcbCidade.setSelectedItem(instituicao.getCidade());
- } else {
- Mensagem.erro("Problema ao carregar instituição de ensino");
- jbtConfirmar.setEnabled(false);
- }
- }
- private void salvarInstituicao() {
- Instituicao instituicao = new Instituicao();
- instituicao.setId(Integer.parseInt(jtfId.getText()));
- instituicao.setNome(jtfNome.getText());
- instituicao.setCnpj(Formatador.removerPontuacaoCnpj(jtfCnpj.getText()));
- instituicao.setInscricaoEstadual(jtfIe.getText());
- instituicao.setTelefone(Formatador.removerPontuacaoTelefone(jtfTelefone.getText()));
- instituicao.setEmail(jtfEmail.getText());
- instituicao.setSite(jtfSite.getText());
- instituicao.setLogradouro(jtfLogradouro.getText());
- instituicao.setNumero(jtfNumero.getText());
- instituicao.setComplemento(jtfComplemento.getText());
- instituicao.setBairro(jtfBairro.getText());
- instituicao.setCidade((Cidade)jcbCidade.getSelectedItem());
- boolean resultado = new InstituicaoDAO().salvar(instituicao);
- if (resultado) {
- Mensagem.sucesso("Alterações registradas com sucesso");
- } else {
- Mensagem.erro("Problema ao registrar alterações");
- }
- }
- private void carregarEstados() {
- DefaultComboBoxModel modelo = new DefaultComboBoxModel();
- ArrayList<IEntidade> estados = new EstadoDAO().consultarTodos();
- for (int i = 0; i < estados.size(); i++) {
- Estado e = (Estado) estados.get(i);
- modelo.addElement(e);
- }
- jcbUf.setModel(modelo);
- }
- private void carregarCidades() {
- Estado estado = (Estado) jcbUf.getSelectedItem();
- if (estado.getId() > 0) {
- DefaultComboBoxModel modelo = new DefaultComboBoxModel();
- ArrayList<IEntidade> cidades = new CidadeDAO().consultarCidadesPorEstado(estado);
- for (int i = 0; i < cidades.size(); i++) {
- Cidade cid = (Cidade) cidades.get(i);
- modelo.addElement(cid);
- }
- jcbCidade.setModel(modelo);
- } else {
- Mensagem.aviso("Selecione um estado");
- }
- }
- /**
- * 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")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- jLabel1 = new javax.swing.JLabel();
- jLabel2 = new javax.swing.JLabel();
- jLabel3 = new javax.swing.JLabel();
- jLabel4 = new javax.swing.JLabel();
- jLabel5 = new javax.swing.JLabel();
- jLabel6 = new javax.swing.JLabel();
- jtfNome = new javax.swing.JTextField();
- jtfIe = new javax.swing.JTextField();
- jtfEmail = new javax.swing.JTextField();
- jtfSite = new javax.swing.JTextField();
- jLabel7 = new javax.swing.JLabel();
- jLabel8 = new javax.swing.JLabel();
- jLabel9 = new javax.swing.JLabel();
- jtfLogradouro = new javax.swing.JTextField();
- jtfNumero = new javax.swing.JTextField();
- jtfBairro = new javax.swing.JTextField();
- jtfComplemento = new javax.swing.JTextField();
- jLabel10 = new javax.swing.JLabel();
- jLabel11 = new javax.swing.JLabel();
- jbtConfirmar = new javax.swing.JButton();
- jbtCancelar = new javax.swing.JButton();
- jtfCnpj = new javax.swing.JFormattedTextField();
- jtfTelefone = new javax.swing.JFormattedTextField();
- jLabel12 = new javax.swing.JLabel();
- jtfId = new javax.swing.JTextField();
- jLabel13 = new javax.swing.JLabel();
- jcbUf = new javax.swing.JComboBox<>();
- jcbCidade = new javax.swing.JComboBox<>();
- setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
- setClosable(true);
- setTitle("Instituição de Ensino");
- jLabel1.setText("Nome");
- jLabel2.setText("CNPJ");
- jLabel3.setText("IE");
- jLabel4.setText("Telefone");
- jLabel5.setText("Email");
- jLabel6.setText("Site");
- jLabel7.setText("Logradouro");
- jLabel8.setText("Número");
- jLabel9.setText("Bairro");
- jLabel10.setText("Complemento");
- jLabel11.setText("Cidade");
- jbtConfirmar.setText("Confirmar");
- jbtConfirmar.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jbtConfirmarActionPerformed(evt);
- }
- });
- jbtCancelar.setText("Cancelar");
- jbtCancelar.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jbtCancelarActionPerformed(evt);
- }
- });
- try {
- jtfCnpj.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##.###.###/####-##")));
- } catch (java.text.ParseException ex) {
- ex.printStackTrace();
- }
- try {
- jtfTelefone.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(##)####-####")));
- } catch (java.text.ParseException ex) {
- ex.printStackTrace();
- }
- jLabel12.setText("Código");
- jtfId.setEditable(false);
- jLabel13.setText("UF");
- jcbUf.addItemListener(new java.awt.event.ItemListener() {
- public void itemStateChanged(java.awt.event.ItemEvent evt) {
- jcbUfItemStateChanged(evt);
- }
- });
- 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.TRAILING)
- .addGroup(layout.createSequentialGroup()
- .addGap(0, 0, Short.MAX_VALUE)
- .addComponent(jbtConfirmar)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jbtCancelar))
- .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jLabel4)
- .addComponent(jLabel5)
- .addComponent(jLabel6))
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(78, 78, 78)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jtfEmail)
- .addComponent(jtfSite)))
- .addGroup(layout.createSequentialGroup()
- .addGap(79, 79, 79)
- .addComponent(jtfTelefone, javax.swing.GroupLayout.PREFERRED_SIZE, 173, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(0, 0, Short.MAX_VALUE))))
- .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jLabel1)
- .addComponent(jLabel12))
- .addGap(93, 93, 93)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jtfNome, javax.swing.GroupLayout.PREFERRED_SIZE, 306, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jtfId, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(0, 2, Short.MAX_VALUE))
- .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jLabel7)
- .addComponent(jLabel9)
- .addComponent(jLabel10)
- .addComponent(jLabel11)
- .addComponent(jLabel13))
- .addGap(42, 42, 42)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jtfBairro, javax.swing.GroupLayout.Alignment.TRAILING)
- .addComponent(jtfLogradouro)
- .addComponent(jtfComplemento)
- .addComponent(jcbCidade, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addGroup(layout.createSequentialGroup()
- .addComponent(jcbUf, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(0, 0, Short.MAX_VALUE)))))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jLabel3)
- .addComponent(jLabel2)
- .addComponent(jLabel8))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jtfIe)
- .addComponent(jtfNumero)
- .addComponent(jtfCnpj, javax.swing.GroupLayout.DEFAULT_SIZE, 166, Short.MAX_VALUE))
- .addContainerGap())
- );
- layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jbtCancelar, jbtConfirmar});
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel12)
- .addComponent(jtfId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel1)
- .addComponent(jtfNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jLabel2)
- .addComponent(jtfCnpj, 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)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel3)
- .addComponent(jtfIe, 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.BASELINE)
- .addComponent(jLabel4)
- .addComponent(jtfTelefone, 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(jLabel5)
- .addComponent(jtfEmail, 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(jLabel6)
- .addComponent(jtfSite, 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)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel7)
- .addComponent(jLabel8)
- .addComponent(jtfNumero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addComponent(jtfLogradouro, 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(jLabel9)
- .addComponent(jtfBairro, 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(jtfComplemento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jLabel10))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel13)
- .addComponent(jcbUf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(5, 5, 5)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel11)
- .addComponent(jcbCidade, 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(jbtConfirmar)
- .addComponent(jbtCancelar))
- .addContainerGap())
- );
- layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jbtCancelar, jbtConfirmar});
- pack();
- }// </editor-fold>
- private void jbtCancelarActionPerformed(java.awt.event.ActionEvent evt) {
- this.dispose();
- }
- private void jbtConfirmarActionPerformed(java.awt.event.ActionEvent evt) {
- salvarInstituicao();
- this.dispose();
- }
- private void jcbUfItemStateChanged(java.awt.event.ItemEvent evt) {
- carregarCidades();
- }
- // Variables declaration - do not modify
- private javax.swing.JLabel jLabel1;
- private javax.swing.JLabel jLabel10;
- private javax.swing.JLabel jLabel11;
- private javax.swing.JLabel jLabel12;
- 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.JLabel jLabel6;
- private javax.swing.JLabel jLabel7;
- private javax.swing.JLabel jLabel8;
- private javax.swing.JLabel jLabel9;
- private javax.swing.JButton jbtCancelar;
- private javax.swing.JButton jbtConfirmar;
- private javax.swing.JComboBox<String> jcbCidade;
- private javax.swing.JComboBox<String> jcbUf;
- private javax.swing.JTextField jtfBairro;
- private javax.swing.JFormattedTextField jtfCnpj;
- private javax.swing.JTextField jtfComplemento;
- private javax.swing.JTextField jtfEmail;
- private javax.swing.JTextField jtfId;
- private javax.swing.JTextField jtfIe;
- private javax.swing.JTextField jtfLogradouro;
- private javax.swing.JTextField jtfNome;
- private javax.swing.JTextField jtfNumero;
- private javax.swing.JTextField jtfSite;
- private javax.swing.JFormattedTextField jtfTelefone;
- // End of variables declaration
- }
Advertisement
Add Comment
Please, Sign In to add comment