Bonsoir, voila je débute sur JAVA et je coince sur un petit problème :
Sur mon premier JPANEL ils y a plusieurs JBUTTON, le problème arrive lorsque je clic sur un JBUTTON "Ajouter" qui doit l'appelé un autre JPANEL "Ajoute Abonné".
Lors du clic sur le JBUTTON, le bouton reste enfoncé mais rien ne se passe !
Ceci est mon MAIN
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 /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package lib; import lib.graphique.CalqueAccueil; import lib.graphique.CalqueAjouterAbonne; import lib.graphique.CalqueAjouterEmprunt; /** * * @author z1t0un3 */ public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here Application application = new Application(); application.setCalqueActif(new CalqueAjouterAbonne(application)); } }
Ceci est le code APPLICATION (création de la fenêtre)
Enfin ceci est le code du JPANEL "Ajouté abonné"
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 package lib; import javax.swing.*; // <editor-fold defaultstate="collapsed" desc=" UML Marker "> // #[regen=yes,id=DCE.ACB36EBB-2C38-5014-8D43-B6B893176849] // </editor-fold> public class Application extends JFrame { public String titre; JPanel Actif; public Application() { super(); build();//On initialise notre fenêtre } private void build() { int largeur = 400; int hauteur = 400; setTitle(titre); //On donne un titre Ã* l'application setSize(largeur, hauteur); //On donne une taille Ã* notre fenêtre setLocationRelativeTo(null); //On centre la fenêtre sur l'écran setResizable(false); //On interdit la redimensionnement de la fenêtre setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //On dit Ã* l'application de se fermer lors du clic sur la croix //setContentPane(Actif); setVisible(true); } public void setCalqueActif(JPanel calqueActif) { Actif=calqueActif; setContentPane(Actif); } }
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 Application appli; // private JTextField email; // private JTextField ici; // <editor-fold defaultstate="collapsed" desc=" UML Marker "> // #[regen=yes,id=DCE.8418F39C-F94F-9A80-91F1-CA105FB0258E] // </editor-fold> public CalqueAjouterAbonne(Application application) { setLayout(null); //titre titre = new JLabel("Veuillez saisir les informations du nouvel abonné!"); titre.setName("titre"); titre.setBounds(10, 10, 400, 30); titre.setVisible(true); this.add(titre); //Nom nomText = new JLabel("Nom : "); nomText.setName("Nom"); nomText.setBounds(10, 50, 100, 30); nomText.setVisible(true); this.add(nomText); nom = new JTextField(""); nom.setBounds(150, 50, 100, 30); nom.setVisible(true); this.add(nom); //Prenom prenomText = new JLabel("Prénom : "); prenomText.setName("Prenom"); prenomText.setBounds(10, 90, 100, 30); prenomText.setVisible(true); this.add(prenomText); prenom = new JTextField(""); prenom.setBounds(150, 90, 100, 30); prenom.setVisible(true); this.add(prenom); //Date de naissance DateText = new JLabel("Date de naissance : "); DateText.setName("Date de naissance"); DateText.setBounds(10, 150, 150, 30); DateText.setVisible(true); this.add(DateText); JComboBox ListeJour = new JComboBox(); ListeJour.setBounds(150, 150, 40, 30); ListeJour.setVisible(true); this.add(ListeJour); for (int i = 1; i <= 12; i++) { ListeJour.addItem(i); } sep = new JLabel("/"); sep.setBounds(195, 150, 30, 30); sep.setVisible(true); this.add(sep); Object[] Mois = new Object[]{"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"}; JComboBox ListeMois = new JComboBox(Mois); ListeMois.setBounds(210, 150, 40, 30); ListeMois.setVisible(true); this.add(ListeMois); sep = new JLabel("/"); sep.setBounds(260, 150, 30, 30); sep.setVisible(true); this.add(sep); JComboBox ListeAnne = new JComboBox(); ListeAnne.setBounds(270, 150, 70, 30); ListeAnne.setVisible(true); this.add(ListeAnne); for (int i = 1900; i <= 2010; i++) { ListeAnne.addItem(i); } BoutonAjouter = new JButton(new ActionAjouter()); BoutonAjouter.setName("Ajouter"); BoutonAjouter.setBounds(150,200,90,30); BoutonAjouter.setVisible(true); this.add(BoutonAjouter); BoutonAnnuler = new JButton(); BoutonAnnuler.setName("Annuler"); BoutonAnnuler.setBounds(150,200,90,30); BoutonAnnuler.setVisible(true); this.add(BoutonAnnuler); //annee = new JTextField(""); // annee.setBounds(250,150,30,30); //annee.setVisible(true); //this.add(annee); } }
Pour être complet voici le code de mon action "ajouté"
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 package action; import java.awt.event.ActionEvent; import javax.swing.*; import lib.Application; import lib.graphique.CalqueAjouterAbonne; import lib.graphique.CalqueAjouterLivre; // <editor-fold defaultstate="collapsed" desc=" UML Marker "> // #[regen=yes,id=DCE.C37345C0-6BDF-0DCF-EF1A-CD30D68AEDC6] // </editor-fold> public class ActionAjouter extends AbstractAction { private Application application ; private CalqueAjouterAbonne AjouterAbonne ; private CalqueAjouterLivre AjouterLivre ; // <editor-fold defaultstate="collapsed" desc=" UML Marker "> // #[regen=yes,id=DCE.4C04C8C9-E248-9B54-BB11-A7DFA1FC9D1F] // </editor-fold> public ActionAjouter () { super("Ajouter"); } public ActionAjouter(Application appli) { this(); application = appli; AjouterAbonne = new CalqueAjouterAbonne(appli); } public void actionPerformed(ActionEvent e) { application.add(AjouterLivre); //System.out.print("lol"); } }
Partager