eto na po yung program ang problema hanggang 99 lang po ang na coconvert.. pano po ba pag convert ng 100 to 999,999 in words...
package com.Converter;
import javax.swing.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.JComponent;
import java.awt.Component;
import java.awt.event.ActionListener;
public class Convert extends JFrame implements ActionListener{
String string;
String st1[] = { "", "One", "Two", "Three", "Four", "Five", "Six", "Seven",
"Eight", "Nine", };
String st2[] = { "Hundred", "Thousand", "Hundred", "" };
String st3[] = { "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen",
"Fifteen", "Sixteen", "Seventeen", "Eighteen", "Ninteen", };
String st4[] = { "Twenty", "Thirty", "Fourty", "Fifty", "Sixty", "Seventy",
"Eighty", "Ninety" };
protected JPanel panel;
protected JLabel label1;
protected JLabel label2;
protected JTextField textField;
protected JTextArea textArea;
protected JButton button;
protected JButton button1;
protected int num;
protected String words;
public Convert() {
super(" Converter");
setTitle("Number To Words");
setSize(380,300);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
panel = new JPanel();
panel.setLayout(null);
add(panel);
label1 = new JLabel("Number To Convert:");
label1.setBounds(20, 50, 150, 20);
panel.add(label1);
textField = new JTextField(20);
textField.setBounds(180, 50, 150, 25);
panel.add(textField);
textField.addActionListener(this);
label2 = new JLabel("Number In Words:");
label2.setBounds(20, 100, 150, 20);
panel.add(label2);
textArea = new JTextArea("3, 20");
textArea.setBounds(60, 150, 250, 50);
panel.add(textArea);
button = new JButton("Convert");
button.setBounds(30, 220, 100, 30);
panel.add(button);
button.addActionListener(this);
button1 = new JButton("Clear");
button1.setBounds(230, 220, 100, 30);
panel.add(button1);
button1.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == button1) {
textField.setText("");
textArea.setText("");
}
if (Integer.parseInt(textField.getText())>=999999){
JOptionPane.showMessageDialog(null,
"Error: Please enter the number between 0-999,999", "Error Massage",
JOptionPane.ERROR_MESSAGE);
}
if (e.getSource() == button) {
num = Integer.parseInt(textField.getText());
textArea.setText(String.valueOf(num ));
}
int n = 1;
int word;
string = "";
while (num != 0) {
switch
{
case 1:
word = num % 100;
pass(word);
if (num > 100 && num % 100 != 0) {
textArea.setText(" and ");
}
num /= 100;
break;
case 2:
word = num % 10;
if (word != 0) {
textArea.setText(" ");
textArea.setText(st2[0]);
textArea.setText(" ");
pass(word);
}
num/= 10;
break;
case 3:
word = num % 100;
if (word != 0) {
textArea.setText(st2[1]);
pass(word);
}
num /= 100;
break;
case 4:
word = num % 1000;
if (word != 0) {
textArea.setText(" ");
textArea.setText(st2[2]);
textArea.setText(" ");
pass(word);
}
num /= 1000;
break;
case 5:
word = num % 10000;
if (word != 0) {
textArea.setText(" ");
textArea.setText(st2[3]);
textArea.setText(" ");
pass(word);
}
num /= 10000;
break;
}
n++;
}
return;
}
private void pass(int num) {
int word, q;
if (num < 10) {
textArea.setText(st1[num]);
}
if (num > 19) {
word = num % 10;
if(num >99){
word = num %100;
}
else {
q = num / 10;
textArea.setText((st4[q - 2])+ st1[word]);
}
}
}
public static void main(String[] args){
SwingUtilities.invokeLater(new Runnable(){
public void run(){
Convert x = new Convert();
x.setVisible(true);
}
});
}
}