Download

Kalkulator NetBeans IDE 7.0.1


Di dalam pembuatan kalkulator ini terdapat 16 (enam belas tombol Button) dan 1 (satu Text Field).
Di bawah ini merupakan source code dari pembutan kalkulator.

===================================================================
import javax.swing.JOptionPane;
public class calculator extends javax.swing.JFrame {
String button;
Double total,button20,button21;
int pilih;
public calculator() {
initComponents();
button=”";
}
private void button1ActionPerformed(java.awt.event.ActionEvent evt) {
button +=”1″;
hasil.setText(hasil.getText()+button1.getLabel());
}
private void button11ActionPerformed(java.awt.event.ActionEvent evt) {
button +=”0″;
hasil.setText(hasil.getText()+button11.getLabel());
}
private void button2ActionPerformed(java.awt.event.ActionEvent evt) {
button +=”2″;
hasil.setText(hasil.getText()+button2.getLabel());
}
private void button3ActionPerformed(java.awt.event.ActionEvent evt) {
button +=”3″;
hasil.setText(hasil.getText()+button3.getLabel());
}
private void button4ActionPerformed(java.awt.event.ActionEvent evt) {
button +=”4″;
hasil.setText(hasil.getText()+button4.getLabel());
}
private void button5ActionPerformed(java.awt.event.ActionEvent evt) {
button +=”5″;
hasil.setText(hasil.getText()+button5.getLabel());
}
private void button6ActionPerformed(java.awt.event.ActionEvent evt) {
button +=”6″;
hasil.setText(hasil.getText()+button6.getLabel());
}
private void button7ActionPerformed(java.awt.event.ActionEvent evt) {
button +=”7″;
hasil.setText(hasil.getText()+button7.getLabel());
}
private void button8ActionPerformed(java.awt.event.ActionEvent evt) {
button +=”8″;
hasil.setText(hasil.getText()+button8.getLabel());
}
private void button9ActionPerformed(java.awt.event.ActionEvent evt) {
button +=”9″;
hasil.setText(hasil.getText()+button9.getLabel());
}
private void button13ActionPerformed(java.awt.event.ActionEvent evt) {
button20=Double.parseDouble(button);
hasil.setText(hasil.getText()+button13.getLabel());
button=”";
pilih=1;
}
private void button14ActionPerformed(java.awt.event.ActionEvent evt) {
button20=Double.parseDouble(button);
hasil.setText(hasil.getText()+button14.getLabel());
button=”";
pilih=2;
}
private void button15ActionPerformed(java.awt.event.ActionEvent evt) {
button20=Double.parseDouble(button);
hasil.setText(hasil.getText()+button15.getLabel());
button=”";
pilih=3;
}
private void button16ActionPerformed(java.awt.event.ActionEvent evt) {
button20=Double.parseDouble(button);
hasil.setText(hasil.getText()+button16.getLabel());
button=”";
pilih=4;
}
private void button12ActionPerformed(java.awt.event.ActionEvent evt) {
switch(pilih){
case 1:
button21=Double.parseDouble(button);
total=button20+button21;
button=Double.toString(total);
hasil.setText(button);
break;
case 2:
button21=Double.parseDouble(button);
total=button20-button21;
button=Double.toString(total);
hasil.setText(button);
break;
case 3:
button21=Double.parseDouble(button);
total=button20*button21;
button=Double.toString(total);
hasil.setText(button);
break;
case 4:
button21=Double.parseDouble(button);
total=button20/button21;
button=Double.toString(total);
hasil.setText(button);
break;
}
}
private void button17ActionPerformed(java.awt.event.ActionEvent evt) {
button=”";
hasil.setText(“”);
}
private void hasilActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
/**
* @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(calculator.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(calculator.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(calculator.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(calculator.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
new calculator().setVisible(true);
}
});
}
// Variables declaration – do not modify
private java.awt.Button button1;
private java.awt.Button button11;
private java.awt.Button button12;
private java.awt.Button button13;
private java.awt.Button button14;
private java.awt.Button button15;
private java.awt.Button button16;
private java.awt.Button button17;
private java.awt.Button button2;
private java.awt.Button button3;
private java.awt.Button button4;
private java.awt.Button button5;
private java.awt.Button button6;
private java.awt.Button button7;
private java.awt.Button button8;
private java.awt.Button button9;
private javax.swing.JTextField hasil;
private javax.swing.JLabel jLabel1;
private javax.swing.JPanel jPanel1;
// End of variables declaration
}

Share this article :
 
 
Support : Creating Website | Johny Template | Mas Template
Copyright © 2011. EdiHaryanto - All Rights Reserved
Template Created by Creating Website Published by Mas Template
Proudly powered by Blogger