Rabu, 09 November 2011

SourceCode Bilangan Prima

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

 * frameprima.java

 *

 * Created By Latahzan

 */

package finisingdaa;

import javax.swing.JOptionPane;

 * @author LA TAHZAN

 */

public class frameprima extends javax.swing.JFrame {

    public frameprima() {

        initComponents();

    }

    /** Mencari Bilangan

    private void initComponents() {

        texthasil = new javax.swing.JButton();

        jButton1 = new javax.swing.JButton();

        jLabel1 = new javax.swing.JLabel();

        jLabel2 = new javax.swing.JLabel();

        jLabel3 = new javax.swing.JLabel();

        jButton2 = new javax.swing.JButton();

        isiinputan = new javax.swing.JTextField();

        outputan = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        texthasil.setBackground(new java.awt.Color(153, 0, 153));

        texthasil.setFont(new java.awt.Font("Ubuntu", 1, 12));

        texthasil.setForeground(new java.awt.Color(255, 255, 0));

        texthasil.setText("hasil");

        texthasil.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {

                texthasilActionPerformed(evt);

            }

        });

        jButton1.setBackground(new java.awt.Color(0, 255, 255));

        jButton1.setFont(new java.awt.Font("Ubuntu", 1, 12));

        jButton1.setForeground(new java.awt.Color(51, 51, 255));

        jButton1.setText("Hapus");

        jButton1.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {

                jButton1ActionPerformed(evt);

            }

        });

        jLabel1.setFont(new java.awt.Font("Franklin Gothic Medium", 1, 14));

        jLabel1.setText("PROGRAM BILANGAN PRIMA");

        jLabel2.setFont(new java.awt.Font("Ubuntu", 1, 12));

        jLabel2.setText("Inputan");

        jLabel3.setFont(new java.awt.Font("Ubuntu", 1, 12));

        jLabel3.setText("Output");

        jButton2.setBackground(new java.awt.Color(0, 255, 51));

        jButton2.setFont(new java.awt.Font("Ubuntu", 1, 12));

        jButton2.setForeground(new java.awt.Color(51, 51, 255));

        jButton2.setText("Keluar");

        jButton2.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {

                jButton2ActionPerformed(evt);

            }

        });

        isiinputan.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {

                isiinputanActionPerformed(evt);

            }

        });

        outputan.setBackground(new java.awt.Color(51, 255, 51));

        outputan.setEditable(false);

        outputan.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        outputan.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {

                outputanActionPerformed(evt);

            }

        });

        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(28, 28, 28)

                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

                    .addComponent(jLabel3)

                    .addComponent(jLabel2))

                .addGap(26, 26, 26)

                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

                    .addGroup(layout.createSequentialGroup()

                        .addComponent(texthasil, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)

                        .addGap(18, 18, 18)

                        .addComponent(jButton1)

                        .addGap(18, 18, 18)

                        .addComponent(jButton2))

                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)

                        .addComponent(outputan, javax.swing.GroupLayout.Alignment.LEADING)

                        .addComponent(isiinputan, javax.swing.GroupLayout.Alignment.LEADING)

                        .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))

                .addContainerGap(77, Short.MAX_VALUE))

        );

        layout.setVerticalGroup(

            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

            .addGroup(layout.createSequentialGroup()

                .addContainerGap()

                .addComponent(jLabel1)

                .addGap(20, 20, 20)

                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

                    .addComponent(jLabel2)

                    .addComponent(isiinputan, 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(jLabel3)

                    .addComponent(outputan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))

                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 27, Short.MAX_VALUE)

                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

                    .addComponent(texthasil)

                    .addComponent(jButton1)

                    .addComponent(jButton2))

                .addGap(42, 42, 42))

        );

        pack();

    }// 

   private boolean primaX(int p) {

boolean b = true;

if(p < 2) b = false;

if(p > 2) {

for(int i = 2; i <= (p / 2); i++) {

if(p % i == 0) {

b = false;

break;

}

}

}

return b;

}

    private void texthasilActionPerformed(java.awt.event.ActionEvent evt) {                                         

String numStr =isiinputan.getText();

int numInt = Integer.parseInt(numStr);

String cek = "Bilangan Prima";

if(!primaX(numInt)) cek = "Bukan Bilangan Prima";

outputan.setText(cek);

// TODO add your handling code here:

    }                                        

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        

isiinputan.setText("");

outputan.setText("");

isiinputan.requestFocus();

        // TODO add your handling code here:

    }                                       

    private void jButton2ActionPerformed(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 isiinputanActionPerformed(java.awt.event.ActionEvent evt) {                                          

        

        // TODO add your handling code here:

    }                                         

    private void outputanActionPerformed(java.awt.event.ActionEvent 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 frameprima().setVisible(true);

            }

        });

    }

    // Variables declaration - do not modify

    private javax.swing.JTextField isiinputan;

    private javax.swing.JButton jButton1;

    private javax.swing.JButton jButton2;

    private javax.swing.JLabel jLabel1;

    private javax.swing.JLabel jLabel2;

    private javax.swing.JLabel jLabel3;

    private javax.swing.JTextField outputan;

    private javax.swing.JButton texthasil;

    // End of variables declaration

    private boolean prima(int numInt) {

        throw new UnsupportedOperationException("Not yet implemented");

    }

}

-------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------

Tapi Masih Dalam Perbaikan Semoga bermanfaat bagi kita. Dan perbaian masih dalam proses secepatnya terima kasih :

1 komentar: