Ya Teman - Teman Kali ini saya akan memberikan contoh tentang Kalkulator java sederhana yang pastinya bukan RAWON KALKULATOR ya gan maklum bulan puasa....hehehehehe :D ) pernah saya buat dengan menggunakan bahasa pemograman Java. Mungkin bagi temen - temen yang ingin mengembangkan project saya ini menjadi lebih baik lagi silakan saja.
classkalkulatorjava
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package kalkulatorjava;
/**
*
* @author My Asus
*/
public class Kalkulatorjava {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
}
}
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package kalkulatorjava;
/**
*
* @author My Asus
*/
public class Kalkulatorjava {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
}
}
ClassFrom
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package kalkulatorjava;
/**
*
* @author My Asus
*/
public class form extends javax.swing.JFrame {
private double total1 = 0.0;
private double total2 = 0.0;
private char math_operator;
private void getOperator(String btnText){
math_operator = btnText.charAt(0);
total1 = total1 + Double.parseDouble(text1.getText());
text1.setText("");
}
/**
* Creates new form form
*/
public form() {
initComponents();
}
/**
* 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() {
jButton1 = new javax.swing.JButton();
text1 = new javax.swing.JTextField();
cmd1 = new javax.swing.JButton();
cmd2 = new javax.swing.JButton();
cmd3 = new javax.swing.JButton();
cmd4 = new javax.swing.JButton();
cmd5 = new javax.swing.JButton();
cmd6 = new javax.swing.JButton();
cmd7 = new javax.swing.JButton();
cmd8 = new javax.swing.JButton();
cmd9 = new javax.swing.JButton();
cmdtambah = new javax.swing.JButton();
cmdkurang = new javax.swing.JButton();
cmdkali = new javax.swing.JButton();
cmdclear = new javax.swing.JButton();
cmd0 = new javax.swing.JButton();
cmdsamadengan = new javax.swing.JButton();
cmdbagi = new javax.swing.JButton();
jButton1.setText("jButton1");
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
cmd1.setText("1");
cmd1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmd1ActionPerformed(evt);
}
});
cmd2.setText("2");
cmd2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmd2ActionPerformed(evt);
}
});
cmd3.setText("3");
cmd3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmd3ActionPerformed(evt);
}
});
cmd4.setText("4");
cmd4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmd4ActionPerformed(evt);
}
});
cmd5.setText("5");
cmd5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmd5ActionPerformed(evt);
}
});
cmd6.setText("6");
cmd6.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmd6ActionPerformed(evt);
}
});
cmd7.setText("7");
cmd7.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmd7ActionPerformed(evt);
}
});
cmd8.setText("8");
cmd8.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmd8ActionPerformed(evt);
}
});
cmd9.setText("9");
cmd9.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmd9ActionPerformed(evt);
}
});
cmdtambah.setText("+");
cmdtambah.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmdtambahActionPerformed(evt);
}
});
cmdkurang.setText("-");
cmdkurang.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmdkurangActionPerformed(evt);
}
});
cmdkali.setText("*");
cmdkali.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmdkaliActionPerformed(evt);
}
});
cmdclear.setText("c");
cmdclear.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmdclearActionPerformed(evt);
}
});
cmd0.setText("0");
cmd0.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmd0ActionPerformed(evt);
}
});
cmdsamadengan.setText("=");
cmdsamadengan.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmdsamadenganActionPerformed(evt);
}
});
cmdbagi.setText("/");
cmdbagi.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmdbagiActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(19, 19, 19)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(text1)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(cmdclear, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(cmd7, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 60, Short.MAX_VALUE)
.addComponent(cmd4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(cmd1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(cmd2, javax.swing.GroupLayout.DEFAULT_SIZE, 62, Short.MAX_VALUE)
.addComponent(cmd5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(cmd8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(cmd0, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(cmd3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(cmd6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(cmd9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(cmdsamadengan, javax.swing.GroupLayout.DEFAULT_SIZE, 64, Short.MAX_VALUE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(cmdkali, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(cmdkurang, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(cmdtambah, javax.swing.GroupLayout.DEFAULT_SIZE, 59, Short.MAX_VALUE)
.addComponent(cmdbagi, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
.addGap(0, 20, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(text1, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cmd1)
.addComponent(cmd2)
.addComponent(cmd3)
.addComponent(cmdtambah))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cmd4)
.addComponent(cmd5)
.addComponent(cmd6)
.addComponent(cmdkurang))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cmd7)
.addComponent(cmd8)
.addComponent(cmd9)
.addComponent(cmdkali))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cmdclear)
.addComponent(cmd0)
.addComponent(cmdsamadengan)
.addComponent(cmdbagi))
.addContainerGap(39, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void cmd2ActionPerformed(java.awt.event.ActionEvent evt) {
String cmd2Text = text1.getText() + cmd2.getText();
text1.setText( cmd2Text ); // TODO add your handling code here:
}
private void cmd1ActionPerformed(java.awt.event.ActionEvent evt) {
String cmd1Text = text1.getText() + cmd1.getText();
text1.setText( cmd1Text );
// TODO add your handling code here:
}
private void cmd3ActionPerformed(java.awt.event.ActionEvent evt) {
String cmd3Text = text1.getText() + cmd3.getText();
text1.setText( cmd3Text ); // TODO add your handling code here:
}
private void cmd4ActionPerformed(java.awt.event.ActionEvent evt) {
String cmd4Text = text1.getText() + cmd4.getText();
text1.setText( cmd4Text ); // TODO add your handling code here:
}
private void cmd5ActionPerformed(java.awt.event.ActionEvent evt) {
String cmd5Text = text1.getText() + cmd5.getText();
text1.setText( cmd5Text ); // TODO add your handling code here:
}
private void cmd6ActionPerformed(java.awt.event.ActionEvent evt) {
String cmd6Text = text1.getText() + cmd6.getText();
text1.setText( cmd6Text );
// TODO add your handling code here:
}
private void cmd7ActionPerformed(java.awt.event.ActionEvent evt) {
String cmd7Text = text1.getText() + cmd7.getText();
text1.setText( cmd7Text ); // TODO add your handling code here:
}
private void cmd8ActionPerformed(java.awt.event.ActionEvent evt) {
String cmd8Text = text1.getText() + cmd8.getText();
text1.setText( cmd8Text );
// TODO add your handling code here:
}
private void cmd9ActionPerformed(java.awt.event.ActionEvent evt) {
String cmd9Text = text1.getText() + cmd9.getText();
text1.setText( cmd9Text );
// TODO add your handling code here:
}
private void cmd0ActionPerformed(java.awt.event.ActionEvent evt) {
String cmd0Text = text1.getText() + cmd0.getText();
text1.setText( cmd0Text ); // TODO add your handling code here:
}
private void cmdclearActionPerformed(java.awt.event.ActionEvent evt) {
total2 = 0;
text1.setText(""); // TODO add your handling code here:
}
private void cmdsamadenganActionPerformed(java.awt.event.ActionEvent evt) {
switch (math_operator){
case '+':
total2 = total1 + Double.parseDouble(text1.getText( ) );
break;
case '-':
total2 = total1 - Double.parseDouble(text1.getText( ) );
break;
case '*':
total2 = total1 * Double.parseDouble(text1.getText( ) );
break;
case '/':
total2 = total1 / Double.parseDouble(text1.getText( ) );
break;
}
text1.setText( Double.toString(total2) );
total1 = 0; // TODO add your handling code here:
}
private void cmdtambahActionPerformed(java.awt.event.ActionEvent evt) {
String button_text = cmdtambah.getText();
getOperator(button_text); // TODO add your handling code here:
}
private void cmdkurangActionPerformed(java.awt.event.ActionEvent evt) {
String button_text = cmdkurang.getText();
getOperator(button_text); // TODO add your handling code here:
}
private void cmdkaliActionPerformed(java.awt.event.ActionEvent evt) {
String button_text = cmdkali.getText();
getOperator(button_text);
// TODO add your handling code here:
}
private void cmdbagiActionPerformed(java.awt.event.ActionEvent evt) {
String button_text = cmdbagi.getText();
getOperator(button_text); // 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(form.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(form.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(form.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(form.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 form().setVisible(true);
}
});
}
// 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 cmdkurang;
private javax.swing.JButton cmdsamadengan;
private javax.swing.JButton cmdtambah;
private javax.swing.JButton jButton1;
private javax.swing.JTextField text1;
// End of variables declaration
}
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package kalkulatorjava;
/**
*
* @author My Asus
*/
public class form extends javax.swing.JFrame {
private double total1 = 0.0;
private double total2 = 0.0;
private char math_operator;
private void getOperator(String btnText){
math_operator = btnText.charAt(0);
total1 = total1 + Double.parseDouble(text1.getText());
text1.setText("");
}
/**
* Creates new form form
*/
public form() {
initComponents();
}
/**
* 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() {
jButton1 = new javax.swing.JButton();
text1 = new javax.swing.JTextField();
cmd1 = new javax.swing.JButton();
cmd2 = new javax.swing.JButton();
cmd3 = new javax.swing.JButton();
cmd4 = new javax.swing.JButton();
cmd5 = new javax.swing.JButton();
cmd6 = new javax.swing.JButton();
cmd7 = new javax.swing.JButton();
cmd8 = new javax.swing.JButton();
cmd9 = new javax.swing.JButton();
cmdtambah = new javax.swing.JButton();
cmdkurang = new javax.swing.JButton();
cmdkali = new javax.swing.JButton();
cmdclear = new javax.swing.JButton();
cmd0 = new javax.swing.JButton();
cmdsamadengan = new javax.swing.JButton();
cmdbagi = new javax.swing.JButton();
jButton1.setText("jButton1");
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
cmd1.setText("1");
cmd1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmd1ActionPerformed(evt);
}
});
cmd2.setText("2");
cmd2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmd2ActionPerformed(evt);
}
});
cmd3.setText("3");
cmd3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmd3ActionPerformed(evt);
}
});
cmd4.setText("4");
cmd4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmd4ActionPerformed(evt);
}
});
cmd5.setText("5");
cmd5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmd5ActionPerformed(evt);
}
});
cmd6.setText("6");
cmd6.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmd6ActionPerformed(evt);
}
});
cmd7.setText("7");
cmd7.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmd7ActionPerformed(evt);
}
});
cmd8.setText("8");
cmd8.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmd8ActionPerformed(evt);
}
});
cmd9.setText("9");
cmd9.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmd9ActionPerformed(evt);
}
});
cmdtambah.setText("+");
cmdtambah.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmdtambahActionPerformed(evt);
}
});
cmdkurang.setText("-");
cmdkurang.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmdkurangActionPerformed(evt);
}
});
cmdkali.setText("*");
cmdkali.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmdkaliActionPerformed(evt);
}
});
cmdclear.setText("c");
cmdclear.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmdclearActionPerformed(evt);
}
});
cmd0.setText("0");
cmd0.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmd0ActionPerformed(evt);
}
});
cmdsamadengan.setText("=");
cmdsamadengan.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmdsamadenganActionPerformed(evt);
}
});
cmdbagi.setText("/");
cmdbagi.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmdbagiActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(19, 19, 19)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(text1)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(cmdclear, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(cmd7, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 60, Short.MAX_VALUE)
.addComponent(cmd4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(cmd1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(cmd2, javax.swing.GroupLayout.DEFAULT_SIZE, 62, Short.MAX_VALUE)
.addComponent(cmd5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(cmd8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(cmd0, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(cmd3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(cmd6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(cmd9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(cmdsamadengan, javax.swing.GroupLayout.DEFAULT_SIZE, 64, Short.MAX_VALUE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(cmdkali, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(cmdkurang, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(cmdtambah, javax.swing.GroupLayout.DEFAULT_SIZE, 59, Short.MAX_VALUE)
.addComponent(cmdbagi, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
.addGap(0, 20, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(text1, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cmd1)
.addComponent(cmd2)
.addComponent(cmd3)
.addComponent(cmdtambah))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cmd4)
.addComponent(cmd5)
.addComponent(cmd6)
.addComponent(cmdkurang))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cmd7)
.addComponent(cmd8)
.addComponent(cmd9)
.addComponent(cmdkali))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cmdclear)
.addComponent(cmd0)
.addComponent(cmdsamadengan)
.addComponent(cmdbagi))
.addContainerGap(39, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void cmd2ActionPerformed(java.awt.event.ActionEvent evt) {
String cmd2Text = text1.getText() + cmd2.getText();
text1.setText( cmd2Text ); // TODO add your handling code here:
}
private void cmd1ActionPerformed(java.awt.event.ActionEvent evt) {
String cmd1Text = text1.getText() + cmd1.getText();
text1.setText( cmd1Text );
// TODO add your handling code here:
}
private void cmd3ActionPerformed(java.awt.event.ActionEvent evt) {
String cmd3Text = text1.getText() + cmd3.getText();
text1.setText( cmd3Text ); // TODO add your handling code here:
}
private void cmd4ActionPerformed(java.awt.event.ActionEvent evt) {
String cmd4Text = text1.getText() + cmd4.getText();
text1.setText( cmd4Text ); // TODO add your handling code here:
}
private void cmd5ActionPerformed(java.awt.event.ActionEvent evt) {
String cmd5Text = text1.getText() + cmd5.getText();
text1.setText( cmd5Text ); // TODO add your handling code here:
}
private void cmd6ActionPerformed(java.awt.event.ActionEvent evt) {
String cmd6Text = text1.getText() + cmd6.getText();
text1.setText( cmd6Text );
// TODO add your handling code here:
}
private void cmd7ActionPerformed(java.awt.event.ActionEvent evt) {
String cmd7Text = text1.getText() + cmd7.getText();
text1.setText( cmd7Text ); // TODO add your handling code here:
}
private void cmd8ActionPerformed(java.awt.event.ActionEvent evt) {
String cmd8Text = text1.getText() + cmd8.getText();
text1.setText( cmd8Text );
// TODO add your handling code here:
}
private void cmd9ActionPerformed(java.awt.event.ActionEvent evt) {
String cmd9Text = text1.getText() + cmd9.getText();
text1.setText( cmd9Text );
// TODO add your handling code here:
}
private void cmd0ActionPerformed(java.awt.event.ActionEvent evt) {
String cmd0Text = text1.getText() + cmd0.getText();
text1.setText( cmd0Text ); // TODO add your handling code here:
}
private void cmdclearActionPerformed(java.awt.event.ActionEvent evt) {
total2 = 0;
text1.setText(""); // TODO add your handling code here:
}
private void cmdsamadenganActionPerformed(java.awt.event.ActionEvent evt) {
switch (math_operator){
case '+':
total2 = total1 + Double.parseDouble(text1.getText( ) );
break;
case '-':
total2 = total1 - Double.parseDouble(text1.getText( ) );
break;
case '*':
total2 = total1 * Double.parseDouble(text1.getText( ) );
break;
case '/':
total2 = total1 / Double.parseDouble(text1.getText( ) );
break;
}
text1.setText( Double.toString(total2) );
total1 = 0; // TODO add your handling code here:
}
private void cmdtambahActionPerformed(java.awt.event.ActionEvent evt) {
String button_text = cmdtambah.getText();
getOperator(button_text); // TODO add your handling code here:
}
private void cmdkurangActionPerformed(java.awt.event.ActionEvent evt) {
String button_text = cmdkurang.getText();
getOperator(button_text); // TODO add your handling code here:
}
private void cmdkaliActionPerformed(java.awt.event.ActionEvent evt) {
String button_text = cmdkali.getText();
getOperator(button_text);
// TODO add your handling code here:
}
private void cmdbagiActionPerformed(java.awt.event.ActionEvent evt) {
String button_text = cmdbagi.getText();
getOperator(button_text); // 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(form.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(form.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(form.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(form.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 form().setVisible(true);
}
});
}
// 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 cmdkurang;
private javax.swing.JButton cmdsamadengan;
private javax.swing.JButton cmdtambah;
private javax.swing.JButton jButton1;
private javax.swing.JTextField text1;
// End of variables declaration
}
Dan Berikut Ini Design Tambilanya BOOS
Note : jangan lupa masukkan gambar background, sesuai sobat inginkan.
Terimakasih telah mengunjungi blog saya ini.
Pengunjung yg baik selalu ninggalin jejak :)
Salam Wani Sinau!
Tidak ada komentar:
Posting Komentar