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

I am doing a GUI check writer program, I want to ask how do you using the amount

ID: 3889614 • Letter: I

Question

I am doing a GUI check writer program, I want to ask how do you using the amount that the user type, and convert it into words in a JLabel?

For example: if I type 1435.56 the output would be one thousand four hundred thirty five dollars fifty six cents

and this is what I have right now

package CheckWriter;

import java.awt.*;

import java.awt.event.*;

import java.text.DecimalFormat;

import javax.swing.*;

public class CheckPanel extends JPanel{

  

   private JLabel amountLabel, nameLabel, orderpayLabel,bankLabel,fmtAmountLabel;

   private JTextField name;

   String appli_Name;

   String bank_amount;

   private JTextField amount;

  

   public CheckPanel(){

      

       setLayout (new FlowLayout());

      

      

       nameLabel = new JLabel("Name:");

       nameLabel.setLocation(10,10);;

       add(nameLabel);

      

       name = new JTextField(7);

       name.setLocation(20,10);

       add(name);

      

       amountLabel = new JLabel("Check Amount:");

       amountLabel.setLocation(30,10);

       add(amountLabel);

      

       amount = new JTextField(7);

       amount.setLocation(40,10);

       add(amount);

      

       orderpayLabel = new JLabel("");

       orderpayLabel.setLocation(15, 30);

       add(orderpayLabel);

      

       bankLabel = new JLabel(" Frost Banking" + " ");

       bankLabel.setLocation(45,25);

       add(bankLabel);

      

       fmtAmountLabel = new JLabel("");

       fmtAmountLabel.setLocation(45, 35);

       add(fmtAmountLabel);

event e = new event();

       name.addActionListener(e);

       amount.addActionListener(e);

}

private class event implements ActionListener{

       public void actionPerformed(ActionEvent e) {

      

           appli_Name = name.getText();

           orderpayLabel.setText("Pay to the order of :" +" " + appli_Name);

          

           bank_amount = amount.getText();

           double amount = Double.parseDouble(bank_amount);

           DecimalFormat formatter = new DecimalFormat("$###,###,###,###.##");

           fmtAmountLabel.setText(formatter.format(amount));

}

   }

Explanation / Answer

we have changed it

package CheckWriter;

import java.awt.*;

import java.awt.event.*;

import java.text.DecimalFormat;

import javax.swing.*;

public class CheckPanel extends JPanel{

  

private JLabel amountLabel, nameLabel, orderpayLabel,bankLabel,fmtAmountLabel;

private JTextField name;

String appli_Name;

String bank_amount;

private JTextField amount;

  

public CheckPanel(){

  

setLayout (new FlowLayout());

  

  

nameLabel = new JLabel("Name:");

nameLabel.setLocation(10,10);;

add(nameLabel);

  

name = new JTextField(7);

name.setLocation(20,10);

add(name);

  

amountLabel = new JLabel("Check Amount:");

amountLabel.setLocation(30,10);

add(amountLabel);

  

amount = new JTextField(7);

amount.setLocation(40,10);

add(amount);

  

orderpayLabel = new JLabel("");

orderpayLabel.setLocation(15, 30);

add(orderpayLabel);

  

bankLabel = new JLabel(" Frost Banking" + " ");

bankLabel.setLocation(45,25);

add(bankLabel);

  

fmtAmountLabel = new JLabel("");

fmtAmountLabel.setLocation(45, 35);

add(fmtAmountLabel);

event e = new event();

name.addActionListener(e);

amount.addActionListener(e);

}

private class event implements ActionListener{

public void actionPerformed(ActionEvent e) {

  

appli_Name = name.getText();

orderpayLabel.setText("Pay to the order of :" +" " + appli_Name);

  

bank_amount = amount.getText();

double amount = Double.parseDouble(bank_amount);

DecimalFormat formatter = new DecimalFormat("$###,###,###,###.##");

fmtAmountLabel.setText(formatter.format(amount));

}

}