Sie sind auf Seite 1von 5

/*

* 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 EXERCICERENDRE;

/**
*
* @author Cheikh
*/
public class Exercice_a_rendre extends javax.swing.JFrame {

/**
* Creates new form Exercice_a_rendre
*/
public Exercice_a_rendre() {
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">//GEN-
BEGIN:initComponents
private void initComponents() {

effacer = new javax.swing.JButton();


resultat = new javax.swing.JTextField();
jLabel1 = new javax.swing.JLabel();
nombre1 = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
nombre2 = new javax.swing.JTextField();
jLabel4 = new javax.swing.JLabel();
additionner = new javax.swing.JButton();
soustraction = new javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

effacer.setText("effacer");
effacer.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
effacerActionPerformed(evt);
}
});

resultat.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
resultatActionPerformed(evt);
}
});

jLabel1.setBackground(new java.awt.Color(255, 255, 255));


jLabel1.setFont(new java.awt.Font("Cambria", 0, 18)); // NOI18N
jLabel1.setForeground(new java.awt.Color(255, 0, 0));
jLabel1.setText("Calculatrice");

nombre1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
nombre1ActionPerformed(evt);
}
});

jLabel2.setText("Nombre1");

jLabel3.setText("Nombre2");

nombre2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
nombre2ActionPerformed(evt);
}
});

jLabel4.setFont(new java.awt.Font("Agency FB", 0, 24)); // NOI18N


jLabel4.setText("Resultat");

additionner.setText("Adiition");
additionner.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
additionnerActionPerformed(evt);
}
});

soustraction.setText("Soustraction");
soustraction.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
soustractionActionPerformed(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()

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(239, 239, 239)
.addComponent(jLabel1))
.addGroup(layout.createSequentialGroup()
.addGap(75, 75, 75)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel3)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(nombre2,
javax.swing.GroupLayout.PREFERRED_SIZE, 153,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(nombre1,
javax.swing.GroupLayout.PREFERRED_SIZE, 153,
javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGroup(layout.createSequentialGroup()
.addGap(86, 86, 86)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel4)
.addComponent(additionner))

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(55, 55, 55)
.addComponent(soustraction)
.addGap(61, 61, 61))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
layout.createSequentialGroup()

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(resultat,
javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(146, 146, 146)))
.addComponent(effacer)))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(23, 23, 23)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 26,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(41, 41, 41)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(nombre1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(nombre2, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(resultat, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(40, 40, 40)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(additionner)
.addComponent(soustraction)
.addComponent(effacer))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE))
);

pack();
}// </editor-fold>//GEN-END:initComponents

private void effacerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-


FIRST:event_effacerActionPerformed
// TODO add your handling code here:
nombre1.setText("");
nombre2.setText("");
resultat.setText("");

}//GEN-LAST:event_effacerActionPerformed

private void resultatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-


FIRST:event_resultatActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_resultatActionPerformed

private void nombre1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-


FIRST:event_nombre1ActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_nombre1ActionPerformed

private void nombre2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-


FIRST:event_nombre2ActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_nombre2ActionPerformed

private void additionnerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-


FIRST:event_additionnerActionPerformed
// TODO add your handling code here:
String txt=nombre1.getText();
int nombre1=Integer.parseInt(txt);
txt=nombre2.getText();
int nombre2=Integer.parseInt(txt);
int res=nombre1+nombre2;
resultat.setText(String.valueOf(res));

}//GEN-LAST:event_additionnerActionPerformed

private void soustractionActionPerformed(java.awt.event.ActionEvent evt)


{//GEN-FIRST:event_soustractionActionPerformed
// TODO add your handling code here:
String txt=nombre1.getText();
int nombre1=Integer.parseInt(txt);
txt=nombre2.getText();
int nombre2=Integer.parseInt(txt);
int res=nombre1-nombre2;
resultat.setText(String.valueOf(res));
}//GEN-LAST:event_soustractionActionPerformed

/**
* @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(Exercice_a_rendre.class.getName()).log(java.util
.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {

java.util.logging.Logger.getLogger(Exercice_a_rendre.class.getName()).log(java.util
.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {

java.util.logging.Logger.getLogger(Exercice_a_rendre.class.getName()).log(java.util
.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {

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

// Variables declaration - do not modify//GEN-BEGIN:variables


private javax.swing.JButton additionner;
private javax.swing.JButton effacer;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JTextField nombre1;
private javax.swing.JTextField nombre2;
private javax.swing.JTextField resultat;
private javax.swing.JButton soustraction;
// End of variables declaration//GEN-END:variables
}

Das könnte Ihnen auch gefallen