/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* FrmCadastroAcessorio.java
*
* Created on 25/08/2010, 17:28:07
*/
package boundary;
import control.ControladoraAcessorio;
import java.sql.SQLException;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import util.ConexaoException;
import util.MinhaException;
/**
*
* @author Rodrigo Martins
*/
public class FrmCadastroAcessorio extends javax.swing.JDialog {
ControladoraAcessorio cadastroAcessorio;
/** Creates new form FrmCadastroAcessorio */
public FrmCadastroAcessorio() {
initComponents();
this.setLocationRelativeTo(null);
this.setModal(true);
this.cadastroAcessorio = new ControladoraAcessorio();
}
/** 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();
jTFDescricaoAcessorio = new javax.swing.JTextField();
jBCadastrar = new javax.swing.JButton();
jBLimpar = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("SCC - Cadastro Acessorio");
setResizable(false);
jLabel1.setText("Descrição Acessório");
jBCadastrar.setText("OK");
jBCadastrar.setMaximumSize(new java.awt.Dimension(80, 22));
jBCadastrar.setMinimumSize(new java.awt.Dimension(80, 22));
jBCadastrar.setPreferredSize(new java.awt.Dimension(80, 22));
jBCadastrar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jBCadastrarActionPerformed(evt);
}
});
jBLimpar.setText("Limpar");
jBLimpar.setMaximumSize(new java.awt.Dimension(80, 22));
jBLimpar.setMinimumSize(new java.awt.Dimension(80, 22));
jBLimpar.setPreferredSize(new java.awt.Dimension(80, 22));
jBLimpar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jBLimparActionPerformed(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.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel1)
.addGap(18, 18, 18)
.addComponent(jTFDescricaoAcessorio, javax.swing.GroupLayout.DEFAULT_SIZE, 171, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(jBLimpar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jBCadastrar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(jTFDescricaoAcessorio, 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(jBCadastrar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jBLimpar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(12, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void jBCadastrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBCadastrarActionPerformed
// TODO add your handling code here:
if (!this.jTFDescricaoAcessorio.getText().isEmpty())
{
Vector novoAcessorio = new Vector();
novoAcessorio.addElement(this.jTFDescricaoAcessorio.getText());
try
{
try {
try {
this.cadastroAcessorio.inserirNovoAcessorio(novoAcessorio);
} catch (ConexaoException ex) {
Logger.getLogger(FrmCadastroAcessorio.class.getName()).log(Level.SEVERE, null, ex);
}
this.jTFDescricaoAcessorio.setText("");
this.dispose();
} catch (MinhaException ex){
JOptionPane.showMessageDialog(null, ex.getMessage(), "Erro", JOptionPane.ERROR_MESSAGE);
}
}
catch (SQLException erro)
{
JOptionPane.showMessageDialog(null, erro.getMessage(), "Erro", JOptionPane.ERROR_MESSAGE);
}
}else
JOptionPane.showMessageDialog(null, "É necessário a Descrição do Acessório","Atenção" , JOptionPane.WARNING_MESSAGE);
}//GEN-LAST:event_jBCadastrarActionPerformed
private void jBLimparActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBLimparActionPerformed
// TODO add your handling code here:
this.jTFDescricaoAcessorio.setText("");
}//GEN-LAST:event_jBLimparActionPerformed
/**
* @param args the command line arguments
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new FrmCadastroAcessorio().setVisible(true);
}
});
}
*/
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jBCadastrar;
private javax.swing.JButton jBLimpar;
private javax.swing.JLabel jLabel1;
private javax.swing.JTextField jTFDescricaoAcessorio;
// End of variables declaration//GEN-END:variables
}