Laman

Selasa, 15 Februari 2011

Program Terbilang by BlackAnt "JAVA"

karna uda ngga ada kerjaan di kosan maka saya membuat program ini untuk menghabiskan waktu.

program ini cukup simpel yaitu agan tinggal masukan nilai kedalam textfield dan tekak button terbilang maka hasil dari penerjemahan akan ditampilkan di textarea.






dan berikut ini programnya...


<<<<<<<<<<++++++++++>>>>>>>>>>

import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.event.*;
import java.awt.event.ActionEvent;
public class coba0100{
   
    public static JFrame frame = new JFrame();
    public static JTextArea area = new JTextArea(50,100);
    public static JTextField textfield = new JTextField(30);
    public static String huruf="";
   
    public coba0100(){
        frame.setTitle("Program Terbilang By BlackAnt999");
        frame.setSize(405,210);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setLocationRelativeTo(null);
    }
    public static void terbilang(long x){
        if(x==1){
        huruf=""+huruf+"satu ";
        }else if(x==2){
        huruf=""+huruf+"dua ";
        }else if(x==3){
        huruf=""+huruf+"tiga ";
        }else if(x==4){
        huruf=""+huruf+"empat ";
        }else if(x==5){
        huruf=""+huruf+"lima ";
        }else if(x==6){
        huruf=""+huruf+"enam ";
        }else if(x==7){
        huruf=""+huruf+"tujuh ";
        }else if(x==8){
        huruf=""+huruf+"delapan ";
        }else if(x==9){
        huruf=""+huruf+"sembilan ";
        }else if(x==10){
        huruf=""+huruf+"sepuluh ";
        }else if(x==11){
        huruf=""+huruf+"sebelas ";
        }else if(x>=12&&x<=19){
        terbilang(x%10);
        huruf=""+huruf+"belas ";
        }else if(x>=20&&x<=99){
        terbilang(x/10);
        huruf=""+huruf+"puluh ";
        terbilang(x%10);
        }else if(x>=100&&x<=199){
        huruf=""+huruf+"seratus ";
        terbilang(x-100);
        }else if(x>=200&&x<=999){
        terbilang(x/100);
        huruf=""+huruf+"ratus ";
        terbilang(x%100);
        }else if(x>=1000&&x<=1999){
        huruf=""+huruf+"seribu ";
        terbilang(x-100);
        }else if(x>=2000&&x<=999999){
        terbilang(x/1000);
        huruf=""+huruf+"ribu ";
        terbilang(x%1000);
        }else if(x>=1000000&&x<=999999999){
        terbilang(x/1000000);
        huruf=""+huruf+"juta ";
        terbilang(x%1000000);
        }else if(x>=1000000000&&x<=2147483647){
        terbilang(x/1000000000);
        huruf=""+huruf+"miliar ";
        terbilang(x%1000000000);
        }
    }
    public static void main (String [] args){
       
        coba0100 coba = new coba0100();
       
        JPanel panel = new JPanel();
        panel.setLayout(null);
       
        textfield.setBounds(10,10,370,30);
        panel.add(textfield);
       
        JButton button = new JButton("Terbilang");
        button.setBounds(120,50,160,30);
        panel.add(button);
        button.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae){
                huruf="";
                try{
                    String x=textfield.getText();
                    long bilangan = Long.parseLong(x);
                    terbilang(bilangan);
                }
                catch (Exception e) {
                    huruf=""+e;
                }
               
                area.setText(""+huruf);
            }
        });
       
        area.setLineWrap(true);
        area.setWrapStyleWord(true);
        area.setBounds(10,90,370,70);
        panel.add(area);
       
        frame.add(panel, BorderLayout.CENTER);
        frame.setVisible(true);
    }
}

<<<<<<<<<<++++++++++>>>>>>>>>>

0 komentar:

Posting Komentar