package Interface;
import Dados.Paciente;
import java.awt.CardLayout;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.sql.Date;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* Cadastro.java
*
* Created on 13/07/2011, 15:39:02
*/
/**
*
* @author Cecilia
*/
public class Cadastro extends javax.swing.JPanel {
/** Creates new form Cadastro */
public Cadastro() {
initComponents();
addComponentListener(new ComponentAdapter() {
@Override
public void componentShown(ComponentEvent e) {
getParent().setPreferredSize(getPreferredSize());
// ((JFrame)getRootPane().getParent()).pack();
jTextFieldEmail.setText("");
jTextFieldEndereco.setText("");
jTextFieldNome.setText("");
jTextFieldRG.setText("");
jTextFieldTelefone.setText("");
jFormattedTextFieldDataNascimento.setText("dd/mm/aaaa");
}
});
}
/** 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">//GEN-BEGIN:initComponents
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jTextFieldRG = new javax.swing.JTextField();
jTextFieldNome = new javax.swing.JTextField();
jButtonCadastrar = new javax.swing.JButton();
jTextFieldEndereco = new javax.swing.JTextField();
jLabel5 = new javax.swing.JLabel();
jTextFieldTelefone = new javax.swing.JTextField();
jLabel6 = new javax.swing.JLabel();
jTextFieldEmail = new javax.swing.JTextField();
jLabel7 = new javax.swing.JLabel();
jFormattedTextFieldDataNascimento = new javax.swing.JFormattedTextField();
jLabel8 = new javax.swing.JLabel();
jFormattedTextFieldDataCadastro = new javax.swing.JFormattedTextField();
jButtonCancelar = new javax.swing.JButton();
jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel1.setText("Cadastro");
jLabel1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
jLabel2.setText("Nome");
jLabel3.setText("Rg");
jLabel4.setText("Endereço");
jButtonCadastrar.setText("Cadastrar");
jButtonCadastrar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButtonCadastrarActionPerformed(evt);
}
});
jLabel5.setText("Telefone");
jLabel6.setText("E-mail");
jLabel7.setText("Data de Nascimento");
jFormattedTextFieldDataNascimento.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter()));
jFormattedTextFieldDataNascimento.setText("dd/mm/aaaa");
jLabel8.setText("Data de Cadastro");
jFormattedTextFieldDataCadastro.setEditable(false);
jFormattedTextFieldDataCadastro.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter()));
jFormattedTextFieldDataCadastro.setPreferredSize(new java.awt.Dimension(66, 20));
jButtonCancelar.setText("Cancelar");
jButtonCancelar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButtonCancelarActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(325, 325, 325)
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 51, Short.MAX_VALUE)
.addGap(325, 325, 325))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jLabel5)
.addComponent(jLabel7)
.addComponent(jFormattedTextFieldDataNascimento)
.addComponent(jTextFieldTelefone, javax.swing.GroupLayout.PREFERRED_SIZE, 168, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel6)
.addGroup(layout.createSequentialGroup()
.addComponent(jFormattedTextFieldDataCadastro, javax.swing.GroupLayout.PREFERRED_SIZE, 156, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButtonCadastrar, javax.swing.GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButtonCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jLabel8)
.addComponent(jTextFieldEmail, javax.swing.GroupLayout.DEFAULT_SIZE, 507, Short.MAX_VALUE)))
.addComponent(jTextFieldEndereco, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 681, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2)
.addComponent(jTextFieldNome, javax.swing.GroupLayout.DEFAULT_SIZE, 498, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel3)
.addComponent(jTextFieldRG, javax.swing.GroupLayout.PREFERRED_SIZE, 177, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addContainerGap())
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel4)
.addContainerGap(646, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(21, 21, 21)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel3))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextFieldNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextFieldRG, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(11, 11, 11)
.addComponent(jLabel4)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jTextFieldEndereco, 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(jLabel6))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextFieldTelefone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextFieldEmail, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel7)
.addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jFormattedTextFieldDataNascimento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jFormattedTextFieldDataCadastro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButtonCadastrar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButtonCancelar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addContainerGap())
);
}// </editor-fold>//GEN-END:initComponents
private void jButtonCadastrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCadastrarActionPerformed
//Insere o novo paciente
SimpleDateFormat formato = new SimpleDateFormat("dd/MM/yyyy");
Paciente novo = new Paciente();
novo.setRG(jTextFieldRG.getText());
novo.setEmail(jTextFieldEmail.getText());
novo.setEndereco(jTextFieldEndereco.getText());
novo.setNome(jTextFieldNome.getText());
novo.setTelefone(jTextFieldTelefone.getText());
java.util.Date data = new java.util.Date();
novo.setCadastro(new Date(data.getTime()));
try {
novo.setNascimento(new java.sql.Date(formato.parse(jFormattedTextFieldDataNascimento.getText()).getTime()));
} catch (ParseException ex) {
Logger.getLogger(Cadastro.class.getName()).log(Level.SEVERE, null, ex);
}
novo.save();
//Volta para o menu principal
CardLayout cardLayout = (CardLayout) this.getParent().getLayout();
cardLayout.show(getParent(),JanelaDaAplicacao.MENUPRINCIPAL);
}//GEN-LAST:event_jButtonCadastrarActionPerformed
private void jButtonCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancelarActionPerformed
CardLayout cardLayout = (CardLayout) this.getParent().getLayout();
cardLayout.show(getParent(),JanelaDaAplicacao.MENUPRINCIPAL);
}//GEN-LAST:event_jButtonCancelarActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButtonCadastrar;
private javax.swing.JButton jButtonCancelar;
private javax.swing.JFormattedTextField jFormattedTextFieldDataCadastro;
private javax.swing.JFormattedTextField jFormattedTextFieldDataNascimento;
private javax.swing.JLabel jLabel1;
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.JTextField jTextFieldEmail;
private javax.swing.JTextField jTextFieldEndereco;
private javax.swing.JTextField jTextFieldNome;
private javax.swing.JTextField jTextFieldRG;
private javax.swing.JTextField jTextFieldTelefone;
// End of variables declaration//GEN-END:variables
}