/* * CadFIla.java * * Created on 19 de Abril de 2006, 21:50 */ package gui; import controller.FilaController; import javax.swing.JOptionPane; /** * * @author lchernicharo */ public class CadFila extends javax.swing.JFrame { private FilaController ctrl; /** Creates new form CadFIla */ public CadFila() { initComponents(); ctrl = new FilaController(); refreshEnable(); } /** 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() { txtCandidato = new javax.swing.JTextField(); btnAdicionar = new javax.swing.JButton(); jLabel1 = new javax.swing.JLabel(); jScrollPane1 = new javax.swing.JScrollPane(); lstCandidatos = new javax.swing.JList(); btnAtender = new javax.swing.JButton(); btnSair = new javax.swing.JButton(); jLabel2 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); txtIdade = new javax.swing.JTextField(); btnSalvar = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setTitle("Controle de fila de pacientes"); btnAdicionar.setText("Ir para a fila"); btnAdicionar.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnAdicionarActionPerformed(evt); } }); jLabel1.setText("Pacientes aguardando atendimento:"); lstCandidatos.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); jScrollPane1.setViewportView(lstCandidatos); btnAtender.setText("Atender"); btnAtender.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnAtenderActionPerformed(evt); } }); btnSair.setText("Sair"); btnSair.setPreferredSize(new java.awt.Dimension(73, 23)); btnSair.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnSairActionPerformed(evt); } }); jLabel2.setText("Paciente"); jLabel3.setText("Idade"); btnSalvar.setText("C\u00f3pia de seguran\u00e7a"); btnSalvar.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnSalvarActionPerformed(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(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 374, Short.MAX_VALUE) .add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 248, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .add(layout.createSequentialGroup() .add(btnAtender) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 56, Short.MAX_VALUE) .add(btnSalvar) .add(47, 47, 47) .add(btnSair, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(txtCandidato, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 213, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .add(jLabel2)) .add(6, 6, 6) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(jLabel3) .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(txtIdade, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 58, Short.MAX_VALUE) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(btnAdicionar))))) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() .addContainerGap() .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(jLabel2) .add(jLabel3)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(btnAdicionar) .add(txtCandidato, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .add(txtIdade, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) .add(14, 14, 14) .add(jLabel1) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .add(15, 15, 15) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(btnSair, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .add(btnAtender) .add(btnSalvar)) .addContainerGap()) ); pack(); }// //GEN-END:initComponents private void btnSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSalvarActionPerformed if( ctrl.saveBackup() ){ JOptionPane.showMessageDialog( this, "Cópia de segurança armazenada com sucesso.", "Informação", JOptionPane.INFORMATION_MESSAGE); } else{ JOptionPane.showMessageDialog( this, "Não foi possível criar a cópia de segurança.", "Erro", JOptionPane.ERROR_MESSAGE); } }//GEN-LAST:event_btnSalvarActionPerformed private void btnSairActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSairActionPerformed dispose(); }//GEN-LAST:event_btnSairActionPerformed private void btnAtenderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAtenderActionPerformed ctrl.atenderPaciente(); lstCandidatos.setListData( ctrl.getFila() ); refreshEnable(); }//GEN-LAST:event_btnAtenderActionPerformed private void refreshEnable(){ btnAtender.setEnabled( lstCandidatos.getModel().getSize() > 0 ); btnSalvar.setEnabled( lstCandidatos.getModel().getSize() > 0 ); } private boolean validaCampos(){ try{ Integer.parseInt(txtIdade.getText()); return txtCandidato.getText().compareTo("") != 0; }catch( NumberFormatException e ){ return false; } } private void btnAdicionarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAdicionarActionPerformed if( !validaCampos() ){ JOptionPane.showMessageDialog( this, "Preencha todos os campos corretamente.", "Erro", JOptionPane.ERROR_MESSAGE); return; } if( lstCandidatos.getModel().getSize() == 0 ){ ctrl.iniciarFila(); } ctrl.adicionaPaciente( txtCandidato.getText(), Integer.parseInt( txtIdade.getText() ) ); lstCandidatos.setListData( ctrl.getFila() ); refreshEnable(); }//GEN-LAST:event_btnAdicionarActionPerformed /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new CadFila().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton btnAdicionar; private javax.swing.JButton btnAtender; private javax.swing.JButton btnSair; private javax.swing.JButton btnSalvar; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JList lstCandidatos; private javax.swing.JTextField txtCandidato; private javax.swing.JTextField txtIdade; // End of variables declaration//GEN-END:variables }