package com.company;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Scanner;
public class Main {
Main()
{
JFrame.setDefaultLookAndFeelDecorated(true);
// Creating a new frame using JFrame
JFrame f = new JFrame("BSIT Currency Converter");
//two labels
JLabel l1, l2;
// Creating two text fields.
// One for peso and one for dollar
JTextField t1, t2;
// Creating three buttons
JButton b1, b2, b3;
// Naming the labels and setting
l1 = new JLabel("PH Peso:");
l1.setBounds(40, 40, 60, 30);
l2 = new JLabel("US Dollar:");
l2.setBounds(170, 40, 60, 30);
// Initializing the text fields with
// 0 by default and setting the
// bounds for the text fields
t1 = new JTextField("0");
t1.setBounds(100, 40, 60, 30);
t2 = new JTextField("0");
t2.setBounds(250, 40, 100, 30);
// Creating a button for Peso to Dollar,
// one button for the dollar
// and one button to close
// and setting the bounds
b1 = new JButton("Peso to Dollar");
b1.setBounds(40, 80, 155, 20);
b2 = new JButton("Dollar to Peso");
b2.setBounds(190, 80, 160, 20);
b3 = new JButton("Close");
b3.setBounds(150, 150, 100, 30);
// Adding action listener
b1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
// Converting to double
double d
= Double.parseDouble(t1.getText());
// Converting peso to dollars
double d1 = (d / 51.28);
// Getting the string value of the
// calculated value
String str1 = String.valueOf(d1);
// Placing it in the text box
t2.setText(str1);
}
});
// Adding action listener
b2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
// Converting to double
double d2
= Double.parseDouble(t2.getText());
// converting Dollars to peso
double d3 = (d2 * 51.28);
// Getting the string value of the
// calculated value
String str2 = String.valueOf(d3);
// Placing it in the text box
t1.setText(str2);
}
});
// Action listener to close the form
b3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
f.dispose();
}
});
// Default method for closing the frame
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
// Adding the created objects
// to the form
f.add(l1);
f.add(t1);
f.add(l2);
f.add(t2);
f.add(b1);
f.add(b2);
f.add(b3);