Ni dia kode programnya..
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* kalku.java
*
* Created on May 23, 2012, 8:16:01 AM
*/
package kalkulator_mini;
/**
*
* @author adic
*/
public class kalku extends javax.swing.JFrame {
String angka;
Double total,angka1,angka2;
int pilih;
/** Creates new form kalku */
public kalku() {
initComponents();
angka= "";
}
/** 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")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
cmdclear = new javax.swing.JButton();
cmdminplus = new javax.swing.JButton();
cmdkurang = new javax.swing.JButton();
cmdtambah = new javax.swing.JButton();
cmdsamadengan = new javax.swing.JButton();
cmd9 = new javax.swing.JButton();
cmd8 = new javax.swing.JButton();
cmd7 = new javax.swing.JButton();
cmd6 = new javax.swing.JButton();
cmdpersen = new javax.swing.JButton();
cmd0 = new javax.swing.JButton();
cmdtampil = new javax.swing.JTextField();
cmdkali = new javax.swing.JButton();
cmd2 = new javax.swing.JButton();
cmd3 = new javax.swing.JButton();
cmdbagi = new javax.swing.JButton();
cmd4 = new javax.swing.JButton();
cmdkoma = new javax.swing.JButton();
cmd5 = new javax.swing.JButton();
cmd1 = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("KALKULATOR MINI");
setBackground(new java.awt.Color(0, 255, 0));
setForeground(new java.awt.Color(204, 0, 255));
jPanel1.setBackground(new java.awt.Color(51, 255, 0));
jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0), 5));
cmdclear.setFont(new java.awt.Font("Tahoma", 1, 11));
cmdclear.setText("C");
cmdclear.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmdclearActionPerformed(evt);
}
});
cmdminplus.setFont(new java.awt.Font("Tahoma", 1, 11));
cmdminplus.setText("+/-");
cmdminplus.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmdminplusActionPerformed(evt);
}
});
cmdkurang.setFont(new java.awt.Font("Tahoma", 1, 11));
cmdkurang.setText("-");
cmdkurang.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmdkurangActionPerformed(evt);
}
});
cmdtambah.setFont(new java.awt.Font("Tahoma", 1, 11));
cmdtambah.setText("+");
cmdtambah.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmdtambahActionPerformed(evt);
}
});
cmdsamadengan.setFont(new java.awt.Font("Tahoma", 1, 11));
cmdsamadengan.setText("=");
cmdsamadengan.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmdsamadenganActionPerformed(evt);
}
});
cmd9.setFont(new java.awt.Font("Tahoma", 1, 11));
cmd9.setText("9");
cmd9.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmd9ActionPerformed(evt);
}
});
cmd8.setFont(new java.awt.Font("Tahoma", 1, 11));
cmd8.setText("8");
cmd8.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmd8ActionPerformed(evt);
}
});
cmd7.setFont(new java.awt.Font("Tahoma", 1, 11));
cmd7.setText("7");
cmd7.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmd7ActionPerformed(evt);
}
});
cmd6.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
cmd6.setText("6");
cmd6.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmd6ActionPerformed(evt);
}
});
cmdpersen.setFont(new java.awt.Font("Tahoma", 1, 11));
cmdpersen.setText("%");
cmdpersen.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmdpersenActionPerformed(evt);
}
});
cmd0.setFont(new java.awt.Font("Tahoma", 1, 11));
cmd0.setText("0");
cmd0.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmd0ActionPerformed(evt);
}
});
cmdtampil.setBackground(new java.awt.Color(255, 255, 0));
cmdtampil.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
cmdtampil.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0), 3));
cmdtampil.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmdtampilActionPerformed(evt);
}
});
cmdkali.setFont(new java.awt.Font("Tahoma", 1, 11));
cmdkali.setText("*");
cmdkali.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmdkaliActionPerformed(evt);
}
});
cmd2.setFont(new java.awt.Font("Tahoma", 1, 11));
cmd2.setText("2");
cmd2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmd2ActionPerformed(evt);
}
});
cmd3.setFont(new java.awt.Font("Tahoma", 1, 11));
cmd3.setText("3");
cmd3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmd3ActionPerformed(evt);
}
});
cmdbagi.setFont(new java.awt.Font("Tahoma", 1, 11));
cmdbagi.setText("/");
cmdbagi.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmdbagiActionPerformed(evt);
}
});
cmd4.setFont(new java.awt.Font("Tahoma", 1, 11));
cmd4.setText("4");
cmd4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmd4ActionPerformed(evt);
}
});
cmdkoma.setFont(new java.awt.Font("Tahoma", 1, 11));
cmdkoma.setText(".");
cmdkoma.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmdkomaActionPerformed(evt);
}
});
cmd5.setFont(new java.awt.Font("Tahoma", 1, 11));
cmd5.setText("5");
cmd5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmd5ActionPerformed(evt);
}
});
cmd1.setFont(new java.awt.Font("Tahoma", 1, 11));
cmd1.setText("1");
cmd1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmd1ActionPerformed(evt);
}
});
jLabel1.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
jLabel1.setText("KALKULATOR MINI ADIC KOMALASARI");
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 278, Short.MAX_VALUE)
.addComponent(cmdtampil, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 278, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(cmd4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 51, Short.MAX_VALUE)
.addComponent(cmdpersen, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 51, Short.MAX_VALUE)
.addComponent(cmd1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 51, Short.MAX_VALUE)
.addComponent(cmd7, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(cmd2, javax.swing.GroupLayout.DEFAULT_SIZE, 56, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(cmd8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(cmd5, javax.swing.GroupLayout.DEFAULT_SIZE, 56, Short.MAX_VALUE))
.addComponent(cmd0, javax.swing.GroupLayout.DEFAULT_SIZE, 56, Short.MAX_VALUE))
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(cmd6, javax.swing.GroupLayout.DEFAULT_SIZE, 50, Short.MAX_VALUE)
.addComponent(cmd9, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(cmdkurang, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(cmdminplus, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(cmdclear, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(cmdkali, javax.swing.GroupLayout.DEFAULT_SIZE, 48, Short.MAX_VALUE)))
.addGroup(jPanel1Layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 6, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(cmdkoma, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(cmd3, javax.swing.GroupLayout.DEFAULT_SIZE, 51, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(cmdtambah, javax.swing.GroupLayout.DEFAULT_SIZE, 48, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cmdbagi, javax.swing.GroupLayout.DEFAULT_SIZE, 48, Short.MAX_VALUE))
.addComponent(cmdsamadengan, javax.swing.GroupLayout.DEFAULT_SIZE, 102, Short.MAX_VALUE))))))
.addGap(20, 20, 20))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(9, 9, 9)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cmdtampil, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cmd7)
.addComponent(cmd8)
.addComponent(cmd9)
.addComponent(cmdminplus)
.addComponent(cmdclear))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cmdkurang)
.addComponent(cmdkali))
.addComponent(cmd4)
.addComponent(cmd6)
.addComponent(cmd5))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cmdtambah)
.addComponent(cmdbagi))
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cmd1)
.addComponent(cmd2)
.addComponent(cmd3)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cmdpersen)
.addComponent(cmdsamadengan)
.addComponent(cmd0)
.addComponent(cmdkoma))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void cmdtampilActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void cmd0ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
//angka+="0";
//cmdtampil.setText("0");
cmdtampil.setText(angka +="0");
}
private void cmdpersenActionPerformed(java.awt.event.ActionEvent evt) {
angka2 = Double.parseDouble(angka);
total = angka2 / 100;
angka = Double.toString(total);
cmdtampil.setText(angka);
}
private void cmd8ActionPerformed(java.awt.event.ActionEvent evt) {
cmdtampil.setText(angka +="8");
}
private void cmd1ActionPerformed(java.awt.event.ActionEvent evt) {
cmdtampil.setText(angka +="1");
}
private void cmd2ActionPerformed(java.awt.event.ActionEvent evt) {
cmdtampil.setText(angka +="2");
}
private void cmd3ActionPerformed(java.awt.event.ActionEvent evt) {
cmdtampil.setText(angka +="3");
}
private void cmd4ActionPerformed(java.awt.event.ActionEvent evt) {
cmdtampil.setText(angka +="4");
}
private void cmd5ActionPerformed(java.awt.event.ActionEvent evt) {
cmdtampil.setText(angka +="5");
}
private void cmd6ActionPerformed(java.awt.event.ActionEvent evt) {
cmdtampil.setText(angka +="6");
}
private void cmd7ActionPerformed(java.awt.event.ActionEvent evt) {
cmdtampil.setText(angka +="7");
}
private void cmd9ActionPerformed(java.awt.event.ActionEvent evt) {
cmdtampil.setText(angka +="9");
}
private void cmdtambahActionPerformed(java.awt.event.ActionEvent evt) {
angka1=Double.parseDouble(angka);
cmdtampil.setText("+");
angka="";
pilih=1;
}
private void cmdsamadenganActionPerformed(java.awt.event.ActionEvent evt) {
switch(pilih)
{case 1:
angka2=Double.parseDouble(angka);
total = angka1 + angka2;
angka = Double.toString(total);
cmdtampil.setText(angka);
break;
case 2:
angka2=Double.parseDouble(angka);
total = angka1 - angka2;
angka= Double.toString(total);
cmdtampil.setText(angka);
break;
case 3:
angka2=Double.parseDouble(angka);
total = angka1 * angka2;
angka= Double.toString(total);
cmdtampil.setText(angka);
break;
case 4:
angka2=Double.parseDouble(angka);
total = angka1 / angka2;
angka= Double.toString(total);
cmdtampil.setText(angka);
break;
default:
break;
}
}
private void cmdclearActionPerformed(java.awt.event.ActionEvent evt) {
angka1 = 0.0;
angka2 = 0.0;
total = 0.0;
angka ="";
cmdtampil.setText("");
}
private void cmdkurangActionPerformed(java.awt.event.ActionEvent evt) {
angka1=Double.parseDouble(angka);
cmdtampil.setText("-");
angka="";
pilih=2;
}
private void cmdkaliActionPerformed(java.awt.event.ActionEvent evt) {
angka1=Double.parseDouble(angka);
cmdtampil.setText("*");
angka="";
pilih=3;
}
private void cmdbagiActionPerformed(java.awt.event.ActionEvent evt) {
angka1=Double.parseDouble(angka);
cmdtampil.setText("/");
angka="";
pilih=4;
}
private void cmdminplusActionPerformed(java.awt.event.ActionEvent evt) {
angka2 = Double.parseDouble(angka);
total = 0 - angka2;
angka = Double.toString(total);
cmdtampil.setText(angka);
}
private void cmdkomaActionPerformed(java.awt.event.ActionEvent evt) {
cmdtampil.setText(angka +=".");
}
/**
* @param args the command line arguments
*/
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(kalku.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(kalku.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(kalku.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(kalku.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 kalku().setVisible(true);
}
});
}
private double temp;
// Variables declaration - do not modify
private javax.swing.JButton cmd0;
private javax.swing.JButton cmd1;
private javax.swing.JButton cmd2;
private javax.swing.JButton cmd3;
private javax.swing.JButton cmd4;
private javax.swing.JButton cmd5;
private javax.swing.JButton cmd6;
private javax.swing.JButton cmd7;
private javax.swing.JButton cmd8;
private javax.swing.JButton cmd9;
private javax.swing.JButton cmdbagi;
private javax.swing.JButton cmdclear;
private javax.swing.JButton cmdkali;
private javax.swing.JButton cmdkoma;
private javax.swing.JButton cmdkurang;
private javax.swing.JButton cmdminplus;
private javax.swing.JButton cmdpersen;
private javax.swing.JButton cmdsamadengan;
private javax.swing.JButton cmdtambah;
private javax.swing.JTextField cmdtampil;
private javax.swing.JLabel jLabel1;
private javax.swing.JPanel jPanel1;
// End of variables declaration
}