/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* myGUIform.java
*
* Created on Mar 11, 2013, 12:41:23 PM
*/
/**
*
* @author Gharekhani
*/
import javax.swing.JOptionPane;
public class myGUIform extends javax.swing.JFrame {
/** Creates new form myGUIform */
public myGUIform() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
//
private void initComponents() {
answer = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jButton4 = new javax.swing.JButton();
jButton5 = new javax.swing.JButton();
jButton6 = new javax.swing.JButton();
jButton7 = new javax.swing.JButton();
jButton8 = new javax.swing.JButton();
jButton9 = new javax.swing.JButton();
jButton10 = new javax.swing.JButton();
jButton11 = new javax.swing.JButton();
jButton12 = new javax.swing.JButton();
jButton13 = new javax.swing.JButton();
jButton14 = new javax.swing.JButton();
jButton15 = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jButton16 = new javax.swing.JButton();
jButton17 = new javax.swing.JButton();
jButton18 = new javax.swing.JButton();
jButton19 = new javax.swing.JButton();
jButton20 = new javax.swing.JButton();
jButton21 = new javax.swing.JButton();
jButton22 = new javax.swing.JButton();
jButton23 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstan ts.EXIT_ON_CLOSE);
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowOpened(java.awt.event.WindowEvent evt) {
formWindowOpened(evt);
}
});
answer.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
answerActionPerformed(evt);
}
});
jButton1.setText("1");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton2.setText("2");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jButton3.setText("3");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
jButton4.setText("4");
jButton4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton4ActionPerformed(evt);
}
});
jButton5.setText("5");
jButton5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton5ActionPerformed(evt);
}
});
jButton6.setText("6");
jButton6.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton6ActionPerformed(evt);
}
});
jButton7.setText("7");
jButton7.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton7ActionPerformed(evt);
}
});
jButton8.setText("8");
jButton8.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton8ActionPerformed(evt);
}
});
jButton9.setText("9");
jButton9.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton9ActionPerformed(evt);
}
});
jButton10.setText("0");
jButton10.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton10ActionPerformed(evt);
}
});
jButton11.setText("+");
jButton11.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton11ActionPerformed(evt);
}
});
jButton12.setText("-");
jButton12.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton12ActionPerformed(evt);
}
});
jButton13.setText("*");
jButton13.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton13ActionPerformed(evt);
}
});
jButton14.setText("/");
jButton14.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton14ActionPerformed(evt);
}
});
jButton15.setText("=");
jButton15.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton15ActionPerformed(evt);
}
});
jButton16.setText("pow");
jButton16.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton16ActionPerformed(evt);
}
});
jButton17.setText("abs");
jButton17.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton17ActionPerformed(evt);
}
});
jButton18.setText("log");
jButton18.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton18ActionPerformed(evt);
}
});
jButton19.setText("sqrt");
jButton19.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton19ActionPerformed(evt);
}
});
jButton20.setText("cos");
jButton20.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton20ActionPerformed(evt);
}
});
jButton21.setText("sin");
jButton21.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton21ActionPerformed(evt);
}
});
jButton22.setText("tan");
jButton22.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton22ActionPerformed(evt);
}
});
jButton23.setText("Exit");
jButton23.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton23ActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILI NG, layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.TRAILING)
.addComponent(answer, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 373, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.TRAILING)
.addComponent(jLabel1)
.addComponent(jLabel2))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jButton1)
.addPreferredGap(javax.swing.LayoutStyle.Component Placement.UNRELATED)
.addComponent(jButton2))
.addGroup(layout.createSequentialGroup()
.addComponent(jButton4)
.addPreferredGap(javax.swing.LayoutStyle.Component Placement.UNRELATED)
.addComponent(jButton5))
.addGroup(layout.createSequentialGroup()
.addComponent(jButton7)
.addPreferredGap(javax.swing.LayoutStyle.Component Placement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
.addComponent(jButton8)
.addComponent(jButton10))))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILI NG, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
.addComponent(jButton3)
.addComponent(jButton6)
.addComponent(jButton9))
.addPreferredGap(javax.swing.LayoutStyle.Component Placement.RELATED, 22, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING, false)
.addComponent(jButton11, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton12, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 41, Short.MAX_VALUE)
.addComponent(jButton14, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton13, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING, false)
.addComponent(jButton17, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton19, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton16, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton18, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING, false)
.addComponent(jButton15, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton22, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton21, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton20, javax.swing.GroupLayout.DEFAULT_SIZE, 58, Short.MAX_VALUE)))
.addComponent(jButton23, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGap(21, 21, 21))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(answer, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.BASELINE)
.addComponent(jButton16)
.addComponent(jButton20))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.BASELINE)
.addComponent(jButton18)
.addComponent(jButton21))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(41, 41, 41)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.BASELINE)
.addComponent(jButton19)
.addComponent(jButton15)))
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.BASELINE)
.addComponent(jButton17)
.addComponent(jButton22))))
.addGroup(layout.createSequentialGroup()
.addComponent(jButton11)
.addGap(18, 18, 18)
.addComponent(jButton12)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(41, 41, 41)
.addComponent(jButton14))
.addComponent(jButton13)))))
.addGroup(layout.createSequentialGroup()
.addGap(66, 66, 66)
.addComponent(jLabel1)
.addGap(0, 0, 0)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jButton2))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.BASELINE)
.addComponent(jButton4)
.addComponent(jButton5))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.BASELINE)
.addComponent(jButton7)
.addComponent(jButton8))
.addGap(18, 18, 18)
.addComponent(jButton10))
.addGroup(layout.createSequentialGroup()
.addComponent(jButton3)
.addGap(18, 18, 18)
.addComponent(jButton6)
.addGap(18, 18, 18)
.addComponent(jButton9))
.addComponent(jLabel2))))
.addPreferredGap(javax.swing.LayoutStyle.Component Placement.RELATED, 30, Short.MAX_VALUE)
.addComponent(jButton23, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
pack();
}//
private void jButton11ActionPerformed(java.awt.event.ActionEven t evt) {
// TODO add your handling code here:
this.jLabel1.setText(this.answer.getText());
this.answer.setText("");
this.jLabel2.setText("+");
}
private void answerActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.answer.setText(this.answer.getText() + "1");
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.answer.setText(this.answer.getText() + "2");
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here
this.answer.setText(this.answer.getText() + "3");
}
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.answer.setText(this.answer.getText() + "4");
}
private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.answer.setText(this.answer.getText() + "5");
}
private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.answer.setText(this.answer.getText() + "6");
}
private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.answer.setText(this.answer.getText() + "7");
}
private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.answer.setText(this.answer.getText() + "8");
}
private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.answer.setText(this.answer.getText() + "9");
}
private void jButton10ActionPerformed(java.awt.event.ActionEven t evt) {
// TODO add your handling code here:
this.answer.setText(this.answer.getText() + "0");
}
private void jButton12ActionPerformed(java.awt.event.ActionEven t evt) {
// TODO add your handling code here:
this.jLabel1.setText(this.answer.getText());
this.answer.setText("");
this.jLabel2.setText("-");
}
private void jButton13ActionPerformed(java.awt.event.ActionEven t evt) {
// TODO add your handling code here:
this.jLabel1.setText(this.answer.getText());
this.answer.setText("");
this.jLabel2.setText("*");
}
private void jButton14ActionPerformed(java.awt.event.ActionEven t evt) {
// TODO add your handling code here:
this.jLabel1.setText(this.answer.getText());
this.answer.setText("");
this.jLabel2.setText("/");
}
private void jButton15ActionPerformed(java.awt.event.ActionEven t evt) {
// TODO add your handling code here:
int n1 = 0, n2 = 0;
double n3 = 0;
n1 = Integer.parseInt(this.answer.getText());
n2 = Integer.parseInt(this.jLabel1.getText());
if ("+".equals(this.jLabel2.getText())) {
n3 = n2 + n1;
} else if ("-".equals(this.jLabel2.getText())) {
n3 = n2 - n1;
} else if ("*".equals(this.jLabel2.getText())) {
n3 = n2 * n1;
} else if ("/".equals(this.jLabel2.getText())) {
n3 = n2 / n1;
} else if ("^".equals(this.jLabel2.getText())) {
n3 = Math.pow(n2, n1);
}
this.answer.setText("" + n3);
}
private void formWindowOpened(java.awt.event.WindowEvent evt) {
// TODO add your handling code here:
this.jLabel1.setVisible(false);
this.jLabel2.setVisible(false);
}
private void jButton17ActionPerformed(java.awt.event.ActionEven t evt) {
// TODO add your handling code here:
int n1 = 0, n2 = 0;
n1 = Integer.parseInt(this.answer.getText());
n2 = Math.abs(n1);
this.answer.setText("" + n2);
}
private void jButton16ActionPerformed(java.awt.event.ActionEven t evt) {
// TODO add your handling code here:
this.jLabel1.setText(this.answer.getText());
this.answer.setText("");
this.jLabel2.setText("^");
}
private void jButton18ActionPerformed(java.awt.event.ActionEven t evt) {
// TODO add your handling code here:
int n1 = 0;
double n2 = 0;
n1 = Integer.parseInt(this.answer.getText());
n2 = Math.log(n1);
this.answer.setText("" + n2);
}
private void jButton19ActionPerformed(java.awt.event.ActionEven t evt) {
// TODO add your handling code here:
double n1 = 0, n2 = 0;
n1 = Integer.parseInt(this.answer.getText());
n2 = Math.sqrt(n1);
this.answer.setText("" + n2);
}
private void jButton20ActionPerformed(java.awt.event.ActionEven t evt) {
// TODO add your handling code here:
double n1 = 0, n2 = 0;
n1 = Integer.parseInt(this.answer.getText());
n2 = Math.cos(n1);
this.answer.setText("" + n2);
}
private void jButton21ActionPerformed(java.awt.event.ActionEven t evt) {
// TODO add your handling code here:
double n1 = 0, n2 = 0;
n1 = Integer.parseInt(this.answer.getText());
n2 = Math.sin(n1);
this.answer.setText("" + n2);
}
private void jButton22ActionPerformed(java.awt.event.ActionEven t evt) {
// TODO add your handling code here:
double n1 = 0, n2 = 0;
n1 = Integer.parseInt(this.answer.getText());
n2 = Math.tan(n1);
this.answer.setText("" + n2);
}
private void jButton23ActionPerformed(java.awt.event.ActionEven t evt) {
// TODO add your handling code here:
int result = JOptionPane.showConfirmDialog(null,"Are you sure ?",null,
JOptionPane.YES_NO_OPTION);
if(result==0)
System.exit(0);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//
/* 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/tu...feel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClass Name());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(myGUIform.class .getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(myGUIform.class .getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(myGUIform.class .getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(myGUIform.class .getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new myGUIform().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JTextField answer;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton10;
private javax.swing.JButton jButton11;
private javax.swing.JButton jButton12;
private javax.swing.JButton jButton13;
private javax.swing.JButton jButton14;
private javax.swing.JButton jButton15;
private javax.swing.JButton jButton16;
private javax.swing.JButton jButton17;
private javax.swing.JButton jButton18;
private javax.swing.JButton jButton19;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton20;
private javax.swing.JButton jButton21;
private javax.swing.JButton jButton22;
private javax.swing.JButton jButton23;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JButton jButton5;
private javax.swing.JButton jButton6;
private javax.swing.JButton jButton7;
private javax.swing.JButton jButton8;
private javax.swing.JButton jButton9;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
// End of variables declaration
}