Aplikasi Calculator sederhana Java Netbeans
Aplikasi Java Calculator Sederhana Netbeans
Buat project dulu klik file new project klik next beri nama calculator ,,,
seperti gambar di bawah ini :
KLik Finish
Seperti gambar di bawah ini :
Setelah itu buat package di source package klik kanan new package
beri nama calculator ,,,
setelah itu klik finish
Setelah membuat package sekarang tgas anda membuat java class
seperti gambar di bawah ,,
cara nya klik kanan di package calculator pilih new java class beri nama
calculator
setelah buat class klo mau ketik atau pun copy terserah anda ,,
nhe codiiiing coy,,
package calculator;
public class Calculator_hitung {
private float first;
private float second;
private float result;
private char operator;
public void setFirst(float first) {
this.first = first;
}
public void setOperator(char operator) {
this.operator = operator;
}
public void setSecond(float second) {
this.second = second;
}
public float getResult() {
return result;
}
public void count() {
switch (this.operator) {
case '+' :
this.result = this.first + this.second;
break;
case '-' :
this.result = this.first - this.second;
break;
case '*' :
this.result = this.first * this.second;
break;
case '/' :
this.result = this.first / this.second;
break;
default:
this.result = 0;
}
}
}
setelah membuat class saat nya kiti membuat Jform nya ,,,
klik kanan pada package pilih JFrame form ,,,
beri nama calculator lalu klik finish,,
seperti gambar ini :
buat desain seperti ini ,,
setelah itu ketik coding di bawah ini :
package calculator;
public class Calculator extends javax.swing.JFrame {
public Calculator() {
initComponents();
setTitle("Calculator Sederhana");
setFont(new java.awt.Font("ARIAL", 0, 10));
}
private void bt_processActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Calculator_hitung ar = new Calculator_hitung();
ar.setFirst(Float.parseFloat(txtFirst.getText()));
ar.setSecond(Float.parseFloat(txtSecond.getText()));
ar.setOperator(cmbOperator.getSelectedItem().toString().charAt(0));
ar.count();
txtResult.setText(ar.getResult() + "");
}
private void btn_resetActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
txtFirst.setText("");
txtSecond.setText("");
txtResult.setText("");
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Calculator().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton bt_process;
private javax.swing.JButton btn_reset;
private javax.swing.JComboBox cmbOperator;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JTextField txtFirst;
private javax.swing.JTextField txtResult;
private javax.swing.JTextField txtSecond;
// End of variables declaration
}
jika berhasil akan muncul aplikasi seperti ini :
download sourcode nya di sini
sekian terima kasih ,,,
0 Response to "Aplikasi Calculator sederhana Java Netbeans"
Post a Comment