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
| import javax.swing.*;
import java.awt.*;
import java.text.*;
public class essai3 {
public static final String labels[]={"1", "2", "3", "4", "5", "6", "7", "8", "9", "0", ".", "=", "+", "-", "*", "/"};
public static void main(String[] args) {
JButton buttons[];
JPanel contenuFenêtre;
JTextField champAffichage;
JButton boutonVirgule;
JButton boutonEgale;
JPanel panneauChiffres;
JFrame frame;
JButton boutonAddition;
JButton boutonSoustraction;
JButton boutonDivision;
JButton boutonMultiplication;
JFormattedTextField field;
buttons = new JButton[labels.length];
contenuFenêtre = new JPanel();
for (int i=0; i < buttons.length; i++) {
buttons[i] = new JButton(labels[i]);
contenuFenêtre.add(buttons[i]); }
BorderLayout dispositionl = new BorderLayout();
contenuFenêtre.setLayout(dispositionl);
frame = new JFrame();
field = new JFormattedTextField( NumberFormat.getNumberInstance() );
boutonVirgule = new JButton(",");
boutonEgale = new JButton("=");
boutonAddition = new JButton("+");
boutonSoustraction = new JButton("-");
boutonDivision = new JButton("/");
boutonMultiplication = new JButton("*");
panneauChiffres = new JPanel();
GridLayout disposition2 = new GridLayout(4,3);
panneauChiffres.setLayout(disposition2);
panneauChiffres.add(boutonVirgule);
panneauChiffres.add(boutonEgale);
panneauChiffres.add(boutonAddition);
panneauChiffres.add(boutonSoustraction);
panneauChiffres.add(boutonDivision);
panneauChiffres.add(boutonMultiplication);
contenuFenêtre.add("Center", panneauChiffres);
contenuFenêtre.add(field, BorderLayout.NORTH);
frame = new JFrame("Calculatrice");
frame.setContentPane(contenuFenêtre);
frame.pack();
frame.setVisible(true);
}
} |
Partager