![]() |
| Gambar 3.1 Soal |
![]() | |
| Gambar 3.2 Langkah Pertama |
/**
*
* @author Raras
*/
public class Tugas_Praktikum_3 extends javax.swing.JFrame {
int a,b,c;
float d,e,f;
/**
* Creates new form Tugas_Praktikum_3
*/
public Tugas_Praktikum_3() {
initComponents();
}
Adapun source code untuk button tambah (+) yaitu sebagai berikut:
private void bTambahActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
a=Integer.parseInt(Bil1.getText());
b=Integer.parseInt(Bil2.getText());
c=a+b;
Hasil.setText(Integer.toString(c));
}
Adapun source code untuk button kurang (-) yaitu sebagai berikut:
private void bKurangActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
a=Integer.parseInt(Bil1.getText());
b=Integer.parseInt(Bil2.getText());
c=a-b;
Hasil.setText(Integer.toString(c));
}
Adapun source code untuk button kali (*) yaitu sebagai berikut:
private void bKaliActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
d=Float.parseFloat(Bil1.getText());
e=Float.parseFloat(Bil2.getText());
f=d*e;
Hasil.setText(Float.toString(f));
}
Adapun source code untuk button bagi (/) yaitu sebagai berikut:
private void bBagiActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
d=Float.parseFloat(Bil1.getText());
e=Float.parseFloat(Bil2.getText());
f=d/e;
Hasil.setText(Float.toString(f));
}
Adapun source code untuk button maximal (Max) yaitu sebagai berikut:
private void bMaxActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
a=Integer.parseInt(Bil1.getText());
b=Integer.parseInt(Bil2.getText());
if (a>=b){
Hasil.setText(a+"");
}else if(a<=b){
Hasil.setText(b+"");
}
}
Adapun source code untuk button minimal (Min) yaitu sebagai berikut:
private void bMinActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
a=Integer.parseInt(Bil1.getText());
b=Integer.parseInt(Bil2.getText());
if (a<=b){
Hasil.setText(a+"");
}else if(a>=b){
Hasil.setText(b+"");
}
}
Adapun source code untuk button Cleae (C) yaitu sebagai berikut :
private void bClearActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Bil1.setText("");
Bil2.setText("");
Hasil.setText("");
}
Adapun source code untuk button Exit yaitu sebagai berikut :
private void bExitActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
dispose();
}
Jika di Run File maka akan tampil seperti berikut :
![]() |
| Gambar 3.3 Run File |
Jika diklik button Tambah (+), maka akan tampil seperti berikut:
![]() |
| Gambar 3.4 Button Tambah (+) |
![]() |
| Gambar 3.5 Button Kurang (-) |
![]() | |
| Gambar 3.6 Button Kali (*) |
![]() |
| Gambar 3.7 Button Bagi (/) |
![]() |
| Gambar 3.8 Button Max |
![]() | |
| Gambar 3.9 Button Min |
![]() |
| Gambar 3.10 Button Clear (C) |










Tidak ada komentar:
Posting Komentar