IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

 Java Discussion :

évènement affichage calculatrice


Sujet :

Java

  1. #1
    Membre du Club
    Inscrit en
    Avril 2009
    Messages
    101
    Détails du profil
    Informations forums :
    Inscription : Avril 2009
    Messages : 101
    Points : 50
    Points
    50
    Par défaut évènement affichage calculatrice
    Bonjour, voici le code que j'ai déja tapé pour ma calculatrice.
    Je commence à m'attaquer aux évènements et j'ai qq soucis (je débute en java).
    Mon code m'affiche seulement le chiffre sur lekel je clique. J'aimerai déja pouvoir rentrer un nombre car si je veux rentrer 59, je clik sur 5, le 5 s'affiche et qd je vais cliquer sur 9, le 9 prendre la place du 5.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.*;
     
    public class Calculette extends JFrame implements ActionListener {
     
    	JPanel pano;
    	JTextArea zone;
    	JButton zero, un, deux, trois, quatre, cinq, six, sept, huit, neuf, plus, egal, moins, virgule;
     
    	public Calculette(){
    		super();
    		zone = new JTextArea();
    		zone.setText("");
     
    		pano = new JPanel();
     
     
    		zero = new JButton("0");
    		zero.addActionListener(this);
    		un = new JButton("1");
    		un.addActionListener(this);
    		deux = new JButton("2");
    		deux.addActionListener(this);
    		trois = new JButton("3");
    		trois.addActionListener(this);
    		quatre = new JButton("4");
    		quatre.addActionListener(this);
    		cinq = new JButton("5");
    		cinq.addActionListener(this);
    		six = new JButton("6");
    		six.addActionListener(this);
    		sept = new JButton("7");
    		sept.addActionListener(this);
    		huit = new JButton("8");
    		huit.addActionListener(this);
    		neuf = new JButton("9");
    		neuf.addActionListener(this);
    		plus = new JButton("+");
    		plus.addActionListener(this);
    		moins = new JButton("-");
    		moins.addActionListener(this);
    		virgule = new JButton(",");
    		virgule.addActionListener(this);
    		egal = new JButton("=");
    		egal.addActionListener(this);
     
     
    		//mettre en places ts les panneaux
    	    pano.setLayout(new BorderLayout());
    	    pano.add(zone, BorderLayout.NORTH);	
     
    	    pano.setLayout(new GridBagLayout());
    	    GridBagConstraints cont = new GridBagConstraints();
    	    cont.fill = GridBagConstraints.BOTH;
     
    	    cont.gridx=0;
    	    cont.gridy=0;
    	    cont.gridwidth=4;
    	    cont.gridheight=1;
    	    cont.weightx=1;
    	    cont.weighty=1;
    	    pano.add(zone,cont);
     
    	    cont.gridx=0;
    	    cont.gridy=3;
    	    cont.gridwidth=1;
    	    cont.gridheight=1;
    	    cont.weightx=1;
    	    cont.weighty=1;
    	    pano.add(un,cont);
     
    	    cont.gridx=1;
    	    cont.gridy=3;
    	    cont.gridwidth=1;
    	    cont.gridheight=1;
    	    cont.weightx=1;
    	    cont.weighty=1;
    	    pano.add(deux,cont);
     
    	    cont.gridx=2;
    	    cont.gridy=3;
    	    cont.gridwidth=1;
    	    cont.gridheight=1;
    	    cont.weightx=1;
    	    cont.weighty=1;
    	    pano.add(trois,cont);
     
    	    cont.gridx=0;
    	    cont.gridy=2;
    	    cont.gridwidth=1;
    	    cont.gridheight=1;
    	    cont.weightx=1;
    	    cont.weighty=1;
    	    pano.add(quatre,cont);
     
    	    cont.gridx=1;
    	    cont.gridy=2;
    	    cont.gridwidth=1;
    	    cont.gridheight=1;
    	    cont.weightx=1;
    	    cont.weighty=1;
    	    pano.add(cinq,cont);  
     
    	    cont.gridx=2;
    	    cont.gridy=2;
    	    cont.gridwidth=1;
    	    cont.gridheight=1;
    	    cont.weightx=1;
    	    cont.weighty=1;
    	    pano.add(six,cont); 
     
    	    cont.gridx=0;
    	    cont.gridy=1;
    	    cont.gridwidth=1;
    	    cont.gridheight=1;
    	    cont.weightx=1;
    	    cont.weighty=1;
    	    pano.add(sept,cont);
     
    	    cont.gridx=1;
    	    cont.gridy=1;
    	    cont.gridwidth=1;
    	    cont.gridheight=1;
    	    cont.weightx=1;
    	    cont.weighty=1;
    	    pano.add(huit,cont);  
     
    	    cont.gridx=2;
    	    cont.gridy=1;
    	    cont.gridwidth=1;
    	    cont.gridheight=1;
    	    cont.weightx=1;
    	    cont.weighty=1;
    	    pano.add(neuf,cont);
     
    	    cont.gridx=0;
    	    cont.gridy=4;
    	    cont.gridwidth=2;
    	    cont.gridheight=1;
    	    cont.weightx=2;
    	    cont.weighty=1;
    	    pano.add(zero,cont);
     
    	    cont.gridx=2;
    	    cont.gridy=4;
    	    cont.gridwidth=1;
    	    cont.gridheight=1;
    	    cont.weightx=1;
    	    cont.weighty=1;
    	    pano.add(virgule,cont); 
     
    	    cont.gridx=3;
    	    cont.gridy=3;
    	    cont.gridwidth=1;
    	    cont.gridheight=2;
    	    cont.weightx=1;
    	    cont.weighty=10;
    	    pano.add(egal,cont); 
     
    	    cont.gridx=3;
    	    cont.gridy=2;
    	    cont.gridwidth=1;
    	    cont.gridheight=1;
    	    cont.weightx=1;
    	    cont.weighty=1;
    	    pano.add(plus,cont);
     
    	    cont.gridx=3;
    	    cont.gridy=1;
    	    cont.gridwidth=1;
    	    cont.gridheight=1;
    	    cont.weightx=1;
    	    cont.weighty=1;
    	    pano.add(moins,cont);
     
     
    	    setTitle("Calculatrice");
    	    setContentPane(pano);
    		setVisible(true);
    		pack();
     
     
    	}	
     
        public void actionPerformed (ActionEvent e){
     
        	if (e.getSource() == un){
        		zone.setText("1");
        	}
        	if (e.getSource() == deux){
        		zone.setText("2");
        	}
        	if (e.getSource() == trois){
        		zone.setText("3");
        	}
        	if (e.getSource() == quatre){
        		zone.setText("4");
        	}
        	if (e.getSource() == cinq){
        		zone.setText("5");
        	}
        	if (e.getSource() == six){
        		zone.setText("6");
        	}
        	if (e.getSource() == sept){
        		zone.setText("7");
        	}
        	if (e.getSource() == huit){
        		zone.setText("8");
        	}
        	if (e.getSource() == neuf){
        		zone.setText("9");
        	}
        	if (e.getSource() == zero){
        		zone.setText("0");
        	}
        	if (e.getSource() == plus){
        		zone.setText("+");
        	}
        	if (e.getSource() == moins){
        		zone.setText("-");
        	}    	
        }
     
     
    	public static void main(String[] args) {
     
    		new Calculette();
    	}
     
    }
    Merci bcp.

  2. #2
    Membre du Club
    Inscrit en
    Avril 2009
    Messages
    101
    Détails du profil
    Informations forums :
    Inscription : Avril 2009
    Messages : 101
    Points : 50
    Points
    50
    Par défaut
    Bon ben merci à ceux qui sont passé jeter un coup d'oeil. J'ai résolu mon pb tout seul, c'était pas si compliqué que ça ^^.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. JTextfield affichage Calculatrice
    Par madDevl31 dans le forum Débuter
    Réponses: 4
    Dernier message: 07/02/2013, 21h57
  2. [Calendrier] Affichage évènement
    Par Invité dans le forum EDI, CMS, Outils, Scripts et API
    Réponses: 12
    Dernier message: 27/07/2009, 23h25
  3. Problème d'appel d'affichage de messages dans évènement TUpDown
    Par the_clansman dans le forum Composants VCL
    Réponses: 16
    Dernier message: 04/02/2008, 17h13
  4. [Conception] Calendrier, affichage d'évènement
    Par grunk dans le forum PHP & Base de données
    Réponses: 1
    Dernier message: 29/07/2006, 11h34
  5. Affichage d'évènements en fonction de leur date ?
    Par swirtel dans le forum Langage SQL
    Réponses: 2
    Dernier message: 17/05/2005, 10h30

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo