Selasa, 24 Januari 2012

BILANGAN FAKTORIAL

BILANGAN FAKTORIAL



 Dibawah Ini Source Code Dari Bilangan Faktorial :
------------------------------------------------------------------------------------------
Source Code

 /**
 *
 * @author latahzan
 */
public class Faktorial extends javax.swing.JFrame {

    /** Creates new form Faktorial */
    public Faktorial() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    //                           
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        cmdhitung = new javax.swing.JButton();
        cmdbatal = new javax.swing.JButton();
        cmdkeluar = new javax.swing.JButton();
        txtangka = new javax.swing.JTextField();
        txthasil = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        dalamkali = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setBackground(new java.awt.Color(51, 255, 204));

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel1.setText("Angka");
        jLabel1.addAncestorListener(new javax.swing.event.AncestorListener() {
            public void ancestorMoved(javax.swing.event.AncestorEvent evt) {
                jLabel1AncestorMoved(evt);
            }
            public void ancestorAdded(javax.swing.event.AncestorEvent evt) {
                jLabel1AncestorAdded(evt);
            }
            public void ancestorRemoved(javax.swing.event.AncestorEvent evt) {
            }
        });

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel2.setText("Hasil");
        jLabel2.addAncestorListener(new javax.swing.event.AncestorListener() {
            public void ancestorMoved(javax.swing.event.AncestorEvent evt) {
                jLabel2AncestorMoved(evt);
            }
            public void ancestorAdded(javax.swing.event.AncestorEvent evt) {
            }
            public void ancestorRemoved(javax.swing.event.AncestorEvent evt) {
            }
        });

        cmdhitung.setBackground(new java.awt.Color(0, 204, 204));
        cmdhitung.setForeground(new java.awt.Color(0, 0, 255));
        cmdhitung.setText("Hitung");
        cmdhitung.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdhitungActionPerformed(evt);
            }
        });

        cmdbatal.setBackground(new java.awt.Color(255, 51, 51));
        cmdbatal.setForeground(new java.awt.Color(51, 255, 51));
        cmdbatal.setText("Hapus");
        cmdbatal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdbatalActionPerformed(evt);
            }
        });

        cmdkeluar.setBackground(new java.awt.Color(255, 255, 0));
        cmdkeluar.setText("Keluar");
        cmdkeluar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdkeluarActionPerformed(evt);
            }
        });

        txtangka.setBackground(new java.awt.Color(204, 255, 255));
        txtangka.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtangkaActionPerformed(evt);
            }
        });

        txthasil.setBackground(new java.awt.Color(153, 255, 153));
        txthasil.setEditable(false);
        txthasil.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txthasilActionPerformed(evt);
            }
        });

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 18));
        jLabel3.setText("PERHITUNGAN FAKTORIAL");

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel4.setText("output");
        jLabel4.addAncestorListener(new javax.swing.event.AncestorListener() {
            public void ancestorMoved(javax.swing.event.AncestorEvent evt) {
                jLabel4AncestorMoved(evt);
            }
            public void ancestorAdded(javax.swing.event.AncestorEvent evt) {
            }
            public void ancestorRemoved(javax.swing.event.AncestorEvent evt) {
            }
        });

        dalamkali.setEditable(false);

        jLabel5.setText("By : Rois & Trioo");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(58, 58, 58)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(cmdhitung)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2)
                            .addComponent(jLabel4))
                        .addGap(28, 28, 28)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(dalamkali)
                            .addComponent(txtangka)
                            .addComponent(txthasil)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(cmdbatal)
                                .addGap(27, 27, 27)
                                .addComponent(cmdkeluar)
                                .addGap(16, 16, 16)))))
                .addContainerGap(50, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(254, Short.MAX_VALUE)
                .addComponent(jLabel5)
                .addGap(35, 35, 35))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel3)
                .addGap(43, 43, 43)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txtangka, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txthasil, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(dalamkali, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 28, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cmdhitung)
                    .addComponent(cmdbatal)
                    .addComponent(cmdkeluar))
                .addGap(45, 45, 45)
                .addComponent(jLabel5)
                .addContainerGap())
        );

        pack();
    }//                         

private String fak(int input){
    int i=0;
    String hasil="";
            
    for (i=input;i>=1;i--){
    if (1=0);
    if (angka>1000)
    JOptionPane.showMessageDialog(rootPane, "Angka tidak boleh lebih dari 1000" );
    else
        txthasil.setText(String.valueOf(factorial));

dalamkali.setText(fak(angka));

        // TODO add your handling code here:
}                                         

    private void cmdkeluarActionPerformed(java.awt.event.ActionEvent evt) {                                          
int i = JOptionPane.showConfirmDialog(this, "Are You Sure!!!");
         if(i == JOptionPane.YES_OPTION){
        this.dispose();

        System.exit(0);        // TODO add your handling code here:
    }                                         

    }
    private void cmdbatalActionPerformed(java.awt.event.ActionEvent evt) {                                         
txtangka.setText("");
txthasil.setText("");
dalamkali.setText("");
txtangka.requestFocus();
        // TODO add your handling code here:
    }                                        

    private void txtangkaActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
    }                                        

    private void txthasilActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
    }                                        

    private void jLabel1AncestorAdded(javax.swing.event.AncestorEvent evt) {                                      
        // TODO add your handling code here:
    }                                     

    private void jLabel1AncestorMoved(javax.swing.event.AncestorEvent evt) {                                      
        // TODO add your handling code here:
    }                                     

    private void jLabel2AncestorMoved(javax.swing.event.AncestorEvent evt) {                                      
        // TODO add your handling code here:
    }                                     

    private void jLabel4AncestorMoved(javax.swing.event.AncestorEvent evt) {                                      
        // TODO add your handling code here:
    }                                     

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Faktorial().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JButton cmdbatal;
    private javax.swing.JButton cmdhitung;
    private javax.swing.JButton cmdkeluar;
    private javax.swing.JTextField dalamkali;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JTextField txtangka;
    private javax.swing.JTextField txthasil;
    // End of variables declaration                   

}


-----------------------------------------------------------------------------------------
 Hasilnya Dibawah Ini :

Tidak ada komentar:

Posting Komentar