You are on page 1of 17

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

package calculatrice1;

/**

* @author Dieu-merci

*/

public class FrmCalculatrice extends javax.swing.JFrame {

/**

* Creates new form FrmCalculatrice

*/

public FrmCalculatrice() {

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")

// <editor-fold defaultstate="collapsed" desc="Generated Code">

private void initComponents() {

jPanel1 = new javax.swing.JPanel();

Txtnombre = new javax.swing.JTextField();


Btn1 = new javax.swing.JButton();

Btn2 = new javax.swing.JButton();

Btn3 = new javax.swing.JButton();

Btn4 = new javax.swing.JButton();

Btn5 = new javax.swing.JButton();

Btn6 = new javax.swing.JButton();

Btn7 = new javax.swing.JButton();

Btn8 = new javax.swing.JButton();

Btn9 = new javax.swing.JButton();

Btnplus = new javax.swing.JButton();

Btnmoin = new javax.swing.JButton();

Btn0 = new javax.swing.JButton();

Btndiv = new javax.swing.JButton();

Btnproduit = new javax.swing.JButton();

Btnplusmoin = new javax.swing.JButton();

Btnvirgule = new javax.swing.JButton();

Btnclean = new javax.swing.JButton();

Btnegale = new javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

Txtnombre.setBackground(new java.awt.Color(204, 255, 255));

Txtnombre.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N

Txtnombre.setHorizontalAlignment(javax.swing.JTextField.RIGHT);

Btn1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N

Btn1.setText("1");

Btn1.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

Btn1ActionPerformed(evt);

}
});

Btn2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N

Btn2.setText("2");

Btn2.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

Btn2ActionPerformed(evt);

});

Btn3.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N

Btn3.setText("3");

Btn3.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

Btn3ActionPerformed(evt);

});

Btn4.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N

Btn4.setText("4");

Btn4.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

Btn4ActionPerformed(evt);

});

Btn5.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N

Btn5.setText("5");

Btn5.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

Btn5ActionPerformed(evt);
}

});

Btn6.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N

Btn6.setText("6");

Btn6.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

Btn6ActionPerformed(evt);

});

Btn7.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N

Btn7.setText("7");

Btn7.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

Btn7ActionPerformed(evt);

});

Btn8.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N

Btn8.setText("8");

Btn8.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

Btn8ActionPerformed(evt);

});

Btn9.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N

Btn9.setText("9");

Btn9.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {


Btn9ActionPerformed(evt);

});

Btnplus.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N

Btnplus.setText("+");

Btnplus.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

BtnplusActionPerformed(evt);

});

Btnmoin.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N

Btnmoin.setText("-");

Btnmoin.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

BtnmoinActionPerformed(evt);

});

Btn0.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N

Btn0.setText("0");

Btn0.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

Btn0ActionPerformed(evt);

});

Btndiv.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N

Btndiv.setText("/");

Btndiv.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {

BtndivActionPerformed(evt);

});

Btnproduit.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N

Btnproduit.setText("*");

Btnproduit.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

BtnproduitActionPerformed(evt);

});

Btnplusmoin.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

Btnplusmoin.setText("+/-");

Btnplusmoin.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

BtnplusmoinActionPerformed(evt);

});

Btnvirgule.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N

Btnvirgule.setText(".");

Btnvirgule.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

BtnvirguleActionPerformed(evt);

});

Btnclean.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N

Btnclean.setText("C");
Btnclean.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

BtncleanActionPerformed(evt);

});

Btnegale.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N

Btnegale.setText("=");

Btnegale.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

BtnegaleActionPerformed(evt);

});

javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);

jPanel1.setLayout(jPanel1Layout);

jPanel1Layout.setHorizontalGroup(

jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(jPanel1Layout.createSequentialGroup()

.addContainerGap()

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING
)

.addGroup(jPanel1Layout.createSequentialGroup()

.addComponent(Txtnombre)

.addContainerGap())

.addGroup(jPanel1Layout.createSequentialGroup()

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEA
DING, false)

.addGroup(jPanel1Layout.createSequentialGroup()

.addComponent(Btn1, javax.swing.GroupLayout.PREFERRED_SIZE, 50,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(Btn2, javax.swing.GroupLayout.PREFERRED_SIZE, 50,
javax.swing.GroupLayout.PREFERRED_SIZE)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(Btn3, javax.swing.GroupLayout.PREFERRED_SIZE, 50,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(Btn4, javax.swing.GroupLayout.PREFERRED_SIZE, 50,


javax.swing.GroupLayout.PREFERRED_SIZE))

.addGroup(jPanel1Layout.createSequentialGroup()

.addComponent(Btn5, javax.swing.GroupLayout.PREFERRED_SIZE, 50,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(Btn6, javax.swing.GroupLayout.PREFERRED_SIZE, 50,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(Btn7, javax.swing.GroupLayout.PREFERRED_SIZE, 50,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(Btn8, javax.swing.GroupLayout.PREFERRED_SIZE, 50,


javax.swing.GroupLayout.PREFERRED_SIZE))

.addGroup(jPanel1Layout.createSequentialGroup()

.addComponent(Btn9, javax.swing.GroupLayout.PREFERRED_SIZE, 50,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(Btn0, javax.swing.GroupLayout.PREFERRED_SIZE, 50,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(Btnplus, javax.swing.GroupLayout.PREFERRED_SIZE, 50,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(Btnmoin, javax.swing.GroupLayout.PREFERRED_SIZE, 50,


javax.swing.GroupLayout.PREFERRED_SIZE))

.addGroup(jPanel1Layout.createSequentialGroup()

.addComponent(Btndiv, javax.swing.GroupLayout.PREFERRED_SIZE, 50,


javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(Btnproduit, javax.swing.GroupLayout.PREFERRED_SIZE, 50,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(Btnplusmoin, javax.swing.GroupLayout.PREFERRED_SIZE, 50,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(Btnvirgule, javax.swing.GroupLayout.PREFERRED_SIZE, 50,


javax.swing.GroupLayout.PREFERRED_SIZE))

.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
jPanel1Layout.createSequentialGroup()

.addComponent(Btnclean, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(Btnegale, javax.swing.GroupLayout.PREFERRED_SIZE, 106,


javax.swing.GroupLayout.PREFERRED_SIZE)))

.addGap(0, 16, Short.MAX_VALUE))))

);

jPanel1Layout.setVerticalGroup(

jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(jPanel1Layout.createSequentialGroup()

.addContainerGap()

.addComponent(Txtnombre, javax.swing.GroupLayout.PREFERRED_SIZE, 38,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addGap(18, 18, 18)

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELIN
E)

.addComponent(Btn1, javax.swing.GroupLayout.PREFERRED_SIZE, 41,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(Btn2, javax.swing.GroupLayout.PREFERRED_SIZE, 41,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(Btn3, javax.swing.GroupLayout.PREFERRED_SIZE, 41,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(Btn4, javax.swing.GroupLayout.PREFERRED_SIZE, 41,


javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELIN
E)

.addComponent(Btn5, javax.swing.GroupLayout.PREFERRED_SIZE, 41,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(Btn6, javax.swing.GroupLayout.PREFERRED_SIZE, 41,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(Btn7, javax.swing.GroupLayout.PREFERRED_SIZE, 41,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(Btn8, javax.swing.GroupLayout.PREFERRED_SIZE, 41,


javax.swing.GroupLayout.PREFERRED_SIZE))

.addGap(18, 18, 18)

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELIN
E)

.addComponent(Btn9, javax.swing.GroupLayout.PREFERRED_SIZE, 41,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(Btn0, javax.swing.GroupLayout.PREFERRED_SIZE, 41,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(Btnplus, javax.swing.GroupLayout.PREFERRED_SIZE, 41,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(Btnmoin, javax.swing.GroupLayout.PREFERRED_SIZE, 41,


javax.swing.GroupLayout.PREFERRED_SIZE))

.addGap(18, 18, 18)

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELIN
E)

.addComponent(Btndiv, javax.swing.GroupLayout.PREFERRED_SIZE, 41,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(Btnproduit, javax.swing.GroupLayout.PREFERRED_SIZE, 41,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(Btnplusmoin, javax.swing.GroupLayout.PREFERRED_SIZE, 41,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(Btnvirgule, javax.swing.GroupLayout.PREFERRED_SIZE, 41,


javax.swing.GroupLayout.PREFERRED_SIZE))

.addGap(18, 18, 18)

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELIN
E)
.addComponent(Btnclean, javax.swing.GroupLayout.PREFERRED_SIZE, 41,
javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(Btnegale, javax.swing.GroupLayout.PREFERRED_SIZE, 41,


javax.swing.GroupLayout.PREFERRED_SIZE))

.addContainerGap(26, Short.MAX_VALUE))

);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());

getContentPane().setLayout(layout);

layout.setHorizontalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

);

layout.setVerticalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

);

pack();

}// </editor-fold>

private void Btn1ActionPerformed(java.awt.event.ActionEvent evt) {

String nombreSaisie = Txtnombre.getText()+Btn1.getText();

Txtnombre.setText(nombreSaisie);

private void Btn2ActionPerformed(java.awt.event.ActionEvent evt) {

String nombreSaisie = Txtnombre.getText()+Btn2.getText();


Txtnombre.setText(nombreSaisie);

private void BtnvirguleActionPerformed(java.awt.event.ActionEvent evt) {

String ch = Txtnombre.getText();

if((ch.indexOf('.')==-1)&&!(ch.isEmpty())){

String nombreSaisie=Txtnombre.getText()+Btnvirgule.getText();

Txtnombre.setText(nombreSaisie);

private void Btn3ActionPerformed(java.awt.event.ActionEvent evt) {

String nombreSaisie = Txtnombre.getText()+Btn3.getText();

Txtnombre.setText(nombreSaisie);

private void Btn4ActionPerformed(java.awt.event.ActionEvent evt) {

String nombreSaisie = Txtnombre.getText()+Btn4.getText();

Txtnombre.setText(nombreSaisie);

private void Btn5ActionPerformed(java.awt.event.ActionEvent evt) {

String nombreSaisie = Txtnombre.getText()+Btn5.getText();

Txtnombre.setText(nombreSaisie);

private void Btn6ActionPerformed(java.awt.event.ActionEvent evt) {

String nombreSaisie = Txtnombre.getText()+Btn6.getText();

Txtnombre.setText(nombreSaisie);

}
private void Btn7ActionPerformed(java.awt.event.ActionEvent evt) {

String nombreSaisie = Txtnombre.getText()+Btn7.getText();

Txtnombre.setText(nombreSaisie);

private void Btn8ActionPerformed(java.awt.event.ActionEvent evt) {

String nombreSaisie = Txtnombre.getText()+Btn8.getText();

Txtnombre.setText(nombreSaisie);

private void Btn9ActionPerformed(java.awt.event.ActionEvent evt) {

String nombreSaisie = Txtnombre.getText()+Btn9.getText();

Txtnombre.setText(nombreSaisie);

private void Btn0ActionPerformed(java.awt.event.ActionEvent evt) {

String nombreSaisie = Txtnombre.getText()+Btn0.getText();

Txtnombre.setText(nombreSaisie);

private void BtncleanActionPerformed(java.awt.event.ActionEvent evt) {

Txtnombre.setText("");

double num1,num2,res;

String opperation;

private void BtnplusActionPerformed(java.awt.event.ActionEvent evt) {

num1 = Double.parseDouble(Txtnombre.getText());

opperation = "+";

Txtnombre.setText("");
}

private void BtnmoinActionPerformed(java.awt.event.ActionEvent evt) {

num1 = Double.parseDouble(Txtnombre.getText());

opperation = "-";

Txtnombre.setText("");

private void BtnproduitActionPerformed(java.awt.event.ActionEvent evt) {

num1 = Double.parseDouble(Txtnombre.getText());

opperation = "*";

Txtnombre.setText("");

private void BtndivActionPerformed(java.awt.event.ActionEvent evt) {

num1 = Double.parseDouble(Txtnombre.getText());

opperation = "/";

Txtnombre.setText("");

private void BtnegaleActionPerformed(java.awt.event.ActionEvent evt) {

String reponse;

num2=Double.parseDouble(Txtnombre.getText());

if(opperation=="+"){

res=num1+num2;

reponse=String.format("%.2f",res);

Txtnombre.setText(reponse);

else if (opperation=="*"){

res=num1*num2;
reponse=String.format("%.2f",res);

Txtnombre.setText(reponse);

else if (opperation=="/"){

res=num1/num2;

reponse=String.format("%.2f",res);

Txtnombre.setText(reponse);

private void BtnplusmoinActionPerformed(java.awt.event.ActionEvent evt) {

double oppSigne = Double.parseDouble(String.valueOf(Txtnombre.getText()));

Txtnombre.setText(String.valueOf(oppSigne));

/**

* @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(FrmCalculatrice.class.getName()).log(java.util.logging.Level.SEVERE
, null, ex);

} catch (InstantiationException ex) {

java.util.logging.Logger.getLogger(FrmCalculatrice.class.getName()).log(java.util.logging.Level.SEVERE
, null, ex);

} catch (IllegalAccessException ex) {

java.util.logging.Logger.getLogger(FrmCalculatrice.class.getName()).log(java.util.logging.Level.SEVERE
, null, ex);

} catch (javax.swing.UnsupportedLookAndFeelException ex) {

java.util.logging.Logger.getLogger(FrmCalculatrice.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 FrmCalculatrice().setVisible(true);

});

// Variables declaration - do not modify

private javax.swing.JButton Btn0;

private javax.swing.JButton Btn1;

private javax.swing.JButton Btn2;

private javax.swing.JButton Btn3;


private javax.swing.JButton Btn4;

private javax.swing.JButton Btn5;

private javax.swing.JButton Btn6;

private javax.swing.JButton Btn7;

private javax.swing.JButton Btn8;

private javax.swing.JButton Btn9;

private javax.swing.JButton Btnclean;

private javax.swing.JButton Btndiv;

private javax.swing.JButton Btnegale;

private javax.swing.JButton Btnmoin;

private javax.swing.JButton Btnplus;

private javax.swing.JButton Btnplusmoin;

private javax.swing.JButton Btnproduit;

private javax.swing.JButton Btnvirgule;

private javax.swing.JTextField Txtnombre;

private javax.swing.JPanel jPanel1;

// End of variables declaration

You might also like