Bienvenidos a un nuevo curso. Ahora estoy en el ciclo de grado superior: Desarrollo de aplicaciones multiplataforma. Y voy a ser parte del experimento de la formación dual. Estaré haciendo practicas durante un año, y a la vez finalizando la formación.

Deseadme suerte.

jueves, 17 de marzo de 2016

Convertidor en Java

0

Mientras intento sacar tiempo para recuperar todos los apuntes y ejercicios perdidos. Intentare mantenerme esta vez, mas al día con la clase. Ultimo trimestre, ultimo empujón. Animo a  todos.
Como no se explicarme muy bien, he ido haciendo capturas, y os paso el código.


















Código Completo:
*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package convertidor;

/**
 *
 * @author alumno
 */
public class Frame1 extends javax.swing.JFrame {

    /**
     * Creates new form Frame1
     */
    public Frame1() {
        initComponents();
    }

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

        MessageBox = new javax.swing.JDialog();
        jLabel4 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        MessageBox2 = new javax.swing.JDialog();
        jLabel5 = new javax.swing.JLabel();
        jButton2 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        txtEuros = new javax.swing.JTextField();
        txtDolares = new javax.swing.JTextField();
        btnConvertir = new javax.swing.JButton();
        btnConvertir2 = new javax.swing.JButton();

        jLabel4.setFont(new java.awt.Font("Dialog", 0, 14)); // NOI18N
        jLabel4.setText("La caja de textos euros esta vacia");

        jButton1.setText("Aceptar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout MessageBoxLayout = new javax.swing.GroupLayout(MessageBox.getContentPane());
        MessageBox.getContentPane().setLayout(MessageBoxLayout);
        MessageBoxLayout.setHorizontalGroup(
            MessageBoxLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(MessageBoxLayout.createSequentialGroup()
                .addGroup(MessageBoxLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(MessageBoxLayout.createSequentialGroup()
                        .addGap(25, 25, 25)
                        .addComponent(jLabel4))
                    .addGroup(MessageBoxLayout.createSequentialGroup()
                        .addGap(100, 100, 100)
                        .addComponent(jButton1)))
                .addContainerGap(31, Short.MAX_VALUE))
        );
        MessageBoxLayout.setVerticalGroup(
            MessageBoxLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(MessageBoxLayout.createSequentialGroup()
                .addGap(35, 35, 35)
                .addComponent(jLabel4)
                .addGap(18, 18, 18)
                .addComponent(jButton1)
                .addContainerGap(20, Short.MAX_VALUE))
        );

        jLabel5.setFont(new java.awt.Font("Dialog", 0, 14)); // NOI18N
        jLabel5.setText("Las casillas estan vacías");

        jButton2.setText("Aceptar");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout MessageBox2Layout = new javax.swing.GroupLayout(MessageBox2.getContentPane());
        MessageBox2.getContentPane().setLayout(MessageBox2Layout);
        MessageBox2Layout.setHorizontalGroup(
            MessageBox2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(MessageBox2Layout.createSequentialGroup()
                .addGroup(MessageBox2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(MessageBox2Layout.createSequentialGroup()
                        .addGap(45, 45, 45)
                        .addComponent(jLabel5))
                    .addGroup(MessageBox2Layout.createSequentialGroup()
                        .addGap(89, 89, 89)
                        .addComponent(jButton2)))
                .addContainerGap(45, Short.MAX_VALUE))
        );
        MessageBox2Layout.setVerticalGroup(
            MessageBox2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(MessageBox2Layout.createSequentialGroup()
                .addContainerGap(44, Short.MAX_VALUE)
                .addComponent(jLabel5)
                .addGap(18, 18, 18)
                .addComponent(jButton2)
                .addGap(36, 36, 36))
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Calculadora Conversora");

        jLabel1.setFont(new java.awt.Font("Dialog", 0, 24)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(51, 0, 153));
        jLabel1.setText("Calculadora");

        jLabel2.setText("Euros");

        jLabel3.setText("Dólares");

        txtEuros.setBackground(new java.awt.Color(255, 204, 255));

        txtDolares.setBackground(new java.awt.Color(204, 255, 204));

        btnConvertir.setText("Convertir");
        btnConvertir.setToolTipText("Convierte de Euros a Dólares");
        btnConvertir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnConvertirActionPerformed(evt);
            }
        });

        btnConvertir2.setText("Convertir completo");
        btnConvertir2.setToolTipText("Convierte en ambos sentidos");
        btnConvertir2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnConvertir2ActionPerformed(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()
                .addGap(21, 21, 21)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(txtEuros, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(59, 59, 59)
                                .addComponent(jLabel3)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(txtDolares, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(btnConvertir))))
                .addContainerGap(31, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(btnConvertir2)
                .addGap(183, 183, 183))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addComponent(jLabel1)
                .addGap(29, 29, 29)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel2)
                        .addComponent(txtEuros, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(txtDolares, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(28, 28, 28)
                        .addComponent(btnConvertir)))
                .addGap(18, 18, 18)
                .addComponent(btnConvertir2)
                .addContainerGap(25, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>                        
    //boton convertir todo
    private void btnConvertir2ActionPerformed(java.awt.event.ActionEvent evt) {                                              

        if(txtEuros.getText().compareTo("")==0 && txtDolares.getText().compareTo("")==0)
        {
            //arrojamos un mensaje
            MessageBox2.setVisible(true);
            MessageBox2.setSize(250,150);
        }
        else if(txtEuros.getText().compareTo("")!=0)
        {
            double euros=Double.parseDouble(txtEuros.getText());
            double dolares=euros*1.3194;
            txtDolares.setText(Double.toString(dolares));
        }
        else
        {
            double dolares=Double.parseDouble(txtDolares.getText());
            double euros=dolares/1.3194;
            txtEuros.setText(Double.toString(euros));
        }
    }                                             
    //boton convertir
    private void btnConvertirActionPerformed(java.awt.event.ActionEvent evt) {                                             

        if(txtEuros.getText().compareTo("")==0)
        {
            //arrojamos un mensaje
            MessageBox.setVisible(true);
            MessageBox.setSize(300,150);
        }
        else
        {
            double euros=Double.parseDouble(txtEuros.getText());
            double dolares=euros*1.3194;
            txtDolares.setText(Double.toString(dolares));
        }
    }                                            
    //Boton aceptar del messageBox
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        MessageBox.dispose();
    }                                        

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        MessageBox2.dispose();
    }                                        

    /**
     * @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(Frame1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Frame1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Frame1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Frame1.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 Frame1().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JDialog MessageBox;
    private javax.swing.JDialog MessageBox2;
    private javax.swing.JButton btnConvertir;
    private javax.swing.JButton btnConvertir2;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JTextField txtDolares;
    private javax.swing.JTextField txtEuros;
    // End of variables declaration                   
}


Related Posts:

  • Examen de programación I 1.- Calculadora mi ejercicio (4.5 de 5 puntos debido a que no controle errores(no se pude dividir por cero) ni trabaje con decimales). usin… Read More
  • Convertidor en Java Mientras intento sacar tiempo para recuperar todos los apuntes y ejercicios perdidos. Intentare mantenerme esta vez, mas al día con la clase. Ultimo … Read More
  • Editor etiquetas A Continuación os pongo el código completo. Como en las imágenes esta todo bien comentado y marcado. … Read More
  • Examen de programación II Resultado profesor (5 pnts. En el ejercicio se sobreescribe. No se modifica o elimina. Tengo mis dudas si eso se practica en las grandes empresas, au… Read More
  • Calculadora 1 A Continuación os pongo el código completo. Como en las imágenes esta todo bien comentado y ma… Read More

0 comentarios:

Publicar un comentario

Etiquetas actuales

BD (67) DEF (64) PROG (64) SQL (44) Java (29) PRACTICAS (20) php (18) DI (16) PRESTASHOP (16) PROGRAMACIÓN WEB (16) HTML (13) SGE (12) ERP (9) CONSULTAS (8) css (8) Linux (5) XML (5) Android (4) PDM (4) C (3) NetBeans (3) PSP (3) SMARTY (3) comandos (3) HOOK (2) POST (2) XSD (2) cURL (2) JS (1) MEDIA-QUERYS (1) PDO (1) RESPONSIVE (1) TPL (1) TRADUCCIÓN (1) app_inventor (1)

Todas las etiquetas

EJER (78) BD (67) DEF (64) PROG (64) SQL (44) c# (40) Programación (39) Ficheros (36) Java (29) bases de datos (21) PRACTICAS (20) lenguajes de marcas (19) AD (18) Entorno de desarrollo (18) php (18) PROCEDIMIENTOS (17) DI (16) FORM (16) PRESTASHOP (16) PROGRAMACIÓN WEB (16) lenguaje C (16) E/R (14) HTML (13) SGE (12) Sistemas informáticos (10) ERP (9) CONSULTAS (8) TRANSACCIONES (8) TRIGGER (8) VISUAL BASIC (8) css (8) FUNCIONES (7) html5 (6) Ada (5) EXAMEN (5) Linux (5) XML (5) estructuras (5) Android (4) DISEÑO (4) INTERFAZ (4) LOG (4) OpenBravo (4) PDM (4) ACTUALIZAR (3) C (3) DIAGRAMA (3) Directorios (3) NEW (3) NOR (3) NetBeans (3) OLD (3) PSP (3) SMARTY (3) comandos (3) css3 (3) AISLAMIENTOS (2) C++ (2) CONTROLERRORES (2) ELIMINAR (2) HOOK (2) INSERTAR (2) INST (2) MULTITABLA (2) POST (2) RECURSIVIDAD (2) SUBCONSULTAS (2) VISTAS (2) XSD (2) cURL (2) punteros (2) AJENA (1) BLOQUEOS (1) Byte (1) CREACION (1) CRM (1) Configuración (1) Controles (1) Datos (1) GOTFOCUS (1) IMAGENES (1) INDICES (1) JS (1) Lenght (1) MEDIA-QUERYS (1) Mingw (1) MonoDeveloped (1) OPTIMISTA (1) PDO (1) PESIMISTA (1) RESPONSIVE (1) SPEAK (1) Scanner (1) Serializacion (1) Streams (1) System (1) TPL (1) TRADUCCIÓN (1) USUARIOS (1) UseSystemPasswordChar (1) app_inventor (1) char (1) examenes (1) libreoffice (1) make (1) redes (1)