Advertisement
pablosotol

Dinero

Aug 27th, 2016
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.61 KB | None | 0 0
  1.  
  2. package dinero;
  3.  
  4. import java.awt.FlowLayout;
  5. import java.awt.event.ActionEvent;
  6. import java.awt.event.ActionListener;
  7. import java.text.DecimalFormat;
  8. import javax.swing.JButton;
  9. import javax.swing.JFrame;
  10. import javax.swing.JLabel;
  11. import javax.swing.JOptionPane;
  12. import javax.swing.JTextField;
  13.  
  14. public class Dinero extends JFrame implements ActionListener{
  15.    
  16.        private JButton dolar;
  17.        private JButton real;
  18.        private JButton euro;
  19.        private JTextField jd;
  20.        private JTextField jf;
  21.        private JLabel titulo;
  22.    
  23.        public Dinero(){
  24.        
  25.            setLayout(new FlowLayout(FlowLayout.CENTER,10,20));
  26.            titulo=new JLabel("CONVERSION DE MONEDAS (DE PESO CHILENO A REAL, DOLAR Y EURO)");
  27.            dolar=new JButton("Dolar");
  28.            euro=new JButton("Euro");
  29.            real=new JButton("Real");
  30.            jd=new JTextField(50);
  31.            jf=new JTextField(50);
  32.            add(titulo);
  33.            add(jd);
  34.            euro.addActionListener(this);
  35.            dolar.addActionListener(this);
  36.            real.addActionListener(this);
  37.            add(euro);
  38.            add(dolar);
  39.            add(real);
  40.            add(jf);
  41.            
  42.            setVisible(true);
  43.            setSize(600,300);
  44.            setDefaultCloseOperation(EXIT_ON_CLOSE);
  45.            
  46.      }
  47.        
  48.        @Override
  49.        public void actionPerformed(ActionEvent e){
  50.              
  51.            float ex=0,ff=0,mEuro=752,mDolar=672,mReal=205;
  52.            DecimalFormat df=new DecimalFormat("0.00");  
  53.    
  54.            try{
  55.               if(e.getSource()==euro){
  56.                  ff=Float.parseFloat(jd.getText());
  57.                  ex=ff/mEuro;
  58.                  jf.setText(String.valueOf(df.format(ex)));
  59.               }
  60.              
  61.               if(e.getSource()==dolar){
  62.                  ff=Float.parseFloat(jd.getText());
  63.                  ex=ff/mDolar;
  64.                  jf.setText(String.valueOf(df.format(ex)));
  65.               }
  66.              
  67.               if(e.getSource()==real){
  68.                  ff=Float.parseFloat(jd.getText());
  69.                  ex=ff/mReal;
  70.                  jf.setText(String.valueOf(df.format(ex)));
  71.                  
  72.               }
  73.            
  74.            }catch(NumberFormatException nfe){
  75.                   jd.setText("");
  76.                   jf.setText("");
  77.                   JOptionPane.showMessageDialog(null,"El valor ingresado no es un numero entero","Error",JOptionPane.ERROR_MESSAGE);
  78.                       }
  79.        }
  80.        
  81.  
  82.    
  83.    
  84.     public static void main(String[] args) {
  85.            Dinero d=new Dinero();
  86.     }
  87.    
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement