Notification

×

Iklan

Iklan

Source Code Program Java Menghitung Persegi Panjang Netbeans

Wednesday, July 29, 2020 | 09:51 WIB Last Updated 2020-07-29T02:51:33Z
Source Code Program Java Menghitung Persegi Panjang Netbeans
Source Code Program Java Menghitung Persegi Panjang Netbeans
KARAWANGPORTAL - Source Code Program Java menghitung persegi panjang dengan netbeans Hello warganet kali ini admin karawangportal akan membagikan tutorial java programming secara gratis tis total bagai mana membuat aplikasi sederhana "menghitung persegi panjang dengan bahasa java programming " yuk lets langsung aja di simak


/* @author www.karawangportal.com
 */
import java.awt.event.KeyEvent;
import javax.swing.JOptionPane;
public class Persegi_P extends javax.swing.JFrame {
    public Persegi_P() {
    initComponents();
    rdbSegitiga.setSelected(true);
    CBX1.setSelectedIndex(0);
    setLocationRelativeTo(null);
    }
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                        
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        rdbPanjang = new javax.swing.JRadioButton();
        rdbSegitiga = new javax.swing.JRadioButton();
        rdbLingkaran = new javax.swing.JRadioButton();
        CBX1 = new javax.swing.JComboBox();
        lbl1 = new javax.swing.JLabel();
        lbl2 = new javax.swing.JLabel();
        lbl3Output = new javax.swing.JLabel();
        txt1 = new javax.swing.JTextField();
        txt2 = new javax.swing.JTextField();
        txt3 = new javax.swing.JTextField();
        btnHitung = new javax.swing.JButton();
        btnHapus = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("al dkidrebel");

        buttonGroup1.add(rdbPanjang);
        rdbPanjang.setText("Persegi");
        rdbPanjang.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rdbPanjangActionPerformed(evt);
            }
        });

        buttonGroup1.add(rdbSegitiga);
        rdbSegitiga.setText("Segitiga");
        rdbSegitiga.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
        rdbSegitigaActionPerformed(evt);
            }
        });

        buttonGroup1.add(rdbLingkaran);
        rdbLingkaran.setText("Lingkaran");
        rdbLingkaran.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rdbLingkaranActionPerformed(evt);
            }
        });

        CBX1.setBackground(new java.awt.Color(0, 255, 255));
        CBX1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Luas", "Keliling" }));
        CBX1.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                CBX1ItemStateChanged(evt);
            }
        });
        CBX1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CBX1ActionPerformed(evt);
            }
        });

        lbl1.setText("................");
        lbl1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                lbl1KeyPressed(evt);
            }
        });

        lbl2.setText("................");
        lbl2.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                lbl2KeyPressed(evt);
            }
        });

        lbl3Output.setText("................");

        txt1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txt1ActionPerformed(evt);
            }
        });

        txt2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txt2ActionPerformed(evt);
            }
        });

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

        btnHapus.setBackground(new java.awt.Color(0, 255, 0));
        btnHapus.setText("Hapus");
        btnHapus.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnHapusActionPerformed(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()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnHitung)
                    .addComponent(btnHapus)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(rdbSegitiga)
                            .addComponent(rdbPanjang)
                            .addComponent(rdbLingkaran)
                            .addComponent(lbl1)
                            .addComponent(lbl2)
                            .addComponent(lbl3Output, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(25, 25, 25)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(txt2, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(txt1, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(CBX1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(txt3, javax.swing.GroupLayout.DEFAULT_SIZE, 110, Short.MAX_VALUE))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addComponent(rdbPanjang)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(rdbSegitiga)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(rdbLingkaran)
                    .addComponent(CBX1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnHitung)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(lbl1)
                        .addGap(18, 18, 18)
                        .addComponent(lbl2)
                        .addGap(18, 18, 18)
                        .addComponent(btnHapus)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lbl3Output)
                            .addComponent(txt3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(txt1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(txt2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(65, Short.MAX_VALUE))
        );

        pack();
    }                     

    private void CBX1ItemStateChanged(java.awt.event.ItemEvent evt) {                                    
    }                                   

    private void txt1ActionPerformed(java.awt.event.ActionEvent evt) {                                    
    }                                   

    private void rdbPanjangActionPerformed(java.awt.event.ActionEvent evt) {                                         
          lbl1.setText("Panjang");
          lbl2.setText("Lebar");
          lbl3Output.setVisible(true);

    }                                        

 
 private void CBX1ActionPerformed(java.awt.event.ActionEvent evt) {                                    
          if(CBX1.getSelectedItem().equals("Luas")){
            lbl3Output.setText("Luas");
            }
            else if(CBX1.getSelectedItem().equals("Keliling")){
            lbl3Output.setText("Keliling");

                        }
    }                                   

    private void txt2ActionPerformed(java.awt.event.ActionEvent evt) {                                   
     
    }                                  

    private void btnHitungActionPerformed(java.awt.event.ActionEvent evt) {                                        
        int exitApp= JOptionPane.showConfirmDialog(null, "Apakah anda mau menghitung ?",
                   "Konfirmasi", JOptionPane.YES_NO_OPTION);
                    if (exitApp==JOptionPane.YES_OPTION){

         if (rdbSegitiga.isSelected())
                                    if(CBX1.getSelectedItem().equals("Luas"))
                                    {   String Masuk1 = txt1.getText();
                                        String Masuk2 = txt2.getText();
                                        Double X1 = Double.parseDouble(Masuk1);
                                        Double X2 = Double.parseDouble(Masuk2);

                                       txt3.setText (""+ 0.5 * X1 * X2);
                                    }
                                    else if (CBX1.getSelectedItem().equals("Keliling"))
                                    {   String Masuk1 = txt1.getText();
                                        String Masuk2 = txt2.getText();
                                        Double X1 = Double.parseDouble(Masuk1);
                                        Double X2 = Double.parseDouble(Masuk2);
                                       txt3.setText ((""+ (X1 + X2 + (Math.sqrt((X1 * X1) + (X2 * X2))))));
                                    }
        }
        {
           { if (rdbPanjang.isSelected())
                                    if(CBX1.getSelectedItem().equals("Luas"))
                                    {   String Masuk1 = txt1.getText();
                                        String Masuk2 = txt2.getText();
                                        Double X1 = Double.parseDouble(Masuk1);
                                        Double X2 = Double.parseDouble(Masuk2);
                                        txt3.setText (""+  X1 +X2);
                                    }

                                    else if (CBX1.getSelectedItem().equals("Keliling"))
                                    {   String Masuk1 = txt1.getText();
                                        String Masuk2 = txt2.getText();
                                        Double X1 = Double.parseDouble(Masuk1);
                                        Double X2 = Double.parseDouble(Masuk2);
                                        txt3.setText (""+ 2 *(X1 + X2));
                                    }
           }
        }
        {
            { if (rdbLingkaran.isSelected())
                if(CBX1.getSelectedItem().equals("Luas"))
                {   String Masuk1 = txt1.getText();
                    Double X1 = Double.parseDouble(Masuk1);
                    txt3.setText (""+  3.14 * X1 * X1);
                }
                else if (CBX1.getSelectedItem().equals("Keliling"))
                {   String Masuk1 = txt1.getText();
                    Double X1 = Double.parseDouble(Masuk1);
                    txt3.setText (""+  2 * 3.14 * X1);
                }
                }
           }
     
    }                                       


    private void rdbSegitigaActionPerformed(java.awt.event.ActionEvent evt) {                                          
        lbl1.setText("Alas");
        lbl2.setText("Tinggi");
        lbl3Output.setVisible(true);

    }                                         

    private void rdbLingkaranActionPerformed(java.awt.event.ActionEvent evt) {                                           
            lbl1.setText("Jari-Jari");
            lbl2.setText("");
    lbl3Output.setVisible(false);

    }                                           

 
 private void btnHapusActionPerformed(java.awt.event.ActionEvent evt) {                                       
         int exitApp= JOptionPane.showConfirmDialog(null, " apa anda yakin ingin menghapus?",
                   "Konfirmasi", JOptionPane.YES_NO_OPTION);
                    if (exitApp==JOptionPane.YES_OPTION){
                        txt1.setText ("");
                        txt2.setText("");
                        txt3.setText("");

                    }
    
    }                                      

    private void lbl1KeyPressed(java.awt.event.KeyEvent evt) {                              
        // TODO add your handling code here:
        if(evt.getKeyCode() == KeyEvent.VK_0){
        } else if (evt.getKeyCode() == KeyEvent.VK_1){
           } else if (evt.getKeyCode() == KeyEvent.VK_2){
                } else if (evt.getKeyCode() == KeyEvent.VK_3){
                    } else if (evt.getKeyCode() == KeyEvent.VK_4){
                        } else if (evt.getKeyCode() == KeyEvent.VK_5){
                            } else if (evt.getKeyCode() == KeyEvent.VK_6){
                                } else if (evt.getKeyCode() == KeyEvent.VK_7){
                                    } else if (evt.getKeyCode() == KeyEvent.VK_8){
                                        } else if (evt.getKeyCode() == KeyEvent.VK_9){
                                            } else if (evt.getKeyCode() == KeyEvent.VK_PERIOD){
                                                } else if (evt.getKeyCode() != KeyEvent.VK_BACK_SPACE)
        JOptionPane.showMessageDialog(null,  "memasukkan Angka Segera !"
                + "SEGERA HAPUS !",
"Warning",  JOptionPane.WARNING_MESSAGE);

    }                             

    private void lbl2KeyPressed(java.awt.event.KeyEvent evt) {                              
        // TODO add your handling code here:
        if(evt.getKeyCode() == KeyEvent.VK_0){
        } else if (evt.getKeyCode() == KeyEvent.VK_1){
           } else if (evt.getKeyCode() == KeyEvent.VK_2){
                } else if (evt.getKeyCode() == KeyEvent.VK_3){
                    } else if (evt.getKeyCode() == KeyEvent.VK_4){
                        } else if (evt.getKeyCode() == KeyEvent.VK_5){
                            } else if (evt.getKeyCode() == KeyEvent.VK_6){
                                } else if (evt.getKeyCode() == KeyEvent.VK_7){
                                    } else if (evt.getKeyCode() == KeyEvent.VK_8){
                                        } else if (evt.getKeyCode() == KeyEvent.VK_9){
                                            } else if (evt.getKeyCode() == KeyEvent.VK_PERIOD){
                                                } else if (evt.getKeyCode() != KeyEvent.VK_BACK_SPACE)
        JOptionPane.showMessageDialog(null,  "memasukkan Angka segera !"
                + "sistem default !",
"Warning",  JOptionPane.WARNING_MESSAGE);

    }                              


    public static void main(String args[]) {
     
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Persegi_P.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Persegi_P.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Persegi_P.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Persegi_P.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }

    
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Persegi_P().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify                   
    private javax.swing.JComboBox CBX1;
    private javax.swing.JButton btnHapus;
    private javax.swing.JButton btnHitung;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JLabel lbl1;
    private javax.swing.JLabel lbl2;
    private javax.swing.JLabel lbl3Output;
    private javax.swing.JRadioButton rdbLingkaran;
    private javax.swing.JRadioButton rdbPanjang;
    private javax.swing.JRadioButton rdbSegitiga;
    private javax.swing.JTextField txt1;
    private javax.swing.JTextField txt2;
    private javax.swing.JTextField txt3;
    // End of variables declaration                 
}
OUTPUT

Source Code Program Java Menghitung Persegi Panjang Netbeans
Output Source Code Program Java Menghitung Persegi Panjang Netbeans

CATATAN

Tulisan yang berwarna merah untuk membuat fungsi event 
 jumlah disaind

    3 Radio Button
    1 Button Group
    3 Text Field
    2 Tombol Butten
    3 Label
    1 Combo Box

Cara membuat radio butten masukan 3 radio button ke layout desain kemudian klik kanan edit text,sesua yang di inginkan dan kemudian masukan 1 button group klik di radio button dan cari button group ada di bagian kanan netbeans klik combonya rubah "none"menjadi button group yang di ingin kan & lakukan pada setiap radio butten

    Cara Membuat Combo box  masukan combo box ke layout dan klik kanan propertis cari model edit kata atau bilangan yang mau di masukan closs layer

    Cara Membuat Fungsi Event KeyPressed,klik kanan Event Key klik KeyPressed
    Cara Membuat windoesClosing klik kanan propertis Event cari windowsClosing tutup Layout copy text ini di bawah public voiid widowsClosing

        int exitApp= JOptionPane.showConfirmDialog(null,
                "Apakah Ingin Menutup Aplikasi?", "Konfirmasi", JOptionPane.YES_NO_OPTION);
                if (exitApp==JOptionPane.YES_OPTION){
                System.exit(0);
                }
    Cara agar layout tak tertutup saat di Closs,klik kanan propertis cari tulisan defaultCloseOperation    EXIT_ON_CLOSE

No comments:

Post a Comment

Karawang Portal | adalah tempat belajar blogger pemula dan profesional. Kamu bisa menemukan kami di sosial media berikut.

Note: Only a member of this blog may post a comment.

×
Berita Terbaru Update