Vous êtes sur la page 1sur 5

/* * To change this template, choose Tools | Templates * and open the template in the editor.

*/ package tecnicaswillian; /** * * @author alunoifba */ public class conversor extends javax.swing.JFrame { /** * Creates new form conversor */ public conversor() { 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">//GEN-BEGIN:i nitComponents private void initComponents() { jPanel1 = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); jtreais = new javax.swing.JTextField(); jtresultado = new javax.swing.JTextField(); JcMoedas = new javax.swing.JComboBox(); jButton1 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jLabel1.setText("Valor em Reais"); jLabel2.setText("Moeda"); jLabel3.setText("Valor Convertido"); jtreais.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jtreaisActionPerformed(evt); } }); JcMoedas.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "D olar", "Pesos", "Euro", " " })); JcMoedas.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { JcMoedasActionPerformed(evt); } });

jButton1.setText("Limpar"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); jButton2.setText("OK"); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } }); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPan el1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment. LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLay out.Alignment.LEADING, false) .addGroup(jPanel1Layout.createSequentialGroup() .addContainerGap() .addGroup(jPanel1Layout.createParallelGroup(javax.swing. GroupLayout.Alignment.LEADING, false) .addGroup(jPanel1Layout.createSequentialGroup() .addComponent(jLabel3) .addGap(18, 18, 18) .addComponent(jtresultado)) .addGroup(jPanel1Layout.createSequentialGroup() .addGroup(jPanel1Layout.createParallelGroup(java x.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel1) .addComponent(jLabel2)) .addGap(36, 36, 36) .addGroup(jPanel1Layout.createParallelGroup(java x.swing.GroupLayout.Alignment.LEADING) .addComponent(jtreais, javax.swing.GroupLayo ut.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(JcMoedas, javax.swing.GroupLay out.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayou t.PREFERRED_SIZE))))) .addGroup(jPanel1Layout.createSequentialGroup() .addGap(25, 25, 25) .addComponent(jButton1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacem ent.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jButton2))) .addContainerGap(133, Short.MAX_VALUE)) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment. LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addContainerGap() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLay out.Alignment.BASELINE)

.addComponent(jLabel1) .addComponent(jtreais, javax.swing.GroupLayout.PREFERRED_SIZ E, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) ) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELA TED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLay out.Alignment.BASELINE) .addComponent(jLabel2) .addComponent(JcMoedas, javax.swing.GroupLayout.PREFERRED_SI ZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE )) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELA TED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLay out.Alignment.BASELINE) .addComponent(jLabel3) .addComponent(jtresultado, javax.swing.GroupLayout.PREFERRED _SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_S IZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELA TED, 81, Short.MAX_VALUE) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLay out.Alignment.BASELINE) .addComponent(jButton1) .addComponent(jButton2)) .addGap(61, 61, 61)) ); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentP ane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING ) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, jav ax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING ) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, jav ax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addContainerGap()) ); pack(); }// </editor-fold>//GEN-END:initComponents private void jtreaisActionPerformed(java.awt.event.ActionEvent evt) {//GEN-F IRST:event_jtreaisActionPerformed // TODO add your handling code here: }//GEN-LAST:event_jtreaisActionPerformed private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-

FIRST:event_jButton2ActionPerformed Float reais; String op; Float resultado; resultado=0f; reais=Float.valueOf(jtreais.getText()); op=String.valueOf(JcMoedas.getSelectedItem()); switch (op) { case "Dolar": resultado=reais/2.32f; break; case "Pesos": resultado=reais/0.40f; break; case "Euro": resultado=reais/3.28f; break; } jtresultado.setText(String.valueOf(resultado)); // TODO add your handling code here: }//GEN-LAST:event_jButton2ActionPerformed private void JcMoedasActionPerformed(java.awt.event.ActionEvent evt) {//GENFIRST:event_JcMoedasActionPerformed // TODO add your handling code here: }//GEN-LAST:event_JcMoedasActionPerformed private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GENFIRST:event_jButton1ActionPerformed jtreais.setText(""); jtresultado.setText(""); // TODO add your handling code here: }//GEN-LAST:event_jButton1ActionPerformed /** * @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 cod e (optional) "> /* If Nimbus (introduced in Java SE 6) is not available, stay with the d efault look and feel. * For details see http://download.oracle.com/javase/tutorial/uiswing/lo okandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIMana ger.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(conversor.class.getName()).log(ja va.util.logging.Level.SEVERE, null, ex);

} catch (InstantiationException ex) { java.util.logging.Logger.getLogger(conversor.class.getName()).log(ja va.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(conversor.class.getName()).log(ja va.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(conversor.class.getName()).log(ja va.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new conversor().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JComboBox JcMoedas; 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.JPanel jPanel1; private javax.swing.JTextField jtreais; private javax.swing.JTextField jtresultado; // End of variables declaration//GEN-END:variables }

Vous aimerez peut-être aussi