Bonjour,
J'ai développé une application JEE en utilisant plusieurs API tels que JPA...J'ai un package qui concerne les services (les methodes CRUD) effectués sur les entités.
Le projet consiste à developper un générateur de test technique. D'abord le test se compose d'un ensemble de question et une question peut étre dans plusieurs test dans ce cas on a une relation ManyToMany ce qui engendre la création d'une table supplémentaire contenant Id_test et Id_test comme étant clé primaire (ça marche graçe au mapping et JPA j'ai généré les tables parfaitement). l'utilisateur a préparer son test et la je veux que quand il clique sur ajouter l'Id du test et les Id des questions seront ajouté a la table test_question je sais pas comment y faire et comment se fait l'ajout.
Nom : question.png
Affichages : 177
Taille : 14,0 Ko Voilà les questions par exemple que je veux ajouter au test (ils ont des id dans la base)
Nom : Test.png
Affichages : 176
Taille : 9,8 Ko Ceci est le schema de la base de donnée

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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
package tn.esen.gui.responsableTechnique;
 
import javax.swing.JPanel;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.border.TitledBorder;
 
import tn.esen.delegate.GestionCategorieDelegate;
import tn.esen.delegate.GestionQuestionDelegate;
import tn.esen.delegate.GestionTestDelegate;
import tn.esen.entities.Categorie;
import tn.esen.entities.Question;
 
import javax.swing.UIManager;
import java.awt.Color;
import java.awt.SystemColor;
import java.util.List;
 
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.SwingConstants;
import javax.swing.JButton;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import org.jdesktop.swingbinding.JTableBinding;
import org.jdesktop.swingbinding.SwingBindings;
import org.jdesktop.beansbinding.AutoBinding.UpdateStrategy;
import org.jdesktop.beansbinding.BeanProperty;
 
import java.util.ArrayList;
import java.util.Collection;
import tn.esen.entities.Reponse;
import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.ItemListener;
import java.awt.event.ItemEvent;
import javax.swing.JList;
import org.jdesktop.swingbinding.JListBinding;
import javax.swing.event.CaretListener;
import javax.swing.event.CaretEvent;
import javax.swing.border.LineBorder;
import javax.swing.border.EmptyBorder;
import javax.swing.border.MatteBorder;
import javax.swing.ImageIcon;
 
public class PreparerTestAutomatique extends JPanel {
	private JTextField Facile;
	private JTextField Moyen;
	private JTextField Difficile;
List<Question> questions= new ArrayList<>();
private JTable table;
Categorie categorie;
JButton btnAfficher;
/**
         * Create the panel.
         */
	public PreparerTestAutomatique() {
	setForeground(new Color(51, 153, 255));
		JPanel panel = new JPanel();
		panel.setForeground(SystemColor.textHighlight);
		panel.setToolTipText("");
		panel.setBounds(0,0,300,300);
		panel.setBackground(new Color(0, 122, 222));
		GroupLayout groupLayout = new GroupLayout(this);
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(Alignment.TRAILING, groupLayout.createSequentialGroup()
					.addGap(20)
					.addComponent(panel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(Alignment.TRAILING, groupLayout.createSequentialGroup()
					.addGap(22)
					.addComponent(panel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
		);
 
		JLabel lblNewLabel = new JLabel("Nombre de question facile\r\n\r\n");
		lblNewLabel.setForeground(new Color(245, 245, 245));
		lblNewLabel.setFont(new Font("Calibri", Font.BOLD, 20));
 
		Facile = new JTextField();
 
 
		Facile.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				btnAfficher.setEnabled(true);
			}
		}); 
		Facile.setColumns(10);
 
		JLabel lblNombreDeQuestion = new JLabel("Nombre de question moyen");
		lblNombreDeQuestion.setForeground(SystemColor.control);
		lblNombreDeQuestion.setFont(new Font("Calibri", Font.BOLD, 20));
 
		Moyen = new JTextField();
		Moyen.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				btnAfficher.setEnabled(true);
			}
		}); 
		Moyen.setColumns(10);
 
		JLabel lblNombreDeQuestion_1 = new JLabel("Nombre de question difficile");
		lblNombreDeQuestion_1.setForeground(SystemColor.control);
		lblNombreDeQuestion_1.setFont(new Font("Calibri", Font.BOLD, 20));
 
		Difficile = new JTextField();
		Difficile.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				btnAfficher.setEnabled(true);
			}
		}); 
		Difficile.setColumns(10);
 
		btnAfficher = new JButton("Afficher");
		btnAfficher.setBackground(Color.LIGHT_GRAY);
		btnAfficher.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				categorie=GestionCategorieDelegate.doFindCategorieById(PreparerTest.idCategorie);
				System.out.println(categorie);
				btnAfficher.setEnabled(false);
				if(Facile.getText().length()!=0)
				{
					questions.addAll(GestionTestDelegate.doPrepareRandomTest(Integer.parseInt(Facile.getText()), categorie,"Facile"));
				} 
				else
				{
 
				}
				if(Moyen.getText().length()!=0)
				{
 
					questions.addAll(GestionTestDelegate.doPrepareRandomTest(Integer.parseInt(Moyen.getText()), categorie, "Moyen"));
 
				}
				else
				{
 
				}
				if(Difficile.getText().length()!=0)
				{
					questions.addAll(GestionTestDelegate.doPrepareRandomTest(Integer.parseInt(Difficile.getText()), categorie, "Difficile"));
 
				}
				System.out.println(questions);
				initDataBindings();
 
 
			}
 
		}); 
 
		btnAfficher.setFont(new Font("Arial", Font.PLAIN, 15));
 
		JScrollPane scrollPane = new JScrollPane();
 
		JButton btnNewButton = new JButton("Pr\u00E9c\u00E9dent");
		btnNewButton.setFont(new Font("Times New Roman", Font.PLAIN, 13));
 
		JButton btnNewButton_1 = new JButton("Reg\u00E9n\u00E9rer");
		btnNewButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				questions.clear();
				categorie=GestionCategorieDelegate.doFindCategorieById(PreparerTest.idCategorie);
				System.out.println(categorie);
				btnAfficher.setEnabled(false);
				if(Facile.getText().length()!=0)
				{
					questions.addAll(GestionTestDelegate.doPrepareRandomTest(Integer.parseInt(Facile.getText()), categorie,"Facile"));
 
				} 
				else
				{
 
				}
				if(Moyen.getText().length()!=0)
				{
 
					questions.addAll(GestionTestDelegate.doPrepareRandomTest(Integer.parseInt(Moyen.getText()), categorie, "Moyen"));
 
				}
				else
				{
 
				}
				if(Difficile.getText().length()!=0)
				{
					questions.addAll(GestionTestDelegate.doPrepareRandomTest(Integer.parseInt(Difficile.getText()), categorie, "Difficile"));
 
				}
				System.out.println(questions);
				initDataBindings();
			}
 
 
		});
		btnNewButton_1.setFont(new Font("Times New Roman", Font.PLAIN, 13));
 
		JButton btnNewButton_2 = new JButton("Ajouter");
		btnNewButton_2.setFont(new Font("Arial", Font.PLAIN, 15));
 
		JButton btnNewButton_3 = new JButton("Quitter");
		btnNewButton_3.setFont(new Font("Arial", Font.PLAIN, 15));
 
		JPanel panel_1 = new JPanel();
		panel_1.setBackground(Color.BLACK);
 
		JLabel lblNewLabel_2 = new JLabel("");
		lblNewLabel_2.setFont(new Font("Tahoma", Font.PLAIN, 9));
		lblNewLabel_2.setIcon(new ImageIcon("C:\\Users\\Daly\\Documents\\logo.png"));
 
 
		GroupLayout gl_panel = new GroupLayout(panel);
		gl_panel.setHorizontalGroup(
			gl_panel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel.createSequentialGroup()
					.addGap(107)
					.addComponent(btnNewButton, GroupLayout.PREFERRED_SIZE, 95, GroupLayout.PREFERRED_SIZE)
					.addGap(35)
					.addComponent(btnNewButton_1, GroupLayout.PREFERRED_SIZE, 97, GroupLayout.PREFERRED_SIZE)
					.addContainerGap(678, Short.MAX_VALUE))
				.addGroup(gl_panel.createSequentialGroup()
					.addGap(449)
					.addComponent(btnAfficher, GroupLayout.PREFERRED_SIZE, 108, GroupLayout.PREFERRED_SIZE)
					.addContainerGap(455, Short.MAX_VALUE))
				.addGroup(gl_panel.createSequentialGroup()
					.addComponent(panel_1, GroupLayout.PREFERRED_SIZE, 1002, GroupLayout.PREFERRED_SIZE)
					.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
				.addGroup(gl_panel.createSequentialGroup()
					.addGap(355)
					.addComponent(btnNewButton_2, GroupLayout.PREFERRED_SIZE, 91, GroupLayout.PREFERRED_SIZE)
					.addGap(18)
					.addComponent(btnNewButton_3, GroupLayout.PREFERRED_SIZE, 91, GroupLayout.PREFERRED_SIZE)
					.addContainerGap(457, Short.MAX_VALUE))
				.addGroup(Alignment.TRAILING, gl_panel.createSequentialGroup()
					.addContainerGap(524, Short.MAX_VALUE)
					.addComponent(lblNewLabel_2, GroupLayout.PREFERRED_SIZE, 429, GroupLayout.PREFERRED_SIZE)
					.addGap(59))
				.addGroup(gl_panel.createSequentialGroup()
					.addGroup(gl_panel.createParallelGroup(Alignment.TRAILING)
						.addGroup(gl_panel.createSequentialGroup()
							.addGroup(gl_panel.createParallelGroup(Alignment.TRAILING)
								.addGroup(gl_panel.createSequentialGroup()
									.addGap(54)
									.addComponent(lblNewLabel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
									.addPreferredGap(ComponentPlacement.RELATED))
								.addGroup(gl_panel.createSequentialGroup()
									.addContainerGap()
									.addComponent(Facile, GroupLayout.PREFERRED_SIZE, 61, GroupLayout.PREFERRED_SIZE)
									.addGap(78)))
							.addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
								.addGroup(gl_panel.createSequentialGroup()
									.addGap(63)
									.addComponent(lblNombreDeQuestion))
								.addGroup(gl_panel.createSequentialGroup()
									.addGap(144)
									.addComponent(Moyen, GroupLayout.PREFERRED_SIZE, 62, GroupLayout.PREFERRED_SIZE)))
							.addPreferredGap(ComponentPlacement.RELATED, 112, Short.MAX_VALUE)
							.addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
								.addGroup(Alignment.TRAILING, gl_panel.createSequentialGroup()
									.addComponent(lblNombreDeQuestion_1)
									.addGap(47))
								.addGroup(Alignment.TRAILING, gl_panel.createSequentialGroup()
									.addComponent(Difficile, GroupLayout.PREFERRED_SIZE, 64, GroupLayout.PREFERRED_SIZE)
									.addGap(114))))
						.addGroup(Alignment.LEADING, gl_panel.createSequentialGroup()
							.addContainerGap()
							.addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, 962, GroupLayout.PREFERRED_SIZE)))
					.addContainerGap(40, Short.MAX_VALUE))
		);
		gl_panel.setVerticalGroup(
			gl_panel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel.createSequentialGroup()
					.addComponent(panel_1, GroupLayout.PREFERRED_SIZE, 64, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(lblNewLabel_2, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
					.addGap(40)
					.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblNewLabel, GroupLayout.PREFERRED_SIZE, 39, GroupLayout.PREFERRED_SIZE)
						.addComponent(lblNombreDeQuestion)
						.addComponent(lblNombreDeQuestion_1))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
						.addComponent(Facile, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(Moyen, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(Difficile, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addGap(36)
					.addComponent(btnAfficher)
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, 199, GroupLayout.PREFERRED_SIZE)
					.addGap(36)
					.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
						.addComponent(btnNewButton_3)
						.addComponent(btnNewButton_2))
					.addGap(85)
					.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
						.addComponent(btnNewButton, GroupLayout.PREFERRED_SIZE, 25, GroupLayout.PREFERRED_SIZE)
						.addComponent(btnNewButton_1, GroupLayout.PREFERRED_SIZE, 25, GroupLayout.PREFERRED_SIZE))
					.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
		);
 
		JLabel lblPrparerUnTest = new JLabel("Pr\u00E9parer un test");
		panel_1.add(lblPrparerUnTest);
		lblPrparerUnTest.setForeground(SystemColor.control);
		lblPrparerUnTest.setFont(new Font("Calibri", Font.BOLD, 35));
		lblPrparerUnTest.setBackground(new Color(0, 0, 0));
 
		table = new JTable();
		scrollPane.setViewportView(table);
		panel.setLayout(gl_panel);
		setLayout(groupLayout);
		initDataBindings();
		table.setRowHeight(30);
	}
	protected void initDataBindings() {
		JTableBinding<Question, List<Question>, JTable> jTableBinding = SwingBindings.createJTableBinding(UpdateStrategy.READ, questions, table);
		//
		BeanProperty<Question, String> questionBeanProperty = BeanProperty.create("contenu");
		jTableBinding.addColumnBinding(questionBeanProperty).setColumnName("Contenu");
		//
		BeanProperty<Question, Collection<Reponse>> questionBeanProperty_1 = BeanProperty.create("reponses");
		jTableBinding.addColumnBinding(questionBeanProperty_1).setColumnName("Reponses");
		//
		BeanProperty<Question, String> questionBeanProperty_2 = BeanProperty.create("niveauDeDifficulte");
		jTableBinding.addColumnBinding(questionBeanProperty_2).setColumnName("Niveau de difficult\u00E9");
		//
		jTableBinding.bind();
	}
}
Merci pour votre aide si vous avez besoin de plus d'informations de mon code veuillez le réclamer.