Accueil   Stratégie   Difficultés  
  Contact   











Stratégie du programme

L'applet est consituée de 2 classes

  • La classe Calculatrice
  • La classe CalcButton

Et de méthodes :

  • La méthode doOp()
  • La méthode init()

 

  1. Déclaration des différents boutons

public final int NONE = 0;
public final int ADD = 1;
public final int SUB = 2;
public final int MUL = 3;
public final int DIV = 4;
public final int NEG = 5;
public final int SQRT = 6;
public final int EQ = 7;
public final int C = 8;
public final int AC = 9;
public final int DECSEP = -1;

2- Mise en page du layout et des boutons

- Déclaration de la police de caractère :

setFont(new Font("Helvetica", Font.PLAIN, 14));

- Déclaration de la couleur du fond de la calculatrice

setBackground(new Color(0xCC, 0xCC, 0xCC));

- Création du bouton :

btn1 = new CalcButton("1",NONE, 1); // Déclaration du bouton
add(btn1); // Ajout du bouton sur l'applet
btn1.reshape(64, 132, 40, 24); // dimension du bouton
btn1.setForeground(Color.blue);// Couleur du textedu bouton

- Création du cadre :

Frame frm = new Frame("Ma premiere calculatrice en java");
PocketCalc ex1 = new PocketCalc();
ex1.init();
frm.add("Center", ex1);
frm.pack();
frm.resize(400, 400);
frm.show();

3- Les opérations

- Les nombres décimaux

public void append(int nValue)
{
String sDigit;

if(nValue == DECSEP)
if(!mbDecimal)
{
if(mbNewNumber)
{
txtDisp.setText("0");
mbNewNumber = false;
}
mbDecimal = true;
sDigit = msDecimal;
}
else
return;
else
sDigit = (new Integer(nValue)).toString();
if(mbNewNumber)
{
txtDisp.setText(sDigit);
mbNewNumber = false;
}
else
txtDisp.setText(txtDisp.getText() + sDigit);
repaint();
}

- les opérations