Bonjour,
Donc voilà, j'essaye ds un jframe d'afficher en même tps un textfield et un panneau de nombres pr 1 calculette.
Ainsi j'ai 1 'blem sur ce truc.
Voici mon code :
ma classe EcranCalculatrice
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 import java.awt.*; import javax.swing.*; public class Calculatrice { public static void main(String[] arg) { JFrame fenetreCalculatrice = new JFrame("Calculatrice"); fenetreCalculatrice.setLocationRelativeTo(null) ; //centre par rapport à l'ecran fenetreCalculatrice.setSize(600, 600) ; Container conteneurCalto = fenetreCalculatrice.getContentPane() ; //conteneurCalto.setLayout( new LayoutManager(5,5,5) ) ; FlowLayout flowLayout = new FlowLayout(5,5,5) ; conteneurCalto.setLayout(flowLayout(5,5,5)) ; EcranCalculatrice ecranCalculatrice = new EcranCalculatrice() ; fenetreCalculatrice.add(ecranCalculatrice) ; fenetreCalculatrice.setVisible(true) ;
ma classe PanneauNombres
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 import javax.swing.*; public class EcranCalculatrice extends JPanel { //variables d'instances private JTextField champInteractif ; public EcranCalculatrice() { //instanciation champInteractif = new JTextField(" ",40) ; } }
Je suis à peu prés sur ke le 'blem vient des layout que j'utilise mais je ne sais pas précisement quoi?
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 import java.awt.* ; import javax.swing.*; public class PanneauChiffres extends JPanel { //private JButton[] tabChiffres ; final static String[] CHIFFRES = { "0", "1", " 2 " ,"3" , "4","5" , "6" , "7" ,"8", "9"} ; /** * constructeur qui mes 10 chiffres de 0..9 */ PanneauChiffres() { JButton tabChiffres ; setLayout(new GridBagLayout()) ; // qd mon JPanel est creé, je modifie son layout manager grace à la methode setLayout(LayoutManager) for (int i=0; i<CHIFFRES.length; i++) { tabChiffres =new JButton(CHIFFRES[i]); add(tabChiffres); } } /*public PanneauChiffres() { //----> PENSEZ A FAIRE DES BOUCLES !!! tabChiffres = new JButton[10]; for(int i = 0 ; i < tabChiffres.length; i ++) { tabChiffres[i] = new JButton(""+i+"") ; //besoin de cette boucle pr l'affichage du pave numerique for (int j = 1 ; j <= tabChiffres.length ; j++) this.add(tabChiffres[i]) ; } //this.setLocation(this) ; } */ }
Si quelqu'un a un conseil, je suis preneur!!
a+
merci d'avance
![]()
Partager