5. TALLER DE PROGRAMACIÓN
PROGRAMA QUE DETERMINA SI UN PACIENTE DEBE SER ATENDIDO DE URGENCIA
1. Código Fuente (NetBeans)
package paqHospital;
import javax.swing.JOptionPane;
/**
*
* @author Familia Ariza
*/
public class jHospital extends javax.swing.JFrame {
/**
* Creates new form jHospital
*/
public jHospital() {
initComponents();
jBtnimpri.setEnabled(false);//se esta desactivando el boton
}
/**
* 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">
private void initComponents() {
jlblingrese = new javax.swing.JLabel();
jlbltemp = new javax.swing.JLabel();
jlbldes = new javax.swing.JLabel();
jlblcarne = new javax.swing.JLabel();
jBtnimpri = new javax.swing.JButton();
jBtnenviar = new javax.swing.JButton();
jTextField1 = new javax.swing.JTextField();
jComboBox = new javax.swing.JComboBox();
jCheckBox1 = new javax.swing.JCheckBox();
jCheckBox2 = new javax.swing.JCheckBox();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jlblingrese.setText("Ingrese el nombre del paciente");
jlbltemp.setText("Temperatura");
jlbldes.setText("Deshidratado");
jlblcarne.setText("Carné de salud ");
jBtnimpri.setText("IMPRIMIR");
jBtnenviar.setText("ENVIAR");
jBtnenviar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jBtnenviarActionPerformed(evt);
}
});
jComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40" }));
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(30, 30, 30)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jlblcarne)
.addComponent(jlbltemp)
.addComponent(jlblingrese)))
.addGroup(layout.createSequentialGroup()
.addGap(52, 52, 52)
.addComponent(jBtnimpri))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(jlbldes)
.addGap(86, 86, 86)))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(35, 35, 35)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jCheckBox1)
.addComponent(jCheckBox2))
.addGap(48, 48, 48)))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 73, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jBtnenviar)
.addComponent(jComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(137, 137, 137))))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(57, 57, 57)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jlblingrese)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(12, 12, 12)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jlbltemp))
.addGap(14, 14, 14)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jlbldes)
.addComponent(jCheckBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jCheckBox2, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jlblcarne))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 31, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jBtnimpri)
.addComponent(jBtnenviar))
.addGap(64, 64, 64))
);
pack();
}// </editor-fold>
private void jBtnenviarActionPerformed(java.awt.event.ActionEvent evt) {
String nombre;//se esta asignando una variable de tipo String o letras
Integer temperatura;//se esta asignando una varibale de tipo Integer o numerica
boolean deshidratado;//se esta asiganado una variable de tipo logica
boolean carné;
nombre=jTextField1.getText();//para campo de texto dando datos de tipo String
temperatura=Integer.parseInt(jComboBox.getSelectedItem().toString());
/**
* toString() pasa datos de Item a String
* parseInt() pasa datos de String a Integer
* getSelectedItem()es para el menu desplegable y devuelve datos de tipo String
*/
deshidratado=jCheckBox1.isSelected();
carné=jCheckBox2.isSelected();
if(temperatura >=39 && deshidratado==true && carné==true)
{
JOptionPane.showMessageDialog(null, " El paciente "+nombre+ " debe ser atendido de urgencia");
jBtnimpri.setEnabled(true);//se activa el boton imprimir
}
else
{
JOptionPane.showMessageDialog(null, " El paciente "+nombre+ " no necesita ser atendido de urgencia");
}
// TODO add your handling code here:
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(jHospital.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(jHospital.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(jHospital.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(jHospital.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new jHospital().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jBtnenviar;
private javax.swing.JButton jBtnimpri;
private javax.swing.JCheckBox jCheckBox1;
private javax.swing.JCheckBox jCheckBox2;
private javax.swing.JComboBox jComboBox;
private javax.swing.JTextField jTextField1;
private javax.swing.JLabel jlblcarne;
private javax.swing.JLabel jlbldes;
private javax.swing.JLabel jlblingrese;
private javax.swing.JLabel jlbltemp;
// End of variables declaration
}
2. Comprimido del Programa
No hay comentarios:
Publicar un comentario