//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();
}
}
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.