1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
| import java.awt.*;
import java.awt.event.*;
import java.awt.event.ActionEvent.*;
public class Plan1 extends Frame implements ActionListener{
private Panel p, p1, p2;
private TextField capital;
private TextField taux;
private TextField nbannuites;
private List resultat;
private Button ok;
public Plan1(String titre) {
super (titre);
p = new Panel();
p1 = new Panel();
p1.setLayout (new GridLayout (6,1));
p1.add (new Label ("Capital"));
capital = new TextField();
p1.add (capital);
p1.add (new Label ("Taux annuel"));
taux = new TextField();
p1.add (taux);
p1.add (new Label ("Nombre d'annuites"));
nbannuites = new TextField();
p1.add (nbannuites);
p.add (p1);
resultat = new List(20);
p.add(resultat);
add(p);
p2 = new Panel();
ok = new Button ("Valider");
p2.add(ok);
add("South", p2);
ok.addActionListener(this);
}
float cap() {
return new Float(capital.getText()).floatValue();
}
float tx() {
return new Float(taux.getText()).floatValue();
}
int nbint() {
return new Integer(nbannuites.getText()).intValue();
}
void ajoute (String s) {
resultat.add(s);
}
void vide() {
resultat.removeAll();
}
void calcul() {
this.vide();
float montant = this.cap();
float taux = this.tx();
int nbannuites = this.nbint();
this.ajoute(new Float(montant).toString());
for(int i=0; i< nbannuites; i++) {
montant = montant * (1+taux/100);
this.ajoute(new Float(montant).toString());
}
}
public void actionPerformed(ActionEvent evt) {
Object src = evt.getSource();
String param = ( (Button) src).getLabel();
if (param == "Valider") this.calcul();
}
}
**************
Fichier TestPlan1.java (qui permet de lancer l'appli):
public class TestPlan1 {
public static void main (String [] args) {
Plan1 f = new Plan1("Actions");
f.setSize(300,400);
f.show();
}
} |