9/19/10



Converting Peso-Dollar and Vice- versa (Java Code)

9/19/2010

//Conversion: $1=Php 46.00

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class PesoDollar extends JFrame{

    private JTextField pesoTF, dollarTF;
    private JLabel pesoL, dollarL;
   
    private static final int JFRAME_WIDTH = 400;
    private static final int JFRAME_LENGTH = 100;

    private CalculatePesoTextField cpHandler;
    private CalculateDollarTextField cdHandler;

    public PesoDollar(){       
       
        super("PESO-DOLLAR CONVERTER");       
        pesoL = new JLabel("Amount of Peso:", SwingConstants.RIGHT);
        dollarL = new JLabel("Amount of Dollar: ", SwingConstants.RIGHT);
   
        pesoTF = new JTextField(10);
        dollarTF = new JTextField(10);
       
        Container con = getContentPane();

        con.add(pesoL);
        con.add(pesoTF);
       
        con.add(dollarL);
        con.add(dollarTF);
       
        con.setLayout(new GridLayout(2,2));
       
        cpHandler = new CalculatePesoTextField();   
        pesoTF.addActionListener(cpHandler);

        cdHandler = new CalculateDollarTextField();   
        dollarTF.addActionListener(cdHandler);

        setSize(JFRAME_WIDTH, JFRAME_LENGTH);
        setVisible(true);
        setDefaultCloseOperation(EXIT_ON_CLOSE);


    }

    public class CalculatePesoTextField implements ActionListener{

        public void actionPerformed(ActionEvent e){
   
            double peso = Double.parseDouble(pesoTF.getText());
            double answer= (peso/46);
            dollarTF.setText("$" + "" + answer);
       
        }

    }

    public class CalculateDollarTextField implements ActionListener{

        public void actionPerformed(ActionEvent e){
   
            double dollar = Double.parseDouble(dollarTF.getText());
            double answer= (dollar * 46);
            pesoTF.setText("Php" + "" + answer);
       
        }

    }

    public static void main(String[] args){
       
        setDefaultLookAndFeelDecorated(true);

        PesoDollar pesodollarObject = new PesoDollar();
   
    }

}



Your thoughts about this post? Leave a commment now.

Posted by

AndyFGo : A place for Pinoy Music News. Lyrics. Music Videos. Pinoy Movie/Foreign Trailers. OPM.

 

© 2013 andyfgo. All rights reserved. Designed by Templateism. Powered by Blogger
Protected by Copyscape DMCA Takedown Notice Violation Search

Back To Top