Bonjour,

je suis actuellement en présence de ce code ci dessus qui permet de demander à l'utilisateur une date de début et une date de fin (Heure, Minutes + Jour, Mois, Année). A partir de ça je dois récupérer ces valeurs et définir le temps total en minutes de cet intervalle. Auriez vous une piste ?

Merci beaucoup.

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
public class TimePanel extends JPanel {
 
	/** Layout constraints of the panel */
	private final GridBagConstraints gbc;
 
	public TimePanel()
	{
		// Initialization of the GBC
		this.gbc = new GridBagConstraints();
		this.gbc.gridwidth = 1;
		this.gbc.gridheight = 1;
		this.gbc.weightx = 0;
		this.gbc.weighty = 0;
		this.gbc.anchor = GridBagConstraints.CENTER;
		this.gbc.insets = new Insets(5, 5, 5, 5);
		this.gbc.fill = GridBagConstraints.NONE;
		//this.gbc.anchor = GridBagConstraints.NORTHWEST;
 
		this.setLayout(new GridBagLayout());
		this.setBorder(BorderFactory.createLineBorder(Color.black));
		this.setBackground(CharteGraphique.PANEL_BACKGROUND);
 
 
 
		txtFieldHeureDebut = new JFormattedTextField(DateFormat.getTimeInstance());
		Calendar hour = Calendar.getInstance(Locale.FRANCE);
		hour.set(Calendar.HOUR, 0);
		hour.set(Calendar.MINUTE, 0);
		hour.set(Calendar.SECOND, 0);
		txtFieldHeureDebut.setValue(hour.getTime());
		txtFieldHeureFin = new JFormattedTextField(DateFormat.getTimeInstance());
		txtFieldHeureFin.setValue(hour.getTime());
		txtFieldDateDebut = new JFormattedTextField(DateFormat.getDateInstance());
		Calendar startDate = Calendar.getInstance(Locale.FRANCE);
		startDate.add(Calendar.DAY_OF_MONTH, -1);
		txtFieldDateDebut.setValue(startDate.getTime());
		txtFieldDateFin = new JFormattedTextField(DateFormat.getDateInstance());
		Calendar endDate = Calendar.getInstance(Locale.FRANCE);
		endDate.add(Calendar.DAY_OF_MONTH, +1);
		txtFieldDateFin.setValue(endDate.getTime());
		initComponents();
	}
 
	public Date getStartDate()
	{
		Calendar startDate = Calendar.getInstance();
		startDate.setTime((Date)txtFieldDateDebut.getValue());
		Calendar startTime = Calendar.getInstance();
		startTime.setTime((Date)txtFieldHeureDebut.getValue());
 
		startDate.set(Calendar.HOUR_OF_DAY, startTime.get(Calendar.HOUR_OF_DAY));
		startDate.set(Calendar.MINUTE, startTime.get(Calendar.MINUTE));
		return startDate.getTime();
	}
 
	public Date getEndDate()
	{
		Calendar startDate = Calendar.getInstance();
		startDate.setTime((Date)txtFieldDateFin.getValue());
		Calendar startTime = Calendar.getInstance();
		startTime.setTime((Date)txtFieldHeureFin.getValue());
 
		startDate.set(Calendar.HOUR_OF_DAY, startTime.get(Calendar.HOUR_OF_DAY));
		startDate.set(Calendar.MINUTE, startTime.get(Calendar.MINUTE));
		return startDate.getTime();
	}