Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package dinero;
- import java.awt.FlowLayout;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.text.DecimalFormat;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JOptionPane;
- import javax.swing.JTextField;
- public class Dinero extends JFrame implements ActionListener{
- private JButton dolar;
- private JButton real;
- private JButton euro;
- private JTextField jd;
- private JTextField jf;
- private JLabel titulo;
- public Dinero(){
- setLayout(new FlowLayout(FlowLayout.CENTER,10,20));
- titulo=new JLabel("CONVERSION DE MONEDAS (DE PESO CHILENO A REAL, DOLAR Y EURO)");
- dolar=new JButton("Dolar");
- euro=new JButton("Euro");
- real=new JButton("Real");
- jd=new JTextField(50);
- jf=new JTextField(50);
- add(titulo);
- add(jd);
- euro.addActionListener(this);
- dolar.addActionListener(this);
- real.addActionListener(this);
- add(euro);
- add(dolar);
- add(real);
- add(jf);
- setVisible(true);
- setSize(600,300);
- setDefaultCloseOperation(EXIT_ON_CLOSE);
- }
- @Override
- public void actionPerformed(ActionEvent e){
- float ex=0,ff=0,mEuro=752,mDolar=672,mReal=205;
- DecimalFormat df=new DecimalFormat("0.00");
- try{
- if(e.getSource()==euro){
- ff=Float.parseFloat(jd.getText());
- ex=ff/mEuro;
- jf.setText(String.valueOf(df.format(ex)));
- }
- if(e.getSource()==dolar){
- ff=Float.parseFloat(jd.getText());
- ex=ff/mDolar;
- jf.setText(String.valueOf(df.format(ex)));
- }
- if(e.getSource()==real){
- ff=Float.parseFloat(jd.getText());
- ex=ff/mReal;
- jf.setText(String.valueOf(df.format(ex)));
- }
- }catch(NumberFormatException nfe){
- jd.setText("");
- jf.setText("");
- JOptionPane.showMessageDialog(null,"El valor ingresado no es un numero entero","Error",JOptionPane.ERROR_MESSAGE);
- }
- }
- public static void main(String[] args) {
- Dinero d=new Dinero();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement