Hello

Etant debutant en java et prog. Objet, je rencontre kk petits pbs ds la creation d'une application d'un agenda.

En fait, l'applic. doit posseder 4 partie (planning, contact, emploi du temps et note) et chacune de ses partie peut etre acceder a partir de 4 boutton ki sont sur la droite de la fenetre.

En fait je suis entrain de cree une classe FrameBase ki contient la fenetre de base (qui contient juste les 4 boutton grossomodo sur la droite de la fenetre).

Mnt moi je m'occupe de la partie "Note" et ce qui se passe c ke jai cree
une autre classe CadreNote ki herite de JPanel, et ki doit en realite sincorporer ds la fentre de base, ds un cadre à gauche specialement prevu pour cet effet.


Mon pb: je voudrai simplement pouvoir recuperer la cadre gauche de ma FrameBase et y mettre un objet CadreNote...

Pour ce faire, ds FrameBase, j'ai une methode public static JPanel getCadreGauche() ki me retourne simplement l'attribut panel_principal déclaré en private static...

Ensuite ds le main :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
 
public static void main(String[] arguments){
		FrameBase fn=new FrameBase();
		fn.getPanelPrincipal().add(cn.getPanelNote());
//cn etant une variable CadreNote
	}
Et vous vous en doutez, ca marche pas!

voici mes 2 classes:
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
 
 
/*FrameBase*/
 
import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;
import javax.swing.border.Border;
import java.util.*;
import java.text.DateFormat;
 
 
public class FrameBase extends JFrame {
	//static Vector notes=new Vector(); 
	 ImageIcon ip=new ImageIcon("icon_planning.jpg");
	 ImageIcon ic=new ImageIcon("icon_contacts2.jpg");
	 ImageIcon ie=new ImageIcon("icon_edt.jpg");
	 ImageIcon in=new ImageIcon("icon_notes2.jpg");
	 JButton bplanning = new JButton(ip);
	 JButton bcontact = new JButton(ic);
	 JButton bedt = new JButton(ie);
	 JButton bnote = new JButton(in);
 
	//JToolBar bar=new JToolBar(1);
	 JLabel espace=new JLabel("      ");
	 JLabel espace2=new JLabel(" ");
	 JLabel espace3=new JLabel(" ");
	/*JLabel espace4=new JLabel("      ",SwingConstants.LEFT);
	JLabel espace5=new JLabel("      ",SwingConstants.CENTER);*/
	 JLabel fonc=new JLabel("   Fonctionnalités   ");
	 JMenuBar menubar=new JMenuBar();
	 JMenu menu=new JMenu("Fichier");
	 JMenuItem j1=new JMenuItem("Quitter"); 
 
//	Border me sert a diviser en 5 ma frame
	 BorderLayout bl=new BorderLayout(10,10);
//  je creer un pane2 pr y mettre les notes
	 JPanel panel_principal=new JPanel();
//	je creer un panel pr y mettre les boutton a la vertical
	 JPanel panel_bouttons=new JPanel();
//	je cree une grille ds lakel je v disposer mes buttons
	 GridBagLayout bouttons = new GridBagLayout();
	GridBagConstraints constraints ;
 
 
 
	//private static CadreNote cn;
 
 
 
	FrameBase(){
		super("ProAgenda - Note");
		setAlwaysOnTop(true);//tjrs laisser la fenetre au 1er plan
		setSize(800,600);
		//setBounds(125,50,800,600);
		//je centre par rapport a ma fenetre parent
		setLocationRelativeTo(getParent());
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setJMenuBar(menubar);
 
		//je met un separateur ds le menu
		menu.addSeparator();
		//je met "quitter" ds le menu
		menu.add(j1);
 
		//menu ds menubar
		menubar.add(menu);
 
 
 
 
		setLayout(bl);//je  rajoute le bl ds ma frame
 
 
		//je creer une instance date
		Date maDate=new Date();
 
		//format de la date jeudi 22 decembre
		DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.FULL);
 
		//mettre le label en haut a droite
		add(new JLabel("Aujourd'hui, "+dateFormat.format(maDate)+"    ",SwingConstants.RIGHT),BorderLayout.NORTH);
 
//		je creer des espaces entre les bords de la frame
		add(espace2,BorderLayout.EAST);
		add(espace3,BorderLayout.SOUTH);
 
 
 
 
		//je creer un contour pr panel_bouttons
		Border borderLine = BorderFactory.createLineBorder(Color.BLACK);
        panel_bouttons.setBorder(borderLine);
 
 
//		je met ce panel 1 a louest
		add(panel_bouttons,BorderLayout.WEST);
 
 
 
		panel_bouttons.setLayout(bouttons);//je  met le gridbag "bouttons" ds panel_bouttons
 
		//je place mon label fonc:
		constraints = new GridBagConstraints();
        constraints.gridx = 0;//position de cellule : 0,0
        constraints.gridy = 0;
        constraints.gridwidth = 2;//nb de cellule occupées à l'horizontal
        constraints.gridheight = 1;//nb de cellule occupées à la vertical
        constraints.weightx = 100;//taille de ce composant=100% en fct des autre composants de cette ligne 
        constraints.weighty = 10;//10% par rapport au 100% de la colonne entiere
        constraints.fill = GridBagConstraints.NONE;
        constraints.anchor =GridBagConstraints.SOUTH;
        bouttons.setConstraints(fonc, constraints);
        panel_bouttons.add(fonc);
 
		//je place mon boutton planning:
		constraints = new GridBagConstraints();
        constraints.gridx = 0;
        constraints.gridy = 1;
        constraints.gridwidth = 3;
        constraints.gridheight = 1;
        constraints.weightx = 100;
        constraints.weighty = 22;
        constraints.fill = GridBagConstraints.NONE;
        constraints.anchor =GridBagConstraints.CENTER;
        bouttons.setConstraints(bplanning, constraints);
        panel_bouttons.add(bplanning);
 
//      je place mon boutton bcontact:
		constraints = new GridBagConstraints();
        constraints.gridx = 0;
        constraints.gridy = 2;
        constraints.gridwidth = 3;
        constraints.gridheight = 1;
        constraints.weightx = 100;
        constraints.weighty = 22;
        constraints.fill = GridBagConstraints.NONE;
        constraints.anchor =GridBagConstraints.CENTER;
        bouttons.setConstraints(bcontact, constraints);
        panel_bouttons.add(bcontact);
 
//      je place mon boutton bedt:
		constraints = new GridBagConstraints();
        constraints.gridx = 0;
        constraints.gridy = 3;
        constraints.gridwidth = 3;
        constraints.gridheight = 1;
        constraints.weightx = 100;
        constraints.weighty = 22;
        constraints.fill = GridBagConstraints.NONE;
        constraints.anchor =GridBagConstraints.CENTER;
        bouttons.setConstraints(bedt, constraints);
        panel_bouttons.add(bedt);
 
//      je place mon boutton bnote:
		constraints = new GridBagConstraints();
        constraints.gridx = 0;
        constraints.gridy = 4;
        constraints.gridwidth = 3;
        constraints.gridheight = 1;
        constraints.weightx = 100;
        constraints.weighty = 22;
        constraints.fill = GridBagConstraints.NONE;
        constraints.anchor =GridBagConstraints.CENTER;
        bouttons.setConstraints(bnote, constraints);
        panel_bouttons.add(bnote);
 
 
//      je creer un panel_principal pr y mettre les notes
		//JPanel panel_principal=new JPanel();
 
//		je met ce panel 2 au centre
		add(panel_principal,BorderLayout.CENTER);
 
		//je creer un contour pr panel_principal
		Border borderLine2 = BorderFactory.createLineBorder(Color.BLACK);
        panel_principal.setBorder(borderLine2);
 
 
 
		//tt ceci est visible
		setVisible(true);
	}
 
 
 
 
 
 
	public JPanel getPanelPrincipal(){
		return panel_principal;
	}
 
 
 
	public static void main(String[] arguments){
		FrameBase fn=new FrameBase();
		//cn=new CadreNote();
		//System.out.println("ds le main : "+fn.getPanelPrincipal());
		//fn.getPanelPrincipal().add(new JLabel("zizi"));
		fn.test();
 
	}
 
}
ET ma classe CadreNote tte simple
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
 
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
 
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.border.Border;
 
 
public class CadreNote extends JPanel{
 
	private static JButton bajout = new JButton("Ajouter");
 
 
	CadreNote (){
 
 
//      Border me sert a diviser en 5 panel_principal
		BorderLayout bl2=new BorderLayout(10,10);
		setLayout(bl2);//je le rajoute ds ma frame
 
		add(new JLabel(" Voici vos notes en attente : "),BorderLayout.NORTH);
		add(new JLabel(" "),BorderLayout.EAST);
		add(new JLabel(" "),BorderLayout.WEST);
 
		//pr le sud, il fo mettre un boutton ajouter:
		//-->je cree un gestionnaire dagencement pr placer mon boutton en bas a droite
		FlowLayout flo=new FlowLayout(FlowLayout.RIGHT);
		//je cree un panel
		JPanel pane_ajout=new JPanel();
		//je rajoute le boutton ajout ds ce panel
		pane_ajout.add(bajout);
		//je met le gestionnaire ds ce nouveau panel 
		pane_ajout.setLayout(flo);
		//je met ce panel ds le sud de bl2
		add(pane_ajout,BorderLayout.SOUTH);
 
 
 
 
	//      je creer un pane3 au centre de bl2
		JPanel pane3=new JPanel();
		//je le rajoute au centre
		add(pane3,BorderLayout.CENTER);
 
 
 
/******************************************************************/
		JPanel liste = new JPanel(); 
 
		//Vector lesNotes=new Vector();
		//JLabel a=new JLabel("hello ");
		for (int i=0;i<100;i++){
			liste.add(new JLabel("hello "+ i+"\n"));
			//scroll.add(a);
		}
 
		//liste.setSelectedIndex(0); 
 
		//je cree un jscroll pane ki contiendra tte les notes
		JScrollPane scroll=new JScrollPane(liste,
				JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
				JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
 
		/*for (int j=0;j<100;j++){
			liste.getComponent(j);
		}*/
 
 
 
		//je dimensionne scroll
		Dimension dim=new Dimension(625,400);
		scroll.setPreferredSize(dim);
//		je creer un contour pr scroll
		Border borderLine3 = BorderFactory.createLineBorder(Color.LIGHT_GRAY);
        scroll.setBorder(borderLine3);
 
 
 
		//je le rajoute a pane3
		pane3.add(scroll);
 
 
 
//		tt ceci est visible
		setVisible(true);
 
 
	}
 
	public JPanel getPanelNote(){
		return new CadreNote();
	}
 
}
C'est long ms pas vrt compliquer , j'ai mis tt mon code pk je sais pas exactement keskil faut vous donner pr repondre a ma question..

Merci bcp!