berikut hasil run nya
hasil run untuk menyimpan
package algoritma;
/**
*
* @author zaka
*/
public class kalkulator extends javax.swing.JFrame {
String angka;
Double Hasil,angka1,angka2;
int operator;
/** Creates new form kalkulator */
public kalkulator() {
initComponents();
angka="";
}
berikut source code untuk nomeric:
private void layarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
layar.setText("");
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka+="1";
layar.setText(angka);
}
private void jButton18ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here: angka+="1";
angka+="2";
layar.setText(angka);
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka+="3";
layar.setText(angka);
}
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka+="4";
layar.setText(angka);
}
private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka+="5";
layar.setText(angka);
}
private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka+="6";
layar.setText(angka);
}
private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka+="7";
layar.setText(angka);
}
private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka+="8";
layar.setText(angka);
}
private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka+="9";
layar.setText(angka);
}
private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka+="0";
layar.setText(angka);
}
private void kaliActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka1=Double.parseDouble(angka);
layar.setText("x");
angka="";
operator=1;
}
private void bagiActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka1=Double.parseDouble(angka);
layar.setText("/");
angka="";
operator=2;
}
private void tambahActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka1=Double.parseDouble(angka);
layar.setText("+");
angka="";
operator=3;
}
private void kurangActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka1=Double.parseDouble(angka);
layar.setText("-");
angka="";
operator=4;
}
private void samadenganActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
switch (operator){
case 1:
angka2 = Double.parseDouble(angka);
Hasil = angka1 * angka2;
angka=Double.toString(Hasil);
layar.setText(angka);
break;
case 2:
angka2 = Double.parseDouble(angka);
Hasil = angka1 / angka2;
angka=Double.toString(Hasil);
layar.setText(angka);
break;
case 3:
angka2 = Double.parseDouble(angka);
Hasil = angka1 + angka2;
angka=Double.toString(Hasil);
layar.setText(angka);
break;
case 4:
angka2 = Double.parseDouble(angka);
Hasil = angka1 - angka2;
angka=Double.toString(Hasil);
layar.setText(angka);
break;
default:
break;
}
}
private void komaActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
angka1=Double.parseDouble(angka);
layar.setText(".");
angka="";
operator=5;
}
private void clearActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
layar.setText("");
angka1=0.0;
angka2=0.0;
Hasil=0.0;
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(kalkulator.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(kalkulator.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(kalkulator.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(kalkulator.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 kalkulator().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton bagi;
private javax.swing.JButton clear;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton10;
private javax.swing.JButton jButton18;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JButton jButton5;
private javax.swing.JButton jButton6;
private javax.swing.JButton jButton7;
private javax.swing.JButton jButton8;
private javax.swing.JButton jButton9;
private javax.swing.JButton kali;
private javax.swing.JButton koma;
private javax.swing.JButton kurang;
private javax.swing.JTextField layar;
private javax.swing.JButton samadengan;
private javax.swing.JButton tambah;
// End of variables declaration
}
Tidak ada komentar:
Posting Komentar