Aplikasi Calculator Sederhana Java Netbeans
Aplikasi Java Calculator Sederhana Netbeans
Buat project dulu klik file new project klik next beri nama calculator ,,,
ibarat 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 ,,,
sehabis itu klik finish
Setelah menciptakan package kini tgas anda menciptakan java class
ibarat gambar di bawah ,,
cara nya klik kanan di package calculator pilih new java class beri nama
calculator
sehabis 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;
}
}
}
sehabis menciptakan class dikala nya kiti menciptakan Jform nya ,,,
klik kanan pada package pilih JFrame form ,,,
beri nama calculator kemudian klik finish,,
ibarat gambar ini :
buat desain ibarat ini ,,
sehabis 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
}
jikalau berhasil akan muncul aplikasi ibarat ini :
download sourcode nya di sini
sekian terima kasih ,,,
Belum ada Komentar untuk "Aplikasi Calculator Sederhana Java Netbeans"
Posting Komentar