Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a JavaFX program that converts US dollars into Canadian dollars, as shown

ID: 3803516 • Letter: W

Question

Write a JavaFX program that converts US dollars into Canadian dollars, as shown in the following figure. The program lets the user enter an amount in US dollars and display it equivalent value in Canadian dollars when clicking the Convert button. One U.S. dollar is approximately 1.5 Canadian dollars. Put the labels and textfields in a GridPane and make the Canadian Dollars field non-editable. Don't worry about making the formatting perfect. You may omit the Java import statements and the main method to save time. (15 pts)

Convert Dollars Canadian Dolla lars to Canadian Dollars 15 Conve

Explanation / Answer

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

import java.text.DecimalFormat;

public class usDollar extends JFrame

{

JLabel usLab, canLab;

JTextField usTextF,canTextF ;

JButton calculateBut, exitBut;

CalculateButtonHandler calculateHand;

ExitButtonHandler exitHand;

public usDollar()

{

usLab = new JLabel("US Dollar", SwingConstants.LEFT);

usTextF = new JTextField(10);

canLab = new JLabel("Can Dollar", SwingConstants.LEFT);

canTextF = new JTextField(10);     

calculateBut = new JButton("Calculate");

calculateHand = new CalculateButtonHandler();

calculateBut.addActionListener(calculateHand);

exitBut = new JButton("Exit");

exitHand = new ExitButtonHandler();

exitBut.addActionListener(exitHand);

setTitle("Final");

setLayout (new GridLayout(3, 3));

Container pane = getContentPane();

pane.add(usLab);

pane.add(canLab);

pane.add(usTextF);

pane.add(canTextF);

pane.add(calculateBut);

pane.add(exitBut);

canTextF.setEditable(false);

setBounds(350, 350, 350, 350);

setDefaultCloseOperation(EXIT_ON_CLOSE);

setVisible(true);

}

private class CalculateButtonHandler implements ActionListener

{

public void actionPerformed(ActionEvent e)

{

int usDollar, canDollar;

double usDoll, canDoll;

usDollar = Integer.parseInt(usTextF.getText());

canDoll = usDollar * 1.5 ;

DecimalFormat money = new DecimalFormat("$0.00");

canTextF.setText(money.format(canDoll));

}

}

private class ExitButtonHandler implements ActionListener {

public void actionPerformed(ActionEvent e)

{

System.exit(0);

}

}             

public static void main(String args[])

{

usDollar Object = new usDollar();

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote