Dalam kesempatan kali ini saya akan membuat kalkulator sederhana dengan program netbeans
pertama tama :
buka prgram netbeans dan buat project baru dan copy code di bawah ini:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Novianto
*/
public class TampilanKalkulator extends javax.swing.JFrame {
/**
* Creates new form TampilanKalkulator
*/
String angka;
double jumlah,angka1,angka2;
int pilih;
public TampilanKalkulator() {
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();
jColorChooser1 = new javax.swing.JColorChooser();
jFrame1 = new javax.swing.JFrame();
jFrame2 = new javax.swing.JFrame();
jFrame3 = new javax.swing.JFrame();
jDialog1 = new javax.swing.JDialog();
jMenu1 = new javax.swing.JMenu();
jMenu2 = new javax.swing.JMenu();
jInternalFrame1 = new javax.swing.JInternalFrame();
jFrame4 = new javax.swing.JFrame();
jFrame5 = new javax.swing.JFrame();
jFrame6 = new javax.swing.JFrame();
jInternalFrame2 = new javax.swing.JInternalFrame();
choice1 = new java.awt.Choice();
btnAngka0 = new javax.swing.JButton();
btnKoma = new javax.swing.JButton();
btnAngka1 = new javax.swing.JButton();
btnAngka2 = new javax.swing.JButton();
btnAngka3 = new javax.swing.JButton();
btnAngka4 = new javax.swing.JButton();
btnAngka5 = new javax.swing.JButton();
btnAngka6 = new javax.swing.JButton();
btnSamadengan = new javax.swing.JButton();
btnTambah = new javax.swing.JButton();
btnKurang = new javax.swing.JButton();
btnKali = new javax.swing.JButton();
btnAngka9 = new javax.swing.JButton();
btnAngka7 = new javax.swing.JButton();
btnAngka8 = new javax.swing.JButton();
btnHapus = new javax.swing.JButton();
btnBagi = new javax.swing.JButton();
display = new javax.swing.JTextField();
jLabel1 = new javax.swing.JLabel();
org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(0, 100, Short.MAX_VALUE)
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(0, 100, Short.MAX_VALUE)
);
org.jdesktop.layout.GroupLayout jFrame1Layout = new org.jdesktop.layout.GroupLayout(jFrame1.getContentPane());
jFrame1.getContentPane().setLayout(jFrame1Layout);
jFrame1Layout.setHorizontalGroup(
jFrame1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(0, 400, Short.MAX_VALUE)
);
jFrame1Layout.setVerticalGroup(
jFrame1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(0, 300, Short.MAX_VALUE)
);
org.jdesktop.layout.GroupLayout jFrame2Layout = new org.jdesktop.layout.GroupLayout(jFrame2.getContentPane());
jFrame2.getContentPane().setLayout(jFrame2Layout);
jFrame2Layout.setHorizontalGroup(
jFrame2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(0, 400, Short.MAX_VALUE)
);
jFrame2Layout.setVerticalGroup(
jFrame2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(0, 300, Short.MAX_VALUE)
);
org.jdesktop.layout.GroupLayout jFrame3Layout = new org.jdesktop.layout.GroupLayout(jFrame3.getContentPane());
jFrame3.getContentPane().setLayout(jFrame3Layout);
jFrame3Layout.setHorizontalGroup(
jFrame3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(0, 400, Short.MAX_VALUE)
);
jFrame3Layout.setVerticalGroup(
jFrame3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(0, 300, Short.MAX_VALUE)
);
org.jdesktop.layout.GroupLayout jDialog1Layout = new org.jdesktop.layout.GroupLayout(jDialog1.getContentPane());
jDialog1.getContentPane().setLayout(jDialog1Layout);
jDialog1Layout.setHorizontalGroup(
jDialog1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(0, 400, Short.MAX_VALUE)
);
jDialog1Layout.setVerticalGroup(
jDialog1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(0, 300, Short.MAX_VALUE)
);
jMenu1.setText("jMenu1");
jMenu2.setText("jMenu2");
jInternalFrame1.setVisible(true);
org.jdesktop.layout.GroupLayout jInternalFrame1Layout = new org.jdesktop.layout.GroupLayout(jInternalFrame1.getContentPane());
jInternalFrame1.getContentPane().setLayout(jInternalFrame1Layout);
jInternalFrame1Layout.setHorizontalGroup(
jInternalFrame1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(0, 0, Short.MAX_VALUE)
);
jInternalFrame1Layout.setVerticalGroup(
jInternalFrame1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(0, 0, Short.MAX_VALUE)
);
org.jdesktop.layout.GroupLayout jFrame4Layout = new org.jdesktop.layout.GroupLayout(jFrame4.getContentPane());
jFrame4.getContentPane().setLayout(jFrame4Layout);
jFrame4Layout.setHorizontalGroup(
jFrame4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(0, 400, Short.MAX_VALUE)
);
jFrame4Layout.setVerticalGroup(
jFrame4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(0, 300, Short.MAX_VALUE)
);
org.jdesktop.layout.GroupLayout jFrame5Layout = new org.jdesktop.layout.GroupLayout(jFrame5.getContentPane());
jFrame5.getContentPane().setLayout(jFrame5Layout);
jFrame5Layout.setHorizontalGroup(
jFrame5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(0, 400, Short.MAX_VALUE)
);
jFrame5Layout.setVerticalGroup(
jFrame5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(0, 300, Short.MAX_VALUE)
);
org.jdesktop.layout.GroupLayout jFrame6Layout = new org.jdesktop.layout.GroupLayout(jFrame6.getContentPane());
jFrame6.getContentPane().setLayout(jFrame6Layout);
jFrame6Layout.setHorizontalGroup(
jFrame6Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(0, 400, Short.MAX_VALUE)
);
jFrame6Layout.setVerticalGroup(
jFrame6Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(0, 300, Short.MAX_VALUE)
);
jInternalFrame2.setVisible(true);
org.jdesktop.layout.GroupLayout jInternalFrame2Layout = new org.jdesktop.layout.GroupLayout(jInternalFrame2.getContentPane());
jInternalFrame2.getContentPane().setLayout(jInternalFrame2Layout);
jInternalFrame2Layout.setHorizontalGroup(
jInternalFrame2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(0, 0, Short.MAX_VALUE)
);
jInternalFrame2Layout.setVerticalGroup(
jInternalFrame2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(0, 0, Short.MAX_VALUE)
);
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Kalkulator Sederhana");
setBackground(new java.awt.Color(0, 0, 204));
setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
setResizable(false);
btnAngka0.setFont(new java.awt.Font("Segoe UI", 0, 18)); // NOI18N
btnAngka0.setText("0");
btnAngka0.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnAngka0ActionPerformed(evt);
}
});
btnKoma.setFont(new java.awt.Font("Segoe UI", 0, 18)); // NOI18N
btnKoma.setText(",");
btnKoma.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnKomaActionPerformed(evt);
}
});
btnAngka1.setFont(new java.awt.Font("Segoe UI", 0, 18)); // NOI18N
btnAngka1.setText("1");
btnAngka1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnAngka1ActionPerformed(evt);
}
});
btnAngka2.setFont(new java.awt.Font("Segoe UI", 0, 18)); // NOI18N
btnAngka2.setText("2");
btnAngka2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnAngka2ActionPerformed(evt);
}
});
btnAngka3.setFont(new java.awt.Font("Segoe UI", 0, 18)); // NOI18N
btnAngka3.setText("3");
btnAngka3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnAngka3ActionPerformed(evt);
}
});
btnAngka4.setFont(new java.awt.Font("Segoe UI", 0, 18)); // NOI18N
btnAngka4.setText("4");
btnAngka4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnAngka4ActionPerformed(evt);
}
});
btnAngka5.setFont(new java.awt.Font("Segoe UI", 0, 18)); // NOI18N
btnAngka5.setText("5");
btnAngka5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnAngka5ActionPerformed(evt);
}
});
btnAngka6.setFont(new java.awt.Font("Segoe UI", 0, 18)); // NOI18N
btnAngka6.setText("6");
btnAngka6.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnAngka6ActionPerformed(evt);
}
});
btnSamadengan.setFont(new java.awt.Font("Segoe UI", 0, 18)); // NOI18N
btnSamadengan.setText("=");
btnSamadengan.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnSamadenganActionPerformed(evt);
}
});
btnTambah.setFont(new java.awt.Font("Segoe UI", 0, 18)); // NOI18N
btnTambah.setText("+");
btnTambah.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnTambahActionPerformed(evt);
}
});
btnKurang.setFont(new java.awt.Font("Segoe UI", 0, 18)); // NOI18N
btnKurang.setText("-");
btnKurang.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnKurangActionPerformed(evt);
}
});
btnKali.setFont(new java.awt.Font("Segoe UI", 0, 18)); // NOI18N
btnKali.setText("x");
btnKali.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnKaliActionPerformed(evt);
}
});
btnAngka9.setFont(new java.awt.Font("Segoe UI", 0, 18)); // NOI18N
btnAngka9.setText("9");
btnAngka9.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnAngka9ActionPerformed(evt);
}
});
btnAngka7.setFont(new java.awt.Font("Segoe UI", 0, 18)); // NOI18N
btnAngka7.setText("7");
btnAngka7.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnAngka7ActionPerformed(evt);
}
});
btnAngka8.setFont(new java.awt.Font("Segoe UI", 0, 18)); // NOI18N
btnAngka8.setText("8");
btnAngka8.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnAngka8ActionPerformed(evt);
}
});
btnHapus.setFont(new java.awt.Font("Segoe UI", 0, 18)); // NOI18N
btnHapus.setText("Clear");
btnHapus.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnHapusActionPerformed(evt);
}
});
btnBagi.setFont(new java.awt.Font("Segoe UI", 0, 18)); // NOI18N
btnBagi.setText("/");
btnBagi.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnBagiActionPerformed(evt);
}
});
display.setEditable(false);
display.setBackground(new java.awt.Color(255, 255, 255));
display.setFont(new java.awt.Font("Segoe UI Light", 0, 24)); // NOI18N
display.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
display.setDisabledTextColor(new java.awt.Color(0, 0, 204));
jLabel1.setBackground(new java.awt.Color(153, 0, 153));
jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jLabel1.setForeground(new java.awt.Color(0, 0, 204));
jLabel1.setText("KALKULATOR SEDERHANA");
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(org.jdesktop.layout.GroupLayout.LEADING, jLabel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(org.jdesktop.layout.GroupLayout.LEADING, display)
.add(layout.createSequentialGroup()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
.add(layout.createSequentialGroup()
.add(btnAngka7, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 50, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(18, 18, 18)
.add(btnAngka8, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 50, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(18, 18, 18)
.add(btnAngka9, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 50, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(layout.createSequentialGroup()
.add(btnAngka4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 50, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(18, 18, 18)
.add(btnAngka5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 50, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(18, 18, 18)
.add(btnAngka6, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 50, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(btnHapus, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.add(layout.createSequentialGroup()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
.add(layout.createSequentialGroup()
.add(btnAngka1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 50, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(18, 18, 18)
.add(btnAngka2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 50, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(btnAngka0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.add(18, 18, 18)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
.add(btnKoma, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 50, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(btnAngka3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 50, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))
.add(18, 18, 18)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(btnBagi, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 50, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(btnKali, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 50, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(btnKurang, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 50, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(btnTambah, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 50, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(btnSamadengan, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 50, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(0, 0, Short.MAX_VALUE)))))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
.add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 47, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(display)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(btnHapus, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 50, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(btnBagi, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 50, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(btnAngka9, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 50, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(btnAngka7, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 50, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(btnAngka8, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 50, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(btnKali, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 50, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(btnAngka6, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 50, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(btnKurang, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 50, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(btnAngka4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 50, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(btnAngka5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 50, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(btnAngka1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 50, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(btnAngka2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 50, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(btnAngka3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 50, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(btnTambah, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 50, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(btnAngka0, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 50, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(btnKoma, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 50, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(btnSamadengan, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 50, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addContainerGap())
);
pack();
}// </editor-fold>
private void btnSamadenganActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
switch(pilih){
case 1:
angka2 = Double.parseDouble(angka);
jumlah = angka1 + angka2;
angka = Double.toString(jumlah);
display.setText(angka);
break;
case 2:
angka2 = Double.parseDouble(angka);
jumlah = angka1 - angka2;
angka = Double.toString(jumlah);
display.setText(angka);
break;
case 3:
angka2 = Double.parseDouble(angka);
jumlah = angka1 * angka2;
angka = Double.toString(jumlah);
display.setText(angka);
break;
case 4:
angka2 = Double.parseDouble(angka);
jumlah = angka1 / angka2;
angka = Double.toString(jumlah);
display.setText(angka);
break;
default:
break;
}
}
private void btnAngka0ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka += "0";
display.setText(angka);
}
private void btnAngka1ActionPerformed(java.awt.event.ActionEvent evt) {
angka += "1";
display.setText(angka); // TODO add your handling code here:
}
private void btnAngka3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka += "3";
display.setText(angka);
}
private void btnAngka2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka += "2";
display.setText(angka);
}
private void btnAngka4ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka += "4";
display.setText(angka);
}
private void btnAngka5ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka += "5";
display.setText(angka);
}
private void btnAngka6ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka += "6";
display.setText(angka);
}
private void btnAngka7ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka += "7";
display.setText(angka);
}
private void btnAngka8ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka += "8";
display.setText(angka);
}
private void btnAngka9ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka += "9";
display.setText(angka);
}
private void btnTambahActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka1=Double.parseDouble(angka);
display.setText("+");
angka="";
pilih=1;
}
private void btnKurangActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka1=Double.parseDouble(angka);
display.setText("-");
angka="";
pilih=2;
}
private void btnKaliActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka1=Double.parseDouble(angka);
display.setText("*");
angka="";
pilih=3;
}
private void btnBagiActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka1=Double.parseDouble(angka);
display.setText("/");
angka="";
pilih=4;
}
private void btnHapusActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
display.setText("");
angka1=0.0;
angka2=0.0;
jumlah=0.0;
angka="";
}
private void btnKomaActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka+=".";
display.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(TampilanKalkulator.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(TampilanKalkulator.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(TampilanKalkulator.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(TampilanKalkulator.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 TampilanKalkulator().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton btnAngka0;
private javax.swing.JButton btnAngka1;
private javax.swing.JButton btnAngka2;
private javax.swing.JButton btnAngka3;
private javax.swing.JButton btnAngka4;
private javax.swing.JButton btnAngka5;
private javax.swing.JButton btnAngka6;
private javax.swing.JButton btnAngka7;
private javax.swing.JButton btnAngka8;
private javax.swing.JButton btnAngka9;
private javax.swing.JButton btnBagi;
private javax.swing.JButton btnHapus;
private javax.swing.JButton btnKali;
private javax.swing.JButton btnKoma;
private javax.swing.JButton btnKurang;
private javax.swing.JButton btnSamadengan;
private javax.swing.JButton btnTambah;
private java.awt.Choice choice1;
private javax.swing.JTextField display;
private javax.swing.JColorChooser jColorChooser1;
private javax.swing.JDialog jDialog1;
private javax.swing.JFrame jFrame1;
private javax.swing.JFrame jFrame2;
private javax.swing.JFrame jFrame3;
private javax.swing.JFrame jFrame4;
private javax.swing.JFrame jFrame5;
private javax.swing.JFrame jFrame6;
private javax.swing.JInternalFrame jInternalFrame1;
private javax.swing.JInternalFrame jInternalFrame2;
private javax.swing.JLabel jLabel1;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenu jMenu2;
private javax.swing.JPanel jPanel1;
// End of variables declaration
}
atau bisa di download di
SINI
jika sudah cobalah di run maka hasilnya akan seperti ini :
Terimakasih dan salam luar biasa