Ir ao conteúdo
  • Cadastre-se
Entre para seguir isso  
josehenriquefs

Problema com nullpointerExcpetion - Não consigo achar o problema

Recommended Posts

Pessoal, preciso entregar um projeto na faculdade e simplesmente fiquei preso nessa parte onde não consigo encontrar o meu erro. Ele lança as seguintes mensagens:

java.lang.NullPointerException
	at br.com.wtech.securecar.ui.CadTitular.validaCampos(CadTitular.java:467)
	at br.com.wtech.securecar.ui.CadTitular.access$0(CadTitular.java:460)
	at br.com.wtech.securecar.ui.CadTitular$2.actionPerformed(CadTitular.java:341)
	at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
	at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
	at java.awt.Component.processMouseEvent(Unknown Source)
	at javax.swing.JComponent.processMouseEvent(Unknown Source)
	at java.awt.Component.processEvent(Unknown Source)
	at java.awt.Container.processEvent(Unknown Source)
	at java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Window.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
	at java.awt.EventQueue.access$500(Unknown Source)
	at java.awt.EventQueue$3.run(Unknown Source)
	at java.awt.EventQueue$3.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.awt.EventQueue$4.run(Unknown Source)
	at java.awt.EventQueue$4.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)
ERRO CT
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
	at br.com.wtech.securecar.ui.CadTitular.limpaCampos(CadTitular.java:406)
	at br.com.wtech.securecar.ui.CadTitular.access$2(CadTitular.java:404)
	at br.com.wtech.securecar.ui.CadTitular$4.actionPerformed(CadTitular.java:391)
	at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
	at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
	at java.awt.Component.processMouseEvent(Unknown Source)
	at javax.swing.JComponent.processMouseEvent(Unknown Source)
	at java.awt.Component.processEvent(Unknown Source)
	at java.awt.Container.processEvent(Unknown Source)
	at java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Window.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
	at java.awt.EventQueue.access$500(Unknown Source)
	at java.awt.EventQueue$3.run(Unknown Source)
	at java.awt.EventQueue$3.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.awt.EventQueue$4.run(Unknown Source)
	at java.awt.EventQueue$4.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)

Passei mais de 8 horas procurando encontrar onde eu errei, reescrevendo linhas  e tudo mais, mas não consigo achar o que está causando isso, será que alguém poderia dar uma luz?

adicionado 1 minuto depois

Segue abaixo o código dessa classe:

package br.com.wtech.securecar.ui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Font;
import java.text.ParseException;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFormattedTextField;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;
import javax.swing.text.MaskFormatter;

import java.sql.*;
import br.com.wtech.securecar.model.Titular;
import br.com.wtech.securecar.persistence.Conexao;
import br.com.wtech.securecar.persistence.PersistenceTitular;


import javax.swing.SwingConstants;
import javax.swing.JFrame;
import java.awt.event.ActionListener;
import java.io.File;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.awt.event.ActionEvent;
import javax.swing.ImageIcon;
import javax.swing.JTextPane;
import javax.swing.UIManager;

public class CadTitular extends JInternalFrame {
	
	
	private JTextField textFieldNome;
	private JTextField textFieldEmail;
	private JTextField textFieldProfissao;
	private JTextField textFieldLogradouro;
	private JTextField textFieldBairro;
	private JTextField textFieldCidade;
	private JFormattedTextField formattedTextFieldCPF;
	private JFormattedTextField formattedTextFieldFone;
	private JFormattedTextField formattedTextFieldDC;
	private JFormattedTextField formattedTextFieldDN;
	private JFormattedTextField formattedTextFieldCEP;
	private JComboBox comboBoxQTDV;
	private JComboBox comboBoxEC;
	private JComboBox comboBoxSexo;
	private JComboBox comboBoxSituacao;
	private JComboBox comboBoxEstado;
	
	Titular titular;
	PersistenceTitular perTitular;
	
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					CadTitular frame = new CadTitular();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public CadTitular() {
		
		// *Instanciando objeto titular
		titular = new Titular();
		perTitular = new PersistenceTitular();
		
		//titular.getInstance();
		//Conexao con = new Conexao();
		//con.getConnection();
		
		// *config do frame
		setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
		setResizable(true);
		setClosable(true);
		setBounds(100, 100, 640, 480);
		
		// *Mascaras de formato
		
		MaskFormatter mascaraData = null;
		try {
			mascaraData = new MaskFormatter("##/##/####");
		} catch (ParseException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}

		MaskFormatter mascaraFone = null;
		try {
			mascaraFone = new MaskFormatter("## 9####-####");
		} catch (ParseException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}

		MaskFormatter mascaraCPF = null;
		try {
			mascaraCPF = new MaskFormatter("###.###.###-##");
		} catch (ParseException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		
		MaskFormatter mascaraCEP = null;
		try {
			mascaraCEP = new MaskFormatter("#####-###");
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		// *inicio swing

		JPanel panelBackground = new JPanel();
		panelBackground.setBackground(Color.LIGHT_GRAY);
		getContentPane().add(panelBackground, BorderLayout.CENTER);
		panelBackground.setLayout(null);

		JLabel lblCadastroDeTitular = new JLabel("CADASTRO DE TITULAR");
		lblCadastroDeTitular.setBounds(235, 17, 125, 14);
		panelBackground.add(lblCadastroDeTitular);
		lblCadastroDeTitular.setFont(new Font("Arial", Font.BOLD, 11));

		JPanel panel = new JPanel();
		panel.setBounds(10, 42, 604, 127);
		panel.setBackground(Color.LIGHT_GRAY);
		panel.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null),
				"Informa\u00E7\u00F5es Pessoais", TitledBorder.LEADING, TitledBorder.TOP, null));
		panelBackground.add(panel);
		panel.setLayout(null);

		JLabel lblNome = new JLabel("*Nome:");
		lblNome.setBounds(10, 20, 34, 14);
		lblNome.setFont(new Font("Arial", Font.PLAIN, 11));
		panel.add(lblNome);

		textFieldNome = new JTextField();
		textFieldNome.setBounds(45, 17, 413, 20);
		textFieldNome.setFont(new Font("Arial", Font.PLAIN, 11));
		panel.add(textFieldNome);
		textFieldNome.setColumns(10);

		JLabel lblCpf = new JLabel("*CPF:");
		lblCpf.setBounds(470, 20, 26, 14);
		lblCpf.setFont(new Font("Arial", Font.PLAIN, 11));
		panel.add(lblCpf);
		JFormattedTextField formattedTextFieldCPF = new JFormattedTextField(mascaraCPF);
		formattedTextFieldCPF.setBounds(501, 16, 93, 20);
		formattedTextFieldCPF.setHorizontalAlignment(SwingConstants.CENTER);
		formattedTextFieldCPF.setText("");
		panel.add(formattedTextFieldCPF);

		JLabel lblEstadoCivil = new JLabel("Estado Civil:");
		lblEstadoCivil.setBounds(10, 45, 62, 14);
		lblEstadoCivil.setFont(new Font("Arial", Font.PLAIN, 11));
		panel.add(lblEstadoCivil);

		JComboBox comboBoxEC = new JComboBox();
		comboBoxEC.setBounds(69, 42, 114, 20);
		comboBoxEC.setFont(new Font("Arial", Font.PLAIN, 11));
		comboBoxEC.setModel(new DefaultComboBoxModel(new String[] { "Solteiro (S)", "Casado (C)", "Vi\u00FAvo (V)",
				"Uni\u00E3o Est\u00E1vel (UE)", "Divorciado (D)" }));
		panel.add(comboBoxEC);

		JLabel lblSexo = new JLabel("Sexo:");
		lblSexo.setBounds(195, 45, 32, 14);
		lblSexo.setFont(new Font("Arial", Font.PLAIN, 11));
		panel.add(lblSexo);

		JComboBox comboBoxSexo = new JComboBox();
		comboBoxSexo.setBounds(224, 42, 80, 20);
		comboBoxSexo.setFont(new Font("Arial", Font.PLAIN, 11));
		comboBoxSexo.setModel(new DefaultComboBoxModel(new String[] { "Masculino", "Feminino" }));
		panel.add(comboBoxSexo);

		JLabel lblDataNascimento = new JLabel("*Data de Nasc.:");
		lblDataNascimento.setBounds(307, 45, 75, 14);
		lblDataNascimento.setFont(new Font("Arial", Font.PLAIN, 11));
		panel.add(lblDataNascimento);
		JFormattedTextField formattedTextFieldDN = new JFormattedTextField(mascaraData);
		formattedTextFieldDN.setBounds(380, 42, 70, 20);
		formattedTextFieldDN.setHorizontalAlignment(SwingConstants.CENTER);
		panel.add(formattedTextFieldDN);

		JLabel lblDataCadastro = new JLabel("*Data de Cad.:");
		lblDataCadastro.setBounds(450, 45, 69, 14);
		lblDataCadastro.setFont(new Font("Arial", Font.PLAIN, 11));
		panel.add(lblDataCadastro);

		JFormattedTextField formattedTextFieldDC = new JFormattedTextField(mascaraData);
		formattedTextFieldDC.setBounds(519, 41, 75, 20);
		formattedTextFieldDC.setHorizontalAlignment(SwingConstants.CENTER);
		panel.add(formattedTextFieldDC);

		JLabel lblEmail = new JLabel("E-mail:");
		lblEmail.setBounds(10, 72, 31, 14);
		lblEmail.setFont(new Font("Arial", Font.PLAIN, 11));
		panel.add(lblEmail);

		textFieldEmail = new JTextField();
		textFieldEmail.setBounds(41, 67, 144, 20);
		textFieldEmail.setFont(new Font("Arial", Font.PLAIN, 11));
		textFieldEmail.setColumns(10);
		panel.add(textFieldEmail);

		JLabel lblTelefone = new JLabel("*Fone:");
		lblTelefone.setHorizontalAlignment(SwingConstants.CENTER);
		lblTelefone.setBounds(195, 72, 31, 14);
		lblTelefone.setFont(new Font("Arial", Font.PLAIN, 11));
		panel.add(lblTelefone);
		JFormattedTextField formattedTextFieldFone = new JFormattedTextField(mascaraFone);
		formattedTextFieldFone.setBounds(224, 70, 80, 18);
		formattedTextFieldFone.setHorizontalAlignment(SwingConstants.CENTER);
		formattedTextFieldFone.setFont(new Font("Arial", Font.PLAIN, 11));
		formattedTextFieldFone.setText("");
		panel.add(formattedTextFieldFone);

		JLabel lblProfissao = new JLabel("Profiss\u00E3o:");
		lblProfissao.setBounds(317, 72, 49, 14);
		lblProfissao.setFont(new Font("Arial", Font.PLAIN, 11));
		panel.add(lblProfissao);

		textFieldProfissao = new JTextField();
		textFieldProfissao.setBounds(365, 70, 93, 20);
		textFieldProfissao.setFont(new Font("Arial", Font.PLAIN, 11));
		textFieldProfissao.setColumns(10);
		panel.add(textFieldProfissao);

		JLabel lblSituacao = new JLabel("*Situa\u00E7\u00E3o:");
		lblSituacao.setBounds(470, 72, 49, 14);
		lblSituacao.setFont(new Font("Arial", Font.PLAIN, 11));
		panel.add(lblSituacao);

		JComboBox comboBoxSituacao = new JComboBox();
		comboBoxSituacao.setBounds(519, 70, 74, 20);
		comboBoxSituacao.setFont(new Font("Arial", Font.PLAIN, 11));
		comboBoxSituacao.setModel(new DefaultComboBoxModel(new String[] { "Ativo (A)", "Inativo (I)" }));
		panel.add(comboBoxSituacao);
		
		JLabel lblNVeiculos = new JLabel("*N\u00BA Veiculos:");
		lblNVeiculos.setFont(new Font("Arial", Font.PLAIN, 11));
		lblNVeiculos.setBounds(10, 99, 64, 14);
		panel.add(lblNVeiculos);
		
		JComboBox comboBoxQTDV = new JComboBox();
		comboBoxQTDV.setModel(new DefaultComboBoxModel(new String[] {"1", "2", "3"}));
		comboBoxQTDV.setFont(new Font("Arial", Font.PLAIN, 11));
		comboBoxQTDV.setBounds(76, 95, 34, 23);
		panel.add(comboBoxQTDV);

		JPanel panelEndereco = new JPanel();
		panelEndereco.setForeground(new Color(0, 0, 0));
		panelEndereco.setToolTipText("");
		panelEndereco.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null), "Endere\u00E7o",
				TitledBorder.LEADING, TitledBorder.TOP, null, null));
		panelEndereco.setBackground(Color.LIGHT_GRAY);
		panelEndereco.setBounds(10, 182, 604, 76);
		panelBackground.add(panelEndereco);
		panelEndereco.setLayout(null);

		JLabel lblLogradouro = new JLabel("Logradouro:");
		lblLogradouro.setFont(new Font("Arial", Font.PLAIN, 11));
		lblLogradouro.setBounds(10, 20, 59, 14);
		panelEndereco.add(lblLogradouro);

		textFieldLogradouro = new JTextField();
		textFieldLogradouro.setFont(new Font("Arial", Font.PLAIN, 11));
		textFieldLogradouro.setBounds(68, 17, 217, 20);
		panelEndereco.add(textFieldLogradouro);
		textFieldLogradouro.setColumns(10);

		JLabel lblBairro = new JLabel("Bairro:");
		lblBairro.setFont(new Font("Arial", Font.PLAIN, 11));
		lblBairro.setBounds(295, 20, 32, 14);
		panelEndereco.add(lblBairro);

		textFieldBairro = new JTextField();
		textFieldBairro.setFont(new Font("Arial", Font.PLAIN, 11));
		textFieldBairro.setColumns(10);
		textFieldBairro.setBounds(327, 17, 93, 20);
		panelEndereco.add(textFieldBairro);

		JLabel lblCidade = new JLabel("Cidade:");
		lblCidade.setFont(new Font("Arial", Font.PLAIN, 11));
		lblCidade.setBounds(430, 20, 36, 14);
		panelEndereco.add(lblCidade);

		textFieldCidade = new JTextField();
		textFieldCidade.setFont(new Font("Arial", Font.PLAIN, 11));
		textFieldCidade.setColumns(10);
		textFieldCidade.setBounds(467, 17, 93, 20);
		panelEndereco.add(textFieldCidade);

		JLabel lblEstado = new JLabel("Estado:");
		lblEstado.setFont(new Font("Arial", Font.PLAIN, 11));
		lblEstado.setBounds(10, 45, 36, 14);
		panelEndereco.add(lblEstado);

		JComboBox comboBoxEstado = new JComboBox();
		comboBoxEstado.setFont(new Font("Arial", Font.PLAIN, 11));
		comboBoxEstado.setModel(new DefaultComboBoxModel(new String[] { "Para\u00EDba (PB)" }));
		comboBoxEstado.setBounds(47, 42, 85, 20);
		panelEndereco.add(comboBoxEstado);

		JLabel lblCep = new JLabel("*CEP:");
		lblCep.setFont(new Font("Arial", Font.PLAIN, 11));
		lblCep.setBounds(141, 45, 26, 14);
		panelEndereco.add(lblCep);

		
		JFormattedTextField formattedTextFieldCEP = new JFormattedTextField(mascaraCEP);
		formattedTextFieldCEP.setHorizontalAlignment(SwingConstants.CENTER);
		formattedTextFieldCEP.setBounds(167, 41, 68, 20);
		panelEndereco.add(formattedTextFieldCEP);
			
		
		// *Botão Cadastrar - CORRIGIR!!!!!
		JButton btnCadastrar = new JButton("CADASTRAR");
		btnCadastrar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent cadastrar) {
				try{
					if(validaCampos()){
						if(preencheCampos()){
							if(perTitular.insert(titular));
								JOptionPane.showMessageDialog(null, "Dados gravados com sucesso!\n");
								limpaCampos();
						}else{
							JOptionPane.showMessageDialog(null, "Erro ao gravar os dados!\n");
						}
					}
				}catch (Exception e){
					e.printStackTrace();
					JOptionPane.showMessageDialog(null, "ERRO DESCONHECIDO\n"+e.getMessage(),"CADASTRAR",JOptionPane.ERROR_MESSAGE);
					System.out.println("ERRO CT");
				}
			}
		});
		btnCadastrar.setFont(new Font("Arial", Font.PLAIN, 11));
		btnCadastrar.setBounds(506, 417, 108, 23);
		panelBackground.add(btnCadastrar);
		
		
		// *Botao cancelar
		JButton btnCancelar = new JButton("CANCELAR");
		btnCancelar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent cancelar) {
				
				setVisible(false);

			}
		});
		btnCancelar.setFont(new Font("Arial", Font.PLAIN, 11));
		btnCancelar.setBounds(400, 417, 96, 23);
		panelBackground.add(btnCancelar);
		
		JLabel lblImg = new JLabel("");
		lblImg.setIcon(new ImageIcon("C:\\Users\\Jos\u00E9Henrique\\git\\SecureCarFinal\\SecureCarFinal\\imgs\\jpanel_logo2.png"));
		lblImg.setBounds(529, 331, 80, 80);
		panelBackground.add(lblImg);
		
		JTextPane txtpncamposObrigatrios = new JTextPane();
		txtpncamposObrigatrios.setBounds(20, 259, 125, 23);
		panelBackground.add(txtpncamposObrigatrios);
		txtpncamposObrigatrios.setBackground(Color.LIGHT_GRAY);
		txtpncamposObrigatrios.setFont(new Font("Arial", Font.PLAIN, 10));
		txtpncamposObrigatrios.setText("*campos obrigat\u00F3rios");
		
		// *Botao limpar;
		JButton btnLimpar = new JButton("LIMPAR");
		btnLimpar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				limpaCampos();
			}
		});
		btnLimpar.setFont(new Font("Arial", Font.PLAIN, 11));
		btnLimpar.setBounds(10, 417, 110, 22);
		panelBackground.add(btnLimpar);

	}
	

	
	
	// *Metodo que limpa os campos da tela
	private void limpaCampos(){
		textFieldNome.setText("");
		formattedTextFieldCPF.setText("");
		comboBoxEC.setSelectedIndex(0);
		comboBoxEstado.setSelectedIndex(0);
		comboBoxQTDV.setSelectedIndex(0);
		comboBoxSexo.setSelectedIndex(0);
		comboBoxSituacao.setSelectedIndex(0);
		formattedTextFieldCEP.setText("");
		formattedTextFieldDC.setText("");
		formattedTextFieldDN.setText("");
		formattedTextFieldFone.setText("");
		textFieldEmail.setText("");
		textFieldProfissao.setText("");
		textFieldLogradouro.setText("");
		textFieldBairro.setText("");
		textFieldCidade.setText("");
		JOptionPane.showMessageDialog(null, "Campos resetados\n");
	}
	
	// *Metodo que preenche os campos no obj
	private boolean preencheCampos(){
	
		String cpf = formattedTextFieldCPF.getText().replace(".","").replace("-","");
		String eC = comboBoxEC.getSelectedItem().toString().substring(0, 2);
		String sexo = comboBoxSexo.getSelectedItem().toString().substring(0, 2).trim();
		String dN = formattedTextFieldDN.getText();
		String dC = formattedTextFieldDC.getText();
		String fone = formattedTextFieldFone.getText().replace("9", "").replace("-", "");
		String situacao = comboBoxSituacao.getSelectedItem().toString().substring(0, 2).trim();
		int qtdV = comboBoxQTDV.getSelectedItem().hashCode();
		String cep = formattedTextFieldCEP.getText().replace("-", "");
		String uf = comboBoxEstado.getSelectedItem().toString().substring(0, 2).trim();
		
		
		titular.setNome(textFieldNome.getText());
		titular.setCpf(cpf);
		titular.setEstadoCivil(eC);
		titular.setSexo(sexo);
		titular.setDataNascimento(dN);
		titular.setDataCadastro(dC);
		titular.setEmail(textFieldEmail.getText());
		titular.setTelefone(fone);
		titular.setProfissão(textFieldProfissao.getText());
		titular.setSituação(situacao);
		titular.setQtdVeiculos(qtdV);
		titular.setLogradouro(textFieldLogradouro.getText());
		titular.setBairro(textFieldBairro.getText());
		titular.setCidade(textFieldCidade.getText());
		titular.setEstado(uf);
		titular.setCep(cep);

		return true;
	}
	
	// *Metodo para validar os campos na interface
	private boolean validaCampos(){
		
		if(textFieldNome.getText().equals("")){
			JOptionPane.showMessageDialog(null, "Campo NOME obrigatório");
			textFieldNome.requestFocus();
			return false;
		}else
			if(formattedTextFieldCPF.getText().equals("")){
			JOptionPane.showMessageDialog(null, "Campo CPF obrigatório");
			formattedTextFieldCPF.requestFocus();
			return false;
		}else
			if(formattedTextFieldDN.getText().equals("")){
			JOptionPane.showMessageDialog(null, "Campo DATA NASC obrigatório");
			formattedTextFieldDN.requestFocus();
			return false;
		}else
			if(formattedTextFieldDC.getText().equals("")){
			JOptionPane.showMessageDialog(null, "Campo DATA CAD obrigatório");
			formattedTextFieldDC.requestFocus();
			return false;
		}else
			if(formattedTextFieldFone.getText().equals("")){
			JOptionPane.showMessageDialog(null, "Campo TELEFONE obrigatório");
			formattedTextFieldFone.requestFocus();
			return false;
		}else
			if(formattedTextFieldCEP.getText().equals("")){
			JOptionPane.showMessageDialog(null, "Campo CEP obrigatório");
			formattedTextFieldCEP.requestFocus();
			return false;
	}
		
		return true;
	}
	
	
}

 

Compartilhar este post


Link para o post
Compartilhar em outros sites

Crie uma conta ou entre para comentar

Você precisar ser um membro para fazer um comentário

Criar uma conta

Crie uma nova conta em nossa comunidade. É fácil!

Crie uma nova conta

Entrar

Já tem uma conta? Faça o login.

Entrar agora
Entre para seguir isso  





Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas publicações sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×