Charmouh Abdellah TP CALCULATRICE
Charmouh Abdellah TP CALCULATRICE
Charmouh Abdellah TP CALCULATRICE
Charmouh Abdellah
TP Calculatric Java:
Execution:
Code Source:
package com.mycompany.calcul;
/**
* @author user
*/
/**
* Creates new form calcul
*/
public calcul() {
initComponents();
jRadioButton1.setEnabled(false);
jRadioButton2.setEnabled(true);
double num1,num2,result;
String opr;
jTextField1.setEnabled(true);
jRadioButton1.setEnabled(false);
jRadioButton2.setEnabled(true);
jButton40.setEnabled(true);
jTextField1.setEnabled(false);
jRadioButton1.setEnabled(true);
jRadioButton2.setEnabled(false);
jButton40.setEnabled(true);
/**
* 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
*/
@SuppressWarnings("unchecked")
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("calcul");
setResizable(false);
setType(java.awt.Window.Type.UTILITY);
jTextField1.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
jRadioButton1.setText("ON");
jRadioButton1.addActionListener(new java.awt.event.ActionListener() {
jRadioButton1ActionPerformed(evt);
});
jRadioButton2.setText("OFF");
jRadioButton2.addActionListener(new java.awt.event.ActionListener() {
jRadioButton2ActionPerformed(evt);
});
jButton40.setText("1/x");
jButton40.addActionListener(new java.awt.event.ActionListener() {
jButton40ActionPerformed(evt);
}
});
jButton41.setText("R");
jButton41.addActionListener(new java.awt.event.ActionListener() {
jButton41ActionPerformed(evt);
});
jButton42.setText("x^3");
jButton42.addActionListener(new java.awt.event.ActionListener() {
jButton42ActionPerformed(evt);
});
jButton43.setText("x^y");
jButton43.addActionListener(new java.awt.event.ActionListener() {
jButton43ActionPerformed(evt);
});
jButton44.addActionListener(new java.awt.event.ActionListener() {
jButton44ActionPerformed(evt);
});
jButton47.setText("log");
jButton47.addActionListener(new java.awt.event.ActionListener() {
jButton47ActionPerformed(evt);
});
jButton48.setText("exp");
jButton48.addActionListener(new java.awt.event.ActionListener() {
jButton48ActionPerformed(evt);
});
jButton49.setText("7");
jButton49.addActionListener(new java.awt.event.ActionListener() {
});
jButton50.setText("%");
jButton50.addActionListener(new java.awt.event.ActionListener() {
jButton50ActionPerformed(evt);
});
jButton51.setText("4");
jButton51.addActionListener(new java.awt.event.ActionListener() {
jButton51ActionPerformed(evt);
});
jButton54.setText("sinh");
jButton54.addActionListener(new java.awt.event.ActionListener() {
jButton54ActionPerformed(evt);
});
jButton55.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jButton55.setText("sin");
jButton55.addActionListener(new java.awt.event.ActionListener() {
jButton55ActionPerformed(evt);
});
jButton56.setText("8");
jButton56.addActionListener(new java.awt.event.ActionListener() {
jButton56ActionPerformed(evt);
});
jButton57.setText("Clr");
jButton57.addActionListener(new java.awt.event.ActionListener() {
jButton57ActionPerformed(evt);
});
jButton58.setText("5");
jButton58.addActionListener(new java.awt.event.ActionListener() {
jButton58ActionPerformed(evt);
});
jButton61.setText("cosh");
jButton61.addActionListener(new java.awt.event.ActionListener() {
jButton61ActionPerformed(evt);
});
jButton62.setText("cos");
jButton62.addActionListener(new java.awt.event.ActionListener() {
jButton62ActionPerformed(evt);
});
jButton63.setText("9");
jButton63.addActionListener(new java.awt.event.ActionListener() {
jButton63ActionPerformed(evt);
}
});
jButton64.setText("B");
jButton64.addActionListener(new java.awt.event.ActionListener() {
jButton64ActionPerformed(evt);
});
jButton65.setText("6");
jButton65.addActionListener(new java.awt.event.ActionListener() {
jButton65ActionPerformed(evt);
});
jButton68.setText("tanh");
jButton68.addActionListener(new java.awt.event.ActionListener() {
jButton68ActionPerformed(evt);
});
jButton69.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jButton69.setText("tan");
jButton69.addActionListener(new java.awt.event.ActionListener() {
jButton69ActionPerformed(evt);
});
jButton70.setText("-");
jButton70.addActionListener(new java.awt.event.ActionListener() {
jButton70ActionPerformed(evt);
});
jButton71.setText("+");
jButton71.addActionListener(new java.awt.event.ActionListener() {
jButton71ActionPerformed(evt);
});
jButton72.setText("*");
jButton72.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton72ActionPerformed(evt);
});
jButton73.setText("2");
jButton73.addActionListener(new java.awt.event.ActionListener() {
jButton73ActionPerformed(evt);
});
jButton75.setText(".");
jButton75.addActionListener(new java.awt.event.ActionListener() {
jButton75ActionPerformed(evt);
});
jButton76.setText("3");
jButton76.addActionListener(new java.awt.event.ActionListener() {
jButton76ActionPerformed(evt);
}
});
jButton77.setText("n!");
jButton77.addActionListener(new java.awt.event.ActionListener() {
jButton77ActionPerformed(evt);
});
jButton78.setText("=");
jButton78.addActionListener(new java.awt.event.ActionListener() {
jButton78ActionPerformed(evt);
});
jButton79.setText("+/-");
jButton79.addActionListener(new java.awt.event.ActionListener() {
jButton79ActionPerformed(evt);
});
jButton80.addActionListener(new java.awt.event.ActionListener() {
jButton80ActionPerformed(evt);
});
jButton82.setText("1");
jButton82.addActionListener(new java.awt.event.ActionListener() {
jButton82ActionPerformed(evt);
});
jButton83.setText("0");
jButton83.addActionListener(new java.awt.event.ActionListener() {
jButton83ActionPerformed(evt);
});
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(layout.createSequentialGroup()
.addComponent(jTextField1)
.addContainerGap())
.addGroup(layout.createSequentialGroup()
.addComponent(jRadioButton1)
.addComponent(jRadioButton2)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jButton41)
.addComponent(jButton40)
.addComponent(jButton43)
.addComponent(jButton42)
.addComponent(jButton44))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jButton48)
.addComponent(jButton47)
.addComponent(jButton49, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton50, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton51, javax.swing.GroupLayout.Alignment.TRAILING,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jButton57, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jButton55)
.addComponent(jButton54)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(jButton58, javax.swing.GroupLayout.Alignment.LEADING,
javax.swing.GroupLayout.DEFAULT_SIZE, 57, Short.MAX_VALUE)
.addComponent(jButton56, javax.swing.GroupLayout.Alignment.LEADING,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)))
.addGap(0, 0, Short.MAX_VALUE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jButton62)
.addComponent(jButton61, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton64, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton63, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton65, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jButton69)
.addComponent(jButton68)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(jButton72, javax.swing.GroupLayout.Alignment.LEADING,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
.addComponent(jButton70, javax.swing.GroupLayout.Alignment.LEADING,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
.addComponent(jButton71, javax.swing.GroupLayout.Alignment.LEADING,
javax.swing.GroupLayout.DEFAULT_SIZE, 57, Short.MAX_VALUE))))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(layout.createSequentialGroup()
.addComponent(jButton79, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED))
.addGroup(layout.createSequentialGroup()
.addComponent(jButton77, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGap(6, 6, 6)))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jButton82, javax.swing.GroupLayout.PREFERRED_SIZE, 57,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton76, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createSequentialGroup()
.addComponent(jButton83)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jButton78, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jRadioButton1)
.addComponent(jRadioButton2))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addGroup(layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jButton56, javax.swing.GroupLayout.PREFERRED_SIZE, 47,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(1, 1, 1)
.addGroup(layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton65, javax.swing.GroupLayout.PREFERRED_SIZE, 47,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addContainerGap(64, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
enable();
disable();
double t = 1/(Double.parseDouble(jTextField1.getText()));
jTextField1.setText("");
jTextField1.setText(jTextField1.getText()+ t );
}
private void jButton41ActionPerformed(java.awt.event.ActionEvent evt) {
double t = Math.sqrt(Double.parseDouble(jTextField1.getText()));
jTextField1.setText("");
jTextField1.setText(jTextField1.getText()+ t );
double t = Double.parseDouble(jTextField1.getText());
t=t*t*t;
jTextField1.setText("");
jTextField1.setText(jTextField1.getText() + t);
num1= Double.parseDouble(jTextField1.getText());
jTextField1.setText("");
opr="x^y";
double t = Double.parseDouble(jTextField1.getText());
t=t*t;
jTextField1.setText("");
jTextField1.setText(jTextField1.getText() + t);
}
private void jButton47ActionPerformed(java.awt.event.ActionEvent evt) {
double t = Math.log(Double.parseDouble(jTextField1.getText()));
jTextField1.setText("");
jTextField1.setText(jTextField1.getText()+ t );
double t = Math.exp(Double.parseDouble(jTextField1.getText()));
jTextField1.setText("");
jTextField1.setText(jTextField1.getText()+ t );
jTextField1.setText(jTextField1.getText()+"7");
num1= Double.parseDouble(jTextField1.getText());
jTextField1.setText("");
opr="%";
jTextField1.setText(jTextField1.getText()+"4");
jTextField1.setText("");
jTextField1.setText(jTextField1.getText()+ t );
double t = Math.sin(Double.parseDouble(jTextField1.getText()));
jTextField1.setText("");
jTextField1.setText(jTextField1.getText()+ t );
jTextField1.setText(jTextField1.getText()+"8");
jTextField1.setText("");
jTextField1.setText(jTextField1.getText()+"5");
double t = Math.cosh(Double.parseDouble(jTextField1.getText()));
jTextField1.setText("");
jTextField1.setText(jTextField1.getText()+ t );
}
double t = Math.cos(Double.parseDouble(jTextField1.getText()));
jTextField1.setText("");
jTextField1.setText(jTextField1.getText()+ t );
jTextField1.setText(jTextField1.getText()+"9");
if(jTextField1.getText().length() > 0)
s.deleteCharAt(jTextField1.getText().length()-1);
backSpace = s.toString();
jTextField1.setText(backSpace);
jTextField1.setText(jTextField1.getText()+"6");
}
private void jButton68ActionPerformed(java.awt.event.ActionEvent evt) {
double t = Math.tanh(Double.parseDouble(jTextField1.getText()));
jTextField1.setText("");
jTextField1.setText(jTextField1.getText()+ t );
double t = Math.tan(Double.parseDouble(jTextField1.getText()));
jTextField1.setText("");
jTextField1.setText(jTextField1.getText()+ t );
num1= Double.parseDouble(jTextField1.getText());
jTextField1.setText("");
opr="-";
num1= Double.parseDouble(jTextField1.getText());
jTextField1.setText("");
opr="+";
num1= Double.parseDouble(jTextField1.getText());
jTextField1.setText("");
opr="*";
jTextField1.setText(jTextField1.getText()+"2");
jTextField1.setText(jTextField1.getText()+".");
jTextField1.setText(jTextField1.getText()+"3");
double t = Double.parseDouble(jTextField1.getText());
while(t!=0){
fact = fact*t;
t--;
jTextField1.setText("");
jTextField1.setText(jTextField1.getText() + fact);
}
private void jButton78ActionPerformed(java.awt.event.ActionEvent evt) {
num2= Double.parseDouble(jTextField1.getText());
if(opr=="+")
jTextField1.setText(Double.toString(result));
else if(opr=="-") {
result = num1-num2 ;
jTextField1.setText(Double.toString(result));
else if(opr=="*") {
result = num1*num2 ;
jTextField1.setText(Double.toString(result));
else if(opr=="/") {
result = num1/num2 ;
jTextField1.setText(Double.toString(result));
else if(opr=="%") {
result = num1%num2 ;
jTextField1.setText(Double.toString(result));
else if (opr=="x^y")
jTextField1.setText(Double.toString(result));
num1= Double.parseDouble(jTextField1.getText());
jTextField1.setText("");
opr="/";
jTextField1.setText(jTextField1.getText()+"1");
jTextField1.setText(jTextField1.getText()+"0");
/**
*/
public static void main(String args[]) {
//<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.
*/
try {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
java.util.logging.Logger.getLogger(calcul.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
java.util.logging.Logger.getLogger(calcul.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
java.util.logging.Logger.getLogger(calcul.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
java.util.logging.Logger.getLogger(calcul.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
new calcul().setVisible(true);
});