Source Code Java Kalkulator Sederhana di Netbeans



Pagi gan maaf ne baru sempet postng lagi maklum lagi sibuk nah kali ini ane mau potsing  tugas  Pemrograman Vsual.oke Next - Source Code Java Kalkulator Sederhana di Netbeans

Source Code Java Kalkulator Sederhana di Netbeans

import java.awt.*;
import java.awt.event.*;

public class Calculator_V extends Frame implements WindowListener, ActionListener {
  Label lbl1, lbl2, lbl3, lbl4, lbl5;
  TextField txtNum1, txtOperator, txtNum2, txtResult;
  Button btnHitung;

 public Calculator_V(String judul) {
      super(judul);
      this.addWindowListener(this);
      this.setLayout(new GridLayout(2,5));
      lbl1 = new Label ("Angka I");   
      lbl2 = new Label ("Operator");
      lbl3 = new Label ("Angka II");
      lbl4 = new Label ("");
      lbl5 = new Label ("Hasil");
     
             
      txtNum1 = new TextField();
      txtNum1.setColumns(15);
      txtOperator = new TextField();
      txtOperator.setColumns(15);
      txtNum2 = new TextField();
      txtNum2.setColumns(15);
      txtResult = new TextField();
      txtResult.setColumns(15);
      btnHitung = new Button("=");
      btnHitung.addActionListener(this);
      add (lbl1);
      add (lbl2);
      add (lbl3);
      add (lbl4);
      add (lbl5);
     
      add(txtNum1);
      add(txtOperator);
      add(txtNum2);
      add(btnHitung);
      add(txtResult);
  }
  public void windowActivated(WindowEvent e) {}
  public void windowClosed(WindowEvent e) {}
  public void windowClosing(WindowEvent e) {
      setVisible(false);
      System.exit(0);
  }
  public void windowDeactivated(WindowEvent e) {}
  public void windowDeiconified(WindowEvent e) {}
  public void windowIconified(WindowEvent e) {}
  public void windowOpened(WindowEvent e) {}

  public void actionPerformed(ActionEvent e) {
      double a, b, Result;
      String c;
      if (e.getSource() == btnHitung){
          a = Double.parseDouble(txtNum1.getText());
          b = Double.parseDouble(txtNum2.getText());
          c = txtOperator.getText();
          if (c.equals("*")) {
              Result = a * b;
          } else if (c.equals("/")) {
              Result = a / b;
          } else if (c.equals("+")) {
              Result = a + b;
          } else if (c.equals("-")) {
              Result = a - b;
          } else {
              Result = 0;
          }
       
          txtResult.setText(""+ Result);
      }
  }

  public static void main(String args[]) {
      Calculator_V frm = new Calculator_V("aldkidrebel");
      frm.setSize(400, 100);
      frm.setVisible(true);
  }
}


Cara Menghitung Luas Dan Kelilig
Source Code

import java.awt.*;
import java.awt.event.*;

public class GuiAwt_PersegiPanjang extends Frame{
     private Label lblPanjang;
     private Label lblLebar;
     private Label lblLuas;
     private Label lblKeliling;
     private TextField txtPanjang;
     private TextField txtLebar;
     private TextField txtLuas;
     private TextField txtKeliling;
     private Button btnHitung;
     private Button btnHapus;
     public GuiAwt_PersegiPanjang(){
        this.addWindowListener(new WindowAdapter(){
            public void windowClosing(WindowEvent e){
                dispose();
                System.exit(0);
            }
        });
       
        lblPanjang = new Label("Panjang");
        txtPanjang = new TextField();
        lblLebar = new Label("Lebar");
        txtLebar = new TextField();
        btnHitung = new Button("Hitung");
        btnHapus = new Button("Hapus");
        lblLuas = new Label("Luas");
        txtLuas = new TextField();
        lblKeliling = new Label("Keliling");
        txtKeliling = new TextField();
       
         btnHitung.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
                int Panjang = Integer.parseInt(txtPanjang.getText());  
                int Lebar = Integer.parseInt(txtLebar.getText());
                int Luas = Panjang * Lebar;
                int Keliling = 2*(Panjang + Lebar);
                txtLuas.setText(Luas+"");
                txtKeliling.setText(Keliling+"");
            }
        });
        
         btnHapus.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
                txtPanjang.setText("");
                txtLebar.setText("");
                txtLuas.setText("");
                txtKeliling.setText("");
               
                          
            }
        });
        
         this.setLayout(new GridLayout(5, 2, 5, 5));
       
        add(lblPanjang);
        add(txtPanjang);
        add(lblLebar);
        add(txtLebar);
        add(btnHitung);
        add(btnHapus);
        add(lblLuas);
        add(txtLuas);
        add(lblKeliling);
        add(txtKeliling);
    
      
       
        this.setTitle("aldkidrebel");
        this.setSize(300, 200);
        this.setVisible(true);
    }
    
     public static void main(String[] args) {
        
           GuiAwt_PersegiPanjang frm = new  GuiAwt_PersegiPanjang();
         
       
    }
}
 
   




Cara Menghitung Bilangan Dengan J_Frame
Source Code



public class Bilangan extends javax.swing.JFrame {

    public Bilangan() {
        initComponents();
    }
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                         
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        btnCari = new javax.swing.JButton();
        btnHapus = new javax.swing.JButton();
        txtBil1 = new javax.swing.JTextField();
        txtBil2 = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("al d'kidrebel");

        jLabel1.setFont(new java.awt.Font("Tekton Pro", 1, 14)); // NOI18N
        jLabel1.setText("Masukan Bilangan");

        jLabel2.setFont(new java.awt.Font("Tekton Pro Ext", 1, 12)); // NOI18N
        jLabel2.setText("Jenis Bilangan");

        btnCari.setText("Cari");
        btnCari.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCariActionPerformed(evt);
            }
        });

        btnHapus.setText("Hapus");
        btnHapus.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnHapusActionPerformed(evt);
            }
        });

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

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

        jLabel3.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
        jLabel3.setText("Meode Sederhana Mencar Jenis Bilangan ");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(40, 40, 40)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(btnCari)
                            .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(81, 81, 81)
                                .addComponent(btnHapus))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(39, 39, 39)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(txtBil1, javax.swing.GroupLayout.DEFAULT_SIZE, 118, Short.MAX_VALUE)
                                    .addComponent(txtBil2)))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(50, 50, 50)
                        .addComponent(jLabel3)))
                .addContainerGap(56, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addComponent(jLabel3)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(txtBil1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 34, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnHapus)
                    .addComponent(btnCari))
                .addGap(45, 45, 45)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txtBil2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(101, 101, 101))
        );

        pack();
    }// </editor-fold>                       

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

    private void btnHapusActionPerformed(java.awt.event.ActionEvent evt) {                                        
txtBil1.setText("");
txtBil2.setText("");
    }                                       

    private void btnCariActionPerformed(java.awt.event.ActionEvent evt) {                                       
int Bilangan;
String Cari;
Bilangan=Integer.parseInt(txtBil1.getText());
        {
        if (Bilangan < 0)
        {
            Cari=" * Bilangan Nagatif";
            txtBil2.setText(Cari);
        }
        else if (Bilangan%2 ==+1)
        {            Cari=" * Bilangan Ganjil";
            txtBil2.setText(Cari);
        }
        else if (Bilangan%2 ==0)
        {
            Cari = "*Bilangan Genap";
            txtBil2.setText(Cari);
        }
        }
                                 
    }                                      

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

  
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        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(Bilangan.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Bilangan.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Bilangan.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Bilangan.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Bilangan().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify                    
    private javax.swing.JButton btnCari;
    private javax.swing.JButton btnHapus;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JTextField txtBil1;
    private javax.swing.JTextField txtBil2;
    // End of variables declaration                  
}

   



1 Comments:


EmoticonEmoticon