package tugas03;
public class JTugas03 extends javax.swing.JFrame {
String angka;
Double jumlah, bil1, bil2;
int option;
public JTugas03() {
initComponents();
angka = "";
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jButton1 = new javax.swing.JButton();
layar = new javax.swing.JTextField();
btnTujuh = new javax.swing.JButton();
btnEmpat = new javax.swing.JButton();
btnSatu = new javax.swing.JButton();
btnNol = new javax.swing.JButton();
btnDelapan = new javax.swing.JButton();
btnLima = new javax.swing.JButton();
btnDua = new javax.swing.JButton();
btnTiga = new javax.swing.JButton();
btnEnam = new javax.swing.JButton();
btnSembilan = new javax.swing.JButton();
btnKoma = new javax.swing.JButton();
btnClear = new javax.swing.JButton();
btnKali = new javax.swing.JButton();
btnBagi = new javax.swing.JButton();
btnKurang = new javax.swing.JButton();
btnTambah = new javax.swing.JButton();
btnEqual = new javax.swing.JButton();
jButton1.setText("jButton1");
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("CALC");
setBackground(new java.awt.Color(255, 29, 29));
setForeground(java.awt.Color.magenta);
setPreferredSize(new java.awt.Dimension(230, 320));
layar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
layarActionPerformed(evt);
}
});
btnTujuh.setText("7");
btnTujuh.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnTujuhActionPerformed(evt);
}
});
btnEmpat.setText("4");
btnEmpat.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnEmpatActionPerformed(evt);
}
});
btnSatu.setText("1");
btnSatu.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnSatuActionPerformed(evt);
}
});
btnNol.setText("0");
btnNol.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnNolActionPerformed(evt);
}
});
btnDelapan.setText("8");
btnDelapan.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnDelapanActionPerformed(evt);
}
});
btnLima.setText("5");
btnLima.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnLimaActionPerformed(evt);
}
});
btnDua.setText("2");
btnDua.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnDuaActionPerformed(evt);
}
});
btnTiga.setText("3");
btnTiga.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnTigaActionPerformed(evt);
}
});
btnEnam.setText("6");
btnEnam.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnEnamActionPerformed(evt);
}
});
btnSembilan.setText("9");
btnSembilan.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnSembilanActionPerformed(evt);
}
});
btnKoma.setText(".");
btnKoma.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnKomaActionPerformed(evt);
}
});
btnClear.setText("C");
btnClear.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnClearActionPerformed(evt);
}
});
btnKali.setText("*");
btnKali.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnKaliActionPerformed(evt);
}
});
btnBagi.setText("/");
btnBagi.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnBagiActionPerformed(evt);
}
});
btnKurang.setText("-");
btnKurang.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnKurangActionPerformed(evt);
}
});
btnTambah.setText("+");
btnTambah.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnTambahActionPerformed(evt);
}
});
btnEqual.setText("=");
btnEqual.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnEqualActionPerformed(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()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(btnTujuh, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnDelapan, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnSembilan, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addComponent(btnEmpat, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnLima, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnEnam, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addComponent(btnSatu, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnDua, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnTiga, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)))))
.addGroup(layout.createSequentialGroup()
.addComponent(btnNol, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnKoma, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(btnTambah, javax.swing.GroupLayout.DEFAULT_SIZE, 45, Short.MAX_VALUE)
.addComponent(btnEqual, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGap(271, 271, 271))
.addGroup(layout.createSequentialGroup()
.addComponent(layar, javax.swing.GroupLayout.PREFERRED_SIZE, 198, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addComponent(btnClear, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnBagi, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnKali, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnKurang, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE))))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(49, 49, 49)
.addComponent(layar, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(13, 13, 13)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnClear, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnBagi, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnKali, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnKurang, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(btnTambah, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnDelapan, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnTujuh, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnSembilan, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(btnEnam, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnLima, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnEmpat, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnDua, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnSatu, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnTiga, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnNol, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnKoma, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addComponent(btnEqual, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
.addContainerGap(269, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void layarActionPerformed(java.awt.event.ActionEvent evt) {
layar.setText("");
// TODO add your handling code here:
}
private void btnNolActionPerformed(java.awt.event.ActionEvent evt) {
angka += "0";
layar.setText(angka);
// TODO add your handling code here:
}
private void btnSatuActionPerformed(java.awt.event.ActionEvent evt) {
angka += "1";
layar.setText(angka);
// TODO add your handling code here:
}
private void btnDuaActionPerformed(java.awt.event.ActionEvent evt) {
angka += "2";
layar.setText(angka);
// TODO add your handling code here:
}
private void btnTigaActionPerformed(java.awt.event.ActionEvent evt) {
angka += "3";
layar.setText(angka);
// TODO add your handling code here:
}
private void btnEmpatActionPerformed(java.awt.event.ActionEvent evt) {
angka += "4";
layar.setText(angka);
// TODO add your handling code here:
}
private void btnLimaActionPerformed(java.awt.event.ActionEvent evt) {
angka += "5";
layar.setText(angka);
// TODO add your handling code here:
}
private void btnEnamActionPerformed(java.awt.event.ActionEvent evt) {
angka += "6";
layar.setText(angka);
// TODO add your handling code here:
}
private void btnTujuhActionPerformed(java.awt.event.ActionEvent evt) {
angka += "7";
layar.setText(angka);
// TODO add your handling code here:
}
private void btnDelapanActionPerformed(java.awt.event.ActionEvent evt) {
angka += "8";
layar.setText(angka);
// TODO add your handling code here:
}
private void btnSembilanActionPerformed(java.awt.event.ActionEvent evt) {
angka += "9";
layar.setText(angka);
// TODO add your handling code here:
}
private void btnEqualActionPerformed(java.awt.event.ActionEvent evt) {
switch(option) {
case 1:
bil2 = Double.parseDouble(angka);
jumlah = bil1 + bil2;
angka = Double.toString(jumlah);
layar.setText(angka);
break;
case 2:
bil2 = Double.parseDouble(angka);
jumlah = bil1 - bil2;
angka = Double.toString(jumlah);
layar.setText(angka);
break;
case 3:
bil2 = Double.parseDouble(angka);
jumlah = bil1 * bil2;
angka = Double.toString(jumlah);
layar.setText(angka);
break;
case 4:
bil2 = Double.parseDouble(angka);
jumlah = bil1 / bil2;
angka = Double.toString(jumlah);
layar.setText(angka);
break;
default:
break;
}
// TODO add your handling code here:
}
private void btnTambahActionPerformed(java.awt.event.ActionEvent evt) {
bil1 = Double.parseDouble(angka);
layar.setText("+");
angka = "";
option = 1;
// TODO add your handling code here:
}
private void btnKurangActionPerformed(java.awt.event.ActionEvent evt) {
bil1 = Double.parseDouble(angka);
layar.setText("-");
angka = "";
option = 2;
// TODO add your handling code here:
}
private void btnKaliActionPerformed(java.awt.event.ActionEvent evt) {
bil1 = Double.parseDouble(angka);
layar.setText("*");
angka = "";
option = 3;
// TODO add your handling code here:
}
private void btnBagiActionPerformed(java.awt.event.ActionEvent evt) {
bil1 = Double.parseDouble(angka);
layar.setText("/");
angka = "";
option = 4;
// TODO add your handling code here:
}
private void btnKomaActionPerformed(java.awt.event.ActionEvent evt) {
angka += ".";
layar.setText(angka);
// TODO add your handling code here:
}
private void btnClearActionPerformed(java.awt.event.ActionEvent evt) {
angka = "";
layar.setText("0");
// 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(JTugas03.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(JTugas03.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(JTugas03.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(JTugas03.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 JTugas03().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton btnBagi;
private javax.swing.JButton btnClear;
private javax.swing.JButton btnDelapan;
private javax.swing.JButton btnDua;
private javax.swing.JButton btnEmpat;
private javax.swing.JButton btnEnam;
private javax.swing.JButton btnEqual;
private javax.swing.JButton btnKali;
private javax.swing.JButton btnKoma;
private javax.swing.JButton btnKurang;
private javax.swing.JButton btnLima;
private javax.swing.JButton btnNol;
private javax.swing.JButton btnSatu;
private javax.swing.JButton btnSembilan;
private javax.swing.JButton btnTambah;
private javax.swing.JButton btnTiga;
private javax.swing.JButton btnTujuh;
private javax.swing.JButton jButton1;
private javax.swing.JTextField layar;
// End of variables declaration
}
About Syed Faizan Ali
Faizan is a 17 year old young guy who is blessed with the art of Blogging,He love to Blog day in and day out,He is a Website Designer and a Certified Graphics Designer.
0 komentar:
Posting Komentar