Membuat Program Kalkulator Menggunakan Java Netbeans
● Buatlah tampilan seperti diatas dengan menggunakan Item-item yang sudah tersedia di Windows Pallete seperti : label, textfield, textarea, button, panel dll .
● Kalau sudah, saatnya membuat variable nama pada button, textfield, textarea ( contoh textfield : txtBil1, txtBil2, txtHasil )
● Setelah selesai baru kita buat kodingannya di Page Source .
private void btnTambahActionPerformed(java.awt.event.ActionEvent evt) { //tonny-lp2maray
String bil1=txtbil1.getText();
String bil2=txtbil2.getText();
double nbil1=Double.parseDouble(bil1);
double nbil2=Double.parseDouble(bil2);
double hasil=nbil1+nbil2;
String shasil=String.valueOf(hasil);
txthasil.setText(shasil);
}
private void btnKurangActionPerformed(java.awt.event.ActionEvent evt) {
//tonny-lp2maray
//tonny-lp2maray
String bil1=txtbil1.getText();
String bil2=txtbil2.getText();
double nbil1=Double.parseDouble(bil1);
double nbil2=Double.parseDouble(bil2);
double hasil=nbil1-nbil2;
String shasil=String.valueOf(hasil);
txthasil.setText(shasil);
}
private void btnKaliActionPerformed(java.awt.event.ActionEvent evt) {
//tonny-lp2maray
String bil1=txtbil1.getText();
String bil1=txtbil1.getText();
String bil2=txtbil2.getText();
double nbil1=Double.parseDouble(bil1);
double nbil2=Double.parseDouble(bil2);
double hasil=nbil1*nbil2;
String shasil=String.valueOf(hasil);
txthasil.setText(shasil);
}
private void btnBagiActionPerformed(java.awt.event.ActionEvent evt) {
//tonny-lp2maray
String bil1=txtbil1.getText();
String bil1=txtbil1.getText();
String bil2=txtbil2.getText();
double nbil1=Double.parseDouble(bil1);
double nbil2=Double.parseDouble(bil2);
double hasil=nbil1/nbil2;
String shasil=String.valueOf(hasil);
txthasil.setText(shasil);
}
private void btnPangkatActionPerformed(java.awt.event.ActionEvent evt) {
//tonny-lp2maray
String bil1=txtbil1.getText();
String bil1=txtbil1.getText();
String bil2=txtbil2.getText();
double nbil1=Double.parseDouble(bil1);
double nbil2=Double.parseDouble(bil2);
double hasil=Math.pow( nbil1,nbil2);
String shasil=String.valueOf(hasil);
txthasil.setText(shasil);
}
private void btnModActionPerformed(java.awt.event.ActionEvent evt) {
//tonny-lp2maray
String bil1=txtbil1.getText();
String bil1=txtbil1.getText();
String bil2=txtbil2.getText();
double nbil1=Double.parseDouble(bil1);
double nbil2=Double.parseDouble(bil2);
double hasil=nbil1 % nbil2;
String shasil=String.valueOf(hasil);
txthasil.setText(shasil);
}
private void btnbersihActionPerformed(java.awt.event.ActionEvent evt) {
//tonny-lp2maray
txtbil1.setText("");
txtbil1.setText("");
txtbil2.setText("");
txthasil.setText("");
}
private void btnKeluarActionPerformed(java.awt.event.ActionEvent evt) {
//tonny-lp2maray
dispose();
dispose();
}
//------------------------------------------------------------------------------------------------------------------------------
private void btnAkarActionPerformed(java.awt.event.ActionEvent evt) {
//tonny-lp2maray
String Angka=txtAngka.getText();
String Angka=txtAngka.getText();
double nAngka=Double.parseDouble(Angka);
double hasil=Math.sqrt(nAngka);
String shasil=String.valueOf(hasil);
txtHasil.setText(shasil);
}
private void btnSinActionPerformed(java.awt.event.ActionEvent evt) {
//tonny-lp2maray
String Angka=txtAngka.getText();
String Angka=txtAngka.getText();
double nAngka=Double.parseDouble(Angka);
double hasil=Math.sin(nAngka);
String shasil=String.valueOf(hasil);
txtHasil.setText(shasil);
}
private void btnTanActionPerformed(java.awt.event.ActionEvent evt) {
//tonny-lp2maray
String Angka=txtAngka.getText();
String Angka=txtAngka.getText();
double nAngka=Double.parseDouble(Angka);
double hasil=Math.tan(nAngka);
String shasil=String.valueOf(hasil);
txtHasil.setText(shasil);
}
private void btnLogActionPerformed(java.awt.event.ActionEvent evt) {
//tonny-lp2maray
String Angka=txtAngka.getText();
String Angka=txtAngka.getText();
double nAngka=Double.parseDouble(Angka);
double hasil=Math.log(nAngka);
String shasil=String.valueOf(hasil);
txtHasil.setText(shasil);
}
private void btnBersihActionPerformed(java.awt.event.ActionEvent evt) {
//tonny-lp2maray
//tonny-lp2maray
txtAngka.setText("");
txtHasil.setText("");
}
Posting Komentar untuk "Membuat Program Kalkulator Menggunakan Java Netbeans"