I am doing a GUI check writer program, I want to ask how do you use the number 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
Code:
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" + "\n");
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));
}
}