/* * SegundaTela.java * * Created on 7 de Outubro de 2006, 14:43 */ package gui; import classes.Aluno; import classes.ObjectSaver; import javax.swing.JOptionPane; /** * * @author 008802 */ public class SegundaTela extends javax.swing.JFrame { /** Creates new form SegundaTela */ public SegundaTela() { initComponents(); cmbCurso.setSelectedIndex(-1); } /** 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. */ // //GEN-BEGIN:initComponents private void initComponents() { jScrollPane1 = new javax.swing.JScrollPane(); jTable1 = new javax.swing.JTable(); jLabel1 = new javax.swing.JLabel(); txtMatricula = new javax.swing.JTextField(); txtNome = new javax.swing.JTextField(); jLabel2 = new javax.swing.JLabel(); cmbCurso = new javax.swing.JComboBox(); jLabel3 = new javax.swing.JLabel(); btnOK = new javax.swing.JButton(); btnSair = new javax.swing.JButton(); btnLocalizar = new javax.swing.JButton(); jTable1.setModel(new javax.swing.table.DefaultTableModel( new Object [][] { {null, null, null, null}, {null, null, null, null}, {null, null, null, null}, {null, null, null, null} }, new String [] { "Title 1", "Title 2", "Title 3", "Title 4" } )); jScrollPane1.setViewportView(jTable1); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setTitle("Cadastro de alunos"); jLabel1.setText("Matricula"); jLabel2.setText("Nome"); cmbCurso.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Superior de Tecnologia em Inform\u00e1tica", "Administra\u00e7\u00e3o de Empresas", "Publicidade e Propaganda" })); jLabel3.setText("Curso"); btnOK.setText("OK"); btnOK.setPreferredSize(new java.awt.Dimension(53, 23)); btnOK.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cadastrarAluno(evt); } }); btnSair.setText("Sair"); btnSair.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { sair(evt); } }); btnLocalizar.setText("..."); btnLocalizar.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { buscarAluno(evt); } }); org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup() .addContainerGap() .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup() .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(jLabel1) .add(layout.createSequentialGroup() .add(txtMatricula, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 67, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 12, Short.MAX_VALUE) .add(btnLocalizar, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 30, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED))) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(jLabel2) .add(txtNome, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 274, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))) .add(cmbCurso, 0, 383, Short.MAX_VALUE) .add(jLabel3)) .addContainerGap()) .add(layout.createSequentialGroup() .add(55, 55, 55) .add(btnOK, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 183, Short.MAX_VALUE) .add(btnSair) .add(59, 59, 59)) ); layout.setVerticalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup() .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(jLabel1) .add(jLabel2)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(txtMatricula, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .add(btnLocalizar) .add(txtNome, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(jLabel3) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(cmbCurso, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .add(24, 24, 24) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(btnOK, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .add(btnSair)) .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); pack(); }// //GEN-END:initComponents private void buscarAluno(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buscarAluno if( txtMatricula.getText().equals( "" ) ){ JOptionPane.showMessageDialog( null, "Primeiro informe a matrícula." ); return; } Aluno a = (Aluno)ObjectSaver.readObject( txtMatricula.getText() + ".xml" ); if( a == null ){ JOptionPane.showMessageDialog( null, "Aluno não encontrado." ); } else{ txtNome.setText( a.getNome() ); cmbCurso.setSelectedItem( a.getCurso() ); } }//GEN-LAST:event_buscarAluno private void cadastrarAluno(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cadastrarAluno Aluno a = new Aluno(); a.setMatricula( txtMatricula.getText() ); a.setNome( txtNome.getText() ); try { a.setCurso( cmbCurso.getSelectedItem().toString() ); } catch( NullPointerException ex ) { JOptionPane.showMessageDialog( null, "Informe o curso.", "Erro!", JOptionPane.ERROR_MESSAGE ); return; } if( ObjectSaver.saveObject( a.getMatricula() + ".xml", a) ) JOptionPane.showMessageDialog( null, "Aluno cadastrado com sucesso." ); else JOptionPane.showMessageDialog( null, "Erro no cadastro do aluno.", "Erro!", JOptionPane.ERROR_MESSAGE ); }//GEN-LAST:event_cadastrarAluno private void sair(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sair dispose(); }//GEN-LAST:event_sair /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new SegundaTela().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton btnLocalizar; private javax.swing.JButton btnOK; private javax.swing.JButton btnSair; private javax.swing.JComboBox cmbCurso; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JTable jTable1; private javax.swing.JTextField txtMatricula; private javax.swing.JTextField txtNome; // End of variables declaration//GEN-END:variables }