sábado, 1 de septiembre de 2012


2.TALLER DE PROGRAMACIÓN

PROGRAMA QUE DETERMINA SI UNA PERSONA ES MAYOR DE EDAD


1. CÓDIGO FUENTE (NETBEANS):


package paqEdad;

import javax.swing.JOptionPane;

/**
 *
 * @author moises
 */
public class jEdad extends javax.swing.JFrame {

    /**
     * Creates new form jEdad
     */
    public jEdad() {
        initComponents();
        JOptionPane.showMessageDialog(null, "***BIENVENIDO ESTO ES UN CENSO RUTINARIO***");
    }

    /**
     * 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() {

        jBtnEdad = new javax.swing.JButton();
        jTxtEdad = new javax.swing.JTextField();
        jLblEdad = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jBtnEdad.setText("Enviar");
        jBtnEdad.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtnEdadActionPerformed(evt);
            }
        });

        jLblEdad.setText("INGRESE SU EDAD");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(159, 159, 159)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLblEdad, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBtnEdad, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTxtEdad, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(134, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(53, Short.MAX_VALUE)
                .addComponent(jLblEdad, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(26, 26, 26)
                .addComponent(jTxtEdad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(31, 31, 31)
                .addComponent(jBtnEdad)
                .addGap(124, 124, 124))
        );

        pack();
    }// </editor-fold>

   private void jBtnEdadActionPerformed(java.awt.event.ActionEvent evt) {                                         
   Integer num=0; //Definimos una variable de tipo entero
   num=Integer.parseInt(jTxtEdad.getText());
   //convierto de letras a numeros
   if(num>17) //Condicion
   {//inicio
   JOptionPane.showMessageDialog(null, "Usted es Mayor de Edad");
   } //fin 
   else
   {//inicio
   JOptionPane.showMessageDialog(null,"Usted es menor de Edad");
   }//fin  
        
               
        // 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(jEdad.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(jEdad.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(jEdad.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(jEdad.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 jEdad().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify
    private javax.swing.JButton jBtnEdad;
    private javax.swing.JLabel jLblEdad;
    private javax.swing.JTextField jTxtEdad;
    // End of variables declaration
}


2. COMPRIMIDO DEL PROGRAMA


No hay comentarios:

Publicar un comentario