Mari kita memulai Uji Coba Logic Calculator kali ini ..
/**
*
* @author AchmadZulfikar
*/
public class simpleCalc extends javax.swing.JFrame {
/** Creates new form simpleCalc */
public simpleCalc() {
initComponents();
}
@SuppressWarnings(“unchecked”)
//
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
a = new javax.swing.JTextField();
b = new javax.swing.JTextField();
c = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
plus = new javax.swing.JButton();
mines = new javax.swing.JButton();
kali = new javax.swing.JButton();
bagi = new javax.swing.JButton();
jButton1 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel2.setText(“=”);
plus.setText(“+”);
plus.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
plusActionPerformed(evt);
}
});
mines.setText(“-”);
mines.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
minesActionPerformed(evt);
}
});
kali.setText(“*”);
kali.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
kaliActionPerformed(evt);
}
});
bagi.setText(“/”);
bagi.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
bagiActionPerformed(evt);
}
});
jButton1.setText(“c”);
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
avax.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)
.addComponent(jLabel1)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(plus)
.addComponent(a, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(b, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(12, 12, 12)
.addComponent(c, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(mines)
.addGap(18, 18, 18)
.addComponent(kali)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jButton1)
.addComponent(bagi))))))
.addContainerGap(142, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(a, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(b, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(c, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2))
.addComponent(jLabel1))
.addGap(37, 37, 37)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(plus)
.addComponent(mines)
.addComponent(kali)
.addComponent(bagi))
.addGap(31, 31, 31)
.addComponent(jButton1)
.addContainerGap(155, Short.MAX_VALUE))
);
pack();
}//
private void plusActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
double calc = Double.parseDouble(a.getText())+Double.parseDouble(b.getText());
c.setText(String.valueOf(calc));
}
private void minesActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
double calc = Double.parseDouble(a.getText())-Double.parseDouble(b.getText());
c.setText(String.valueOf(calc));
}
private void kaliActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
double calc = Double.parseDouble(a.getText())*Double.parseDouble(b.getText());
c.setText(String.valueOf(calc));
}
private void bagiActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
double calc = Double.parseDouble(a.getText())/Double.parseDouble(b.getText());
c.setText(String.valueOf(calc));
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
a.setText(“”);
b.setText(“”);
c.setText(“”);
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new simpleCalc().setVisible(true);
}
});
}
// Variables declaration – do not modify
private javax.swing.JTextField a;
private javax.swing.JTextField b;
private javax.swing.JButton bagi;
private javax.swing.JTextField c;
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JButton kali;
private javax.swing.JButton mines;
private javax.swing.JButton plus;
// End of variables declaration
}
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(plus)
.addComponent(a, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(b, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(12, 12, 12)
.addComponent(c, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(mines)
.addGap(18, 18, 18)
.addComponent(kali)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jButton1)
.addComponent(bagi))))))
.addContainerGap(142, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(a, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(b, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(c, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2))
.addComponent(jLabel1))
.addGap(37, 37, 37)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(plus)
.addComponent(mines)
.addComponent(kali)
.addComponent(bagi))
.addGap(31, 31, 31)
.addComponent(jButton1)
.addContainerGap(155, Short.MAX_VALUE))
);
pack();
}//
private void plusActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
double calc = Double.parseDouble(a.getText())+Double.parseDouble(b.getText());
c.setText(String.valueOf(calc));
}
private void minesActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
double calc = Double.parseDouble(a.getText())-Double.parseDouble(b.getText());
c.setText(String.valueOf(calc));
}
private void kaliActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
double calc = Double.parseDouble(a.getText())*Double.parseDouble(b.getText());
c.setText(String.valueOf(calc));
}
private void bagiActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
double calc = Double.parseDouble(a.getText())/Double.parseDouble(b.getText());
c.setText(String.valueOf(calc));
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
a.setText(“”);
b.setText(“”);
c.setText(“”);
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new simpleCalc().setVisible(true);
}
});
}
// Variables declaration – do not modify
private javax.swing.JTextField a;
private javax.swing.JTextField b;
private javax.swing.JButton bagi;
private javax.swing.JTextField c;
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JButton kali;
private javax.swing.JButton mines;
private javax.swing.JButton plus;
// End of variables declaration
}
Tidak ada komentar:
Posting Komentar